Skip to content

Commit 8b24889

Browse files
committed
nodes: Also count the nodes that are not parsed correctly
1 parent fd17889 commit 8b24889

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

nodes.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type NodesMetrics struct {
3838
maint map[string]float64
3939
mix map[string]float64
4040
resv map[string]float64
41+
other map[string]float64
4142
total map[string]float64
4243
}
4344

@@ -74,6 +75,7 @@ func InitFeatureSet(nm *NodesMetrics, feature_set string) {
7475
nm.maint[feature_set] = nm.maint[feature_set]
7576
nm.mix[feature_set] = nm.mix[feature_set]
7677
nm.resv[feature_set] = nm.resv[feature_set]
78+
nm.other[feature_set] = nm.other[feature_set]
7779
nm.total[feature_set] = nm.total[feature_set]
7880
}
7981

@@ -96,6 +98,7 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
9698
nm.maint = make(map[string]float64)
9799
nm.mix = make(map[string]float64)
98100
nm.resv = make(map[string]float64)
101+
nm.other = make(map[string]float64)
99102
nm.total = make(map[string]float64)
100103

101104
for _, line := range lines_uniq {
@@ -141,6 +144,8 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
141144
nm.mix[feature_set] += count
142145
case resv.MatchString(state):
143146
nm.resv[feature_set] += count
147+
default:
148+
nm.other[feature_set] += count
144149
}
145150
}
146151
}
@@ -225,6 +230,7 @@ func NewNodesCollector() *NodesCollector {
225230
maint: prometheus.NewDesc("slurm_nodes_maint", "Maint nodes", labelnames, nil),
226231
mix: prometheus.NewDesc("slurm_nodes_mix", "Mix nodes", labelnames, nil),
227232
resv: prometheus.NewDesc("slurm_nodes_resv", "Reserved nodes", labelnames, nil),
233+
other: prometheus.NewDesc("slurm_nodes_other", "Nodes reported with an unknown state", labelnames, nil),
228234
total: prometheus.NewDesc("slurm_nodes_total", "Total number of nodes", nil, nil),
229235
}
230236
}
@@ -240,6 +246,7 @@ type NodesCollector struct {
240246
maint *prometheus.Desc
241247
mix *prometheus.Desc
242248
resv *prometheus.Desc
249+
other *prometheus.Desc
243250
total *prometheus.Desc
244251
}
245252

@@ -255,6 +262,7 @@ func (nc *NodesCollector) Describe(ch chan<- *prometheus.Desc) {
255262
ch <- nc.maint
256263
ch <- nc.mix
257264
ch <- nc.resv
265+
ch <- nc.other
258266
ch <- nc.total
259267
}
260268

@@ -282,6 +290,7 @@ func (nc *NodesCollector) Collect(ch chan<- prometheus.Metric) {
282290
SendFeatureSetMetric(ch, nc.maint, prometheus.GaugeValue, nm.maint, part)
283291
SendFeatureSetMetric(ch, nc.mix, prometheus.GaugeValue, nm.mix, part)
284292
SendFeatureSetMetric(ch, nc.resv, prometheus.GaugeValue, nm.resv, part)
293+
SendFeatureSetMetric(ch, nc.other, prometheus.GaugeValue, nm.other, part)
285294
}
286295
total := SlurmGetTotal()
287296
ch <- prometheus.MustNewConstMetric(nc.total, prometheus.GaugeValue, total)

nodes_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ func TestNodesMetrics(t *testing.T) {
3636
assert.Equal(t, 40, int(nm.alloc["feature_a,feature_b"]))
3737
assert.Equal(t, 20, int(nm.alloc["feature_a"]))
3838
assert.Equal(t, 10, int(nm.down["null"]))
39+
assert.Equal(t, 42, int(nm.other["null"]))
40+
assert.Equal(t, 24, int(nm.other["feature_a"]))
3941
}

test_data/sinfo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
40|allocated|feature_a,feature_b
44
20|allocated|feature_a
55
10|down*|(null)
6+
42|foo_bar_baz|(null)
7+
24|foo_bar_baz|feature_a
68

0 commit comments

Comments
 (0)