Skip to content

Commit 9969e80

Browse files
authored
Merge pull request #99 from weaveworks/ring-states
Expose different ring states in the metrics
2 parents 9328f09 + 1cad88e commit 9969e80

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

ring/model.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ const (
1616
Leaving
1717
)
1818

19+
func (s IngesterState) String() string {
20+
switch s {
21+
case Active:
22+
return "Active"
23+
case Leaving:
24+
return "Leaving"
25+
}
26+
return ""
27+
}
28+
1929
// Desc is the serialised state in Consul representing
2030
// all ingesters (ie, the ring).
2131
type Desc struct {

ring/ring.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import (
1414
)
1515

1616
const (
17-
healthyLabel = "healthy"
18-
unhealthyLabel = "unhealthy"
17+
unhealthy = "Unhealthy"
1918
)
2019

2120
// Operation can be Read or Write
@@ -242,27 +241,28 @@ func (r *Ring) Collect(ch chan<- prometheus.Metric) {
242241
)
243242
}
244243

245-
healthy, unhealthy := 0, 0
244+
// Initialised to zero so we emit zero-metrics (instead of not emitting anything)
245+
byState := map[string]int{
246+
unhealthy: 0,
247+
Active.String(): 0,
248+
Leaving.String(): 0,
249+
}
246250
for _, ingester := range r.ringDesc.Ingesters {
247251
if time.Now().Sub(ingester.Timestamp) > r.heartbeatTimeout {
248-
unhealthy++
252+
byState[unhealthy]++
249253
} else {
250-
healthy++
254+
byState[ingester.State.String()]++
251255
}
252256
}
253257

254-
ch <- prometheus.MustNewConstMetric(
255-
r.numIngestersDesc,
256-
prometheus.GaugeValue,
257-
float64(healthy),
258-
healthyLabel,
259-
)
260-
ch <- prometheus.MustNewConstMetric(
261-
r.numIngestersDesc,
262-
prometheus.GaugeValue,
263-
float64(unhealthy),
264-
unhealthyLabel,
265-
)
258+
for state, count := range byState {
259+
ch <- prometheus.MustNewConstMetric(
260+
r.numIngestersDesc,
261+
prometheus.GaugeValue,
262+
float64(count),
263+
state,
264+
)
265+
}
266266
ch <- prometheus.MustNewConstMetric(
267267
r.numTokensDesc,
268268
prometheus.GaugeValue,

0 commit comments

Comments
 (0)