Skip to content

Commit

Permalink
server: fix store metrics (#1261) (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
rleungx authored and disksing committed Oct 23, 2018
1 parent 6ee05f5 commit 43c2cb7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/store_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newStoreStatistics(opt *scheduleOption, namespace string) *storeStatistics
}

func (s *storeStatistics) Observe(store *core.StoreInfo) {
id := strconv.FormatUint(store.GetId(), 10)
// Store state.
switch store.GetState() {
case metapb.StoreState_Up:
Expand All @@ -61,6 +62,7 @@ func (s *storeStatistics) Observe(store *core.StoreInfo) {
s.Offline++
case metapb.StoreState_Tombstone:
s.Tombstone++
s.resetStoreStatistics(id)
return
}
if store.IsLowSpace(s.opt.GetLowSpaceRatio()) {
Expand All @@ -73,7 +75,6 @@ func (s *storeStatistics) Observe(store *core.StoreInfo) {
s.RegionCount += store.RegionCount
s.LeaderCount += store.LeaderCount

id := strconv.FormatUint(store.GetId(), 10)
storeStatusGauge.WithLabelValues(s.namespace, id, "region_score").Set(store.RegionScore(s.opt.GetHighSpaceRatio(), s.opt.GetLowSpaceRatio(), 0))
storeStatusGauge.WithLabelValues(s.namespace, id, "leader_score").Set(store.LeaderScore(0))
storeStatusGauge.WithLabelValues(s.namespace, id, "region_size").Set(float64(store.RegionSize))
Expand Down Expand Up @@ -104,6 +105,18 @@ func (s *storeStatistics) Collect() {
}
}

func (s *storeStatistics) resetStoreStatistics(id string) {
storeStatusGauge.WithLabelValues(s.namespace, id, "region_score").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "leader_score").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "region_size").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "region_count").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "leader_size").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "leader_count").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "store_available").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "store_used").Set(0)
storeStatusGauge.WithLabelValues(s.namespace, id, "store_capacity").Set(0)
}

type storeStatisticsMap struct {
opt *scheduleOption
classifier namespace.Classifier
Expand Down

0 comments on commit 43c2cb7

Please sign in to comment.