Skip to content

Commit d6fd92e

Browse files
committed
Add the "planned" node state
1 parent 73303e7 commit d6fd92e

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

nodes.go

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ import (
2828
)
2929

3030
type NodesMetrics struct {
31-
alloc map[string]float64
32-
comp map[string]float64
33-
down map[string]float64
34-
drain map[string]float64
35-
err map[string]float64
36-
fail map[string]float64
37-
idle map[string]float64
38-
maint map[string]float64
39-
mix map[string]float64
40-
resv map[string]float64
41-
other map[string]float64
42-
total map[string]float64
31+
alloc map[string]float64
32+
comp map[string]float64
33+
down map[string]float64
34+
drain map[string]float64
35+
err map[string]float64
36+
fail map[string]float64
37+
idle map[string]float64
38+
maint map[string]float64
39+
mix map[string]float64
40+
resv map[string]float64
41+
other map[string]float64
42+
planned map[string]float64
43+
total map[string]float64
4344
}
4445

4546
func NodesGetMetrics(part string) *NodesMetrics {
@@ -76,6 +77,7 @@ func InitFeatureSet(nm *NodesMetrics, feature_set string) {
7677
nm.mix[feature_set] = nm.mix[feature_set]
7778
nm.resv[feature_set] = nm.resv[feature_set]
7879
nm.other[feature_set] = nm.other[feature_set]
80+
nm.planned[feature_set] = nm.planned[feature_set]
7981
nm.total[feature_set] = nm.total[feature_set]
8082
}
8183

@@ -99,6 +101,7 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
99101
nm.mix = make(map[string]float64)
100102
nm.resv = make(map[string]float64)
101103
nm.other = make(map[string]float64)
104+
nm.planned = make(map[string]float64)
102105
nm.total = make(map[string]float64)
103106

104107
for _, line := range lines_uniq {
@@ -123,6 +126,7 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
123126
maint := regexp.MustCompile(`^maint`)
124127
mix := regexp.MustCompile(`^mix`)
125128
resv := regexp.MustCompile(`^res`)
129+
planned := regexp.MustCompile(`^planned`)
126130
switch {
127131
case alloc.MatchString(state):
128132
nm.alloc[feature_set] += count
@@ -144,6 +148,8 @@ func ParseNodesMetrics(input []byte) *NodesMetrics {
144148
nm.mix[feature_set] += count
145149
case resv.MatchString(state):
146150
nm.resv[feature_set] += count
151+
case planned.MatchString(state):
152+
nm.planned[feature_set] += count
147153
default:
148154
nm.other[feature_set] += count
149155
}
@@ -220,34 +226,36 @@ func NewNodesCollector() *NodesCollector {
220226
labelnames = append(labelnames, "partition")
221227
labelnames = append(labelnames, "active_feature_set")
222228
return &NodesCollector{
223-
alloc: prometheus.NewDesc("slurm_nodes_alloc", "Allocated nodes", labelnames, nil),
224-
comp: prometheus.NewDesc("slurm_nodes_comp", "Completing nodes", labelnames, nil),
225-
down: prometheus.NewDesc("slurm_nodes_down", "Down nodes", labelnames, nil),
226-
drain: prometheus.NewDesc("slurm_nodes_drain", "Drain nodes", labelnames, nil),
227-
err: prometheus.NewDesc("slurm_nodes_err", "Error nodes", labelnames, nil),
228-
fail: prometheus.NewDesc("slurm_nodes_fail", "Fail nodes", labelnames, nil),
229-
idle: prometheus.NewDesc("slurm_nodes_idle", "Idle nodes", labelnames, nil),
230-
maint: prometheus.NewDesc("slurm_nodes_maint", "Maint nodes", labelnames, nil),
231-
mix: prometheus.NewDesc("slurm_nodes_mix", "Mix nodes", labelnames, nil),
232-
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),
234-
total: prometheus.NewDesc("slurm_nodes_total", "Total number of nodes", nil, nil),
229+
alloc: prometheus.NewDesc("slurm_nodes_alloc", "Allocated nodes", labelnames, nil),
230+
comp: prometheus.NewDesc("slurm_nodes_comp", "Completing nodes", labelnames, nil),
231+
down: prometheus.NewDesc("slurm_nodes_down", "Down nodes", labelnames, nil),
232+
drain: prometheus.NewDesc("slurm_nodes_drain", "Drain nodes", labelnames, nil),
233+
err: prometheus.NewDesc("slurm_nodes_err", "Error nodes", labelnames, nil),
234+
fail: prometheus.NewDesc("slurm_nodes_fail", "Fail nodes", labelnames, nil),
235+
idle: prometheus.NewDesc("slurm_nodes_idle", "Idle nodes", labelnames, nil),
236+
maint: prometheus.NewDesc("slurm_nodes_maint", "Maint nodes", labelnames, nil),
237+
mix: prometheus.NewDesc("slurm_nodes_mix", "Mix nodes", labelnames, nil),
238+
resv: prometheus.NewDesc("slurm_nodes_resv", "Reserved nodes", labelnames, nil),
239+
other: prometheus.NewDesc("slurm_nodes_other", "Nodes reported with an unknown state", labelnames, nil),
240+
planned: prometheus.NewDesc("slurm_nodes_planned", "Planned nodes", labelnames, nil),
241+
total: prometheus.NewDesc("slurm_nodes_total", "Total number of nodes", nil, nil),
235242
}
236243
}
237244

238245
type NodesCollector struct {
239-
alloc *prometheus.Desc
240-
comp *prometheus.Desc
241-
down *prometheus.Desc
242-
drain *prometheus.Desc
243-
err *prometheus.Desc
244-
fail *prometheus.Desc
245-
idle *prometheus.Desc
246-
maint *prometheus.Desc
247-
mix *prometheus.Desc
248-
resv *prometheus.Desc
249-
other *prometheus.Desc
250-
total *prometheus.Desc
246+
alloc *prometheus.Desc
247+
comp *prometheus.Desc
248+
down *prometheus.Desc
249+
drain *prometheus.Desc
250+
err *prometheus.Desc
251+
fail *prometheus.Desc
252+
idle *prometheus.Desc
253+
maint *prometheus.Desc
254+
mix *prometheus.Desc
255+
resv *prometheus.Desc
256+
other *prometheus.Desc
257+
planned *prometheus.Desc
258+
total *prometheus.Desc
251259
}
252260

253261
// Send all metric descriptions
@@ -263,6 +271,7 @@ func (nc *NodesCollector) Describe(ch chan<- *prometheus.Desc) {
263271
ch <- nc.mix
264272
ch <- nc.resv
265273
ch <- nc.other
274+
ch <- nc.planned
266275
ch <- nc.total
267276
}
268277

@@ -291,6 +300,7 @@ func (nc *NodesCollector) Collect(ch chan<- prometheus.Metric) {
291300
SendFeatureSetMetric(ch, nc.mix, prometheus.GaugeValue, nm.mix, part)
292301
SendFeatureSetMetric(ch, nc.resv, prometheus.GaugeValue, nm.resv, part)
293302
SendFeatureSetMetric(ch, nc.other, prometheus.GaugeValue, nm.other, part)
303+
SendFeatureSetMetric(ch, nc.planned, prometheus.GaugeValue, nm.planned, part)
294304
}
295305
total := SlurmGetTotal()
296306
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
@@ -38,4 +38,6 @@ func TestNodesMetrics(t *testing.T) {
3838
assert.Equal(t, 10, int(nm.down["null"]))
3939
assert.Equal(t, 42, int(nm.other["null"]))
4040
assert.Equal(t, 24, int(nm.other["feature_a"]))
41+
assert.Equal(t, 3, int(nm.planned["feature_a"]))
42+
assert.Equal(t, 5, int(nm.planned["feature_b"]))
4143
}

test_data/sinfo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
10|down*|(null)
66
42|foo_bar_baz|(null)
77
24|foo_bar_baz|feature_a
8+
3|planned|feature_a
9+
5|planned|feature_b
810

0 commit comments

Comments
 (0)