Skip to content

Commit

Permalink
[dbnode] Expose cluster total shards and replicas as metrics (#2452)
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington authored Jul 8, 2020
1 parent daaa0c8 commit 097de06
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/dbnode/storage/cluster/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ type newStorageDatabaseFn func(
) (storage.Database, error)

type databaseMetrics struct {
initializing tally.Gauge
leaving tally.Gauge
available tally.Gauge
initializing tally.Gauge
leaving tally.Gauge
available tally.Gauge
shardsClusterTotal tally.Gauge
shardsClusterReplicas tally.Gauge
}

func newDatabaseMetrics(scope tally.Scope) databaseMetrics {
shardsScope := scope.SubScope("shards")
shardsClusterScope := scope.SubScope("shards-cluster")
return databaseMetrics{
initializing: scope.Gauge("shards.initializing"),
leaving: scope.Gauge("shards.leaving"),
available: scope.Gauge("shards.available"),
initializing: shardsScope.Gauge("initializing"),
leaving: shardsScope.Gauge("leaving"),
available: shardsScope.Gauge("available"),
shardsClusterTotal: shardsClusterScope.Gauge("total"),
shardsClusterReplicas: shardsClusterScope.Gauge("replicas"),
}
}

Expand Down Expand Up @@ -319,7 +325,8 @@ func (d *clusterDB) activeTopologyWatch() {
}

func (d *clusterDB) analyzeAndReportShardStates() {
entry, ok := d.watch.Get().LookupHostShardSet(d.hostID)
placement := d.watch.Get()
entry, ok := placement.LookupHostShardSet(d.hostID)
if !ok {
return
}
Expand All @@ -343,6 +350,9 @@ func (d *clusterDB) analyzeAndReportShardStates() {
d.metrics.initializing.Update(float64(initializing))
d.metrics.leaving.Update(float64(leaving))
d.metrics.available.Update(float64(available))
shardsClusterTotal := len(placement.ShardSet().All())
d.metrics.shardsClusterTotal.Update(float64(shardsClusterTotal))
d.metrics.shardsClusterReplicas.Update(float64(placement.Replicas()))
}

defer reportStats()
Expand Down

0 comments on commit 097de06

Please sign in to comment.