Skip to content

Commit 7f340d6

Browse files
committed
add the other metric for partitions
1 parent 7548b3a commit 7f340d6

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

partitions.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os/exec"
2121
"log"
2222
"strings"
23-
"strconv"
23+
"strconv"
2424
"github.com/prometheus/client_golang/prometheus"
2525
)
2626

@@ -59,26 +59,41 @@ func ParsePartitionsMetrics(input []byte) map[string]*PartitionMetrics {
5959
partitions[partition] = &PartitionMetrics{0,0,0,0}
6060
}
6161
states := strings.Split(line,",")[1]
62-
allocated,_ := strconv.ParseFloat(strings.Split(states,"/")[0],64)
62+
allocated,_ := strconv.ParseFloat(strings.Split(states,"/")[0],64)
63+
idle,_ := strconv.ParseFloat(strings.Split(states,"/")[1],64)
64+
other,_ := strconv.ParseFloat(strings.Split(states,"/")[2],64)
65+
total,_ := strconv.ParseFloat(strings.Split(states,"/")[3],64)
6366
partitions[partition].allocated = allocated
67+
partitions[partition].idle = idle
68+
partitions[partition].other = other
69+
partitions[partition].total = total
6470
}
6571
}
6672
return partitions
6773
}
6874

6975
type PartitionsCollector struct {
7076
allocated *prometheus.Desc
77+
idle *prometheus.Desc
78+
other *prometheus.Desc
79+
total *prometheus.Desc
7180
}
7281

7382
func NewPartitionsCollector() *PartitionsCollector {
7483
labels := []string{"partition"}
7584
return &PartitionsCollector{
7685
allocated: prometheus.NewDesc("slurm_partition_cpus_allocated", "Allocated CPUs for partition", labels,nil),
86+
idle: prometheus.NewDesc("slurm_partition_cpus_idle", "Idle CPUs for partition", labels,nil),
87+
other: prometheus.NewDesc("slurm_partition_cpus_other", "Other CPUs for partition", labels,nil),
88+
total: prometheus.NewDesc("slurm_partition_cpus_total", "Total CPUs for partition", labels,nil),
7789
}
7890
}
7991

8092
func (pc *PartitionsCollector) Describe(ch chan<- *prometheus.Desc) {
8193
ch <- pc.allocated
94+
ch <- pc.idle
95+
ch <- pc.other
96+
ch <- pc.total
8297
}
8398

8499
func (pc *PartitionsCollector) Collect(ch chan<- prometheus.Metric) {
@@ -87,5 +102,14 @@ func (pc *PartitionsCollector) Collect(ch chan<- prometheus.Metric) {
87102
if pm[p].allocated > 0 {
88103
ch <- prometheus.MustNewConstMetric(pc.allocated, prometheus.GaugeValue, pm[p].allocated, p)
89104
}
105+
if pm[p].idle > 0 {
106+
ch <- prometheus.MustNewConstMetric(pc.idle, prometheus.GaugeValue, pm[p].idle, p)
107+
}
108+
if pm[p].other > 0 {
109+
ch <- prometheus.MustNewConstMetric(pc.other, prometheus.GaugeValue, pm[p].other, p)
110+
}
111+
if pm[p].total > 0 {
112+
ch <- prometheus.MustNewConstMetric(pc.total, prometheus.GaugeValue, pm[p].total, p)
113+
}
90114
}
91115
}

0 commit comments

Comments
 (0)