Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: fix store metrics #1261

Merged
merged 2 commits into from
Sep 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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