@@ -24,19 +24,19 @@ import (
24
24
"strings"
25
25
)
26
26
27
- type CoresMetrics struct {
27
+ type CPUsMetrics struct {
28
28
alloc float64
29
29
idle float64
30
30
other float64
31
31
total float64
32
32
}
33
33
34
- func CoresGetMetrics () * CoresMetrics {
35
- return ParseCoresMetrics ( CoresData ())
34
+ func CPUsGetMetrics () * CPUsMetrics {
35
+ return ParseCPUsMetrics ( CPUsData ())
36
36
}
37
37
38
- func ParseCoresMetrics (input []byte ) * CoresMetrics {
39
- var cm CoresMetrics
38
+ func ParseCPUsMetrics (input []byte ) * CPUsMetrics {
39
+ var cm CPUsMetrics
40
40
if strings .Contains (string (input ), "/" ) {
41
41
splitted := strings .Split (strings .TrimSpace (string (input )), "/" )
42
42
cm .alloc , _ = strconv .ParseFloat (splitted [0 ], 64 )
@@ -48,7 +48,7 @@ func ParseCoresMetrics(input []byte) *CoresMetrics {
48
48
}
49
49
50
50
// Execute the sinfo command and return its output
51
- func CoresData () []byte {
51
+ func CPUsData () []byte {
52
52
cmd := exec .Command ("sinfo" , "-h" , "-o %C" )
53
53
stdout , err := cmd .StdoutPipe ()
54
54
if err != nil {
@@ -70,33 +70,33 @@ func CoresData() []byte {
70
70
* https://godoc.org/github.com/prometheus/client_golang/prometheus#Collector
71
71
*/
72
72
73
- func NewCoresCollector () * CoresCollector {
74
- return & CoresCollector {
75
- alloc : prometheus .NewDesc ("slurm_cores_alloc " , "Allocated cores " , nil , nil ),
76
- idle : prometheus .NewDesc ("slurm_cores_idle " , "Idle cores " , nil , nil ),
77
- other : prometheus .NewDesc ("slurm_cores_other " , "Mix cores " , nil , nil ),
78
- total : prometheus .NewDesc ("slurm_cores_total " , "Total cores " , nil , nil ),
73
+ func NewCPUsCollector () * CPUsCollector {
74
+ return & CPUsCollector {
75
+ alloc : prometheus .NewDesc ("slurm_cpus_alloc " , "Allocated CPUs " , nil , nil ),
76
+ idle : prometheus .NewDesc ("slurm_cpus_idle " , "Idle CPUs " , nil , nil ),
77
+ other : prometheus .NewDesc ("slurm_cpus_other " , "Mix CPUs " , nil , nil ),
78
+ total : prometheus .NewDesc ("slurm_cpus_total " , "Total CPUs " , nil , nil ),
79
79
}
80
80
}
81
81
82
- type CoresCollector struct {
82
+ type CPUsCollector struct {
83
83
alloc * prometheus.Desc
84
84
idle * prometheus.Desc
85
85
other * prometheus.Desc
86
86
total * prometheus.Desc
87
87
}
88
88
89
89
// Send all metric descriptions
90
- func (cc * CoresCollector ) Describe (ch chan <- * prometheus.Desc ) {
90
+ func (cc * CPUsCollector ) Describe (ch chan <- * prometheus.Desc ) {
91
91
ch <- cc .alloc
92
92
ch <- cc .idle
93
93
ch <- cc .other
94
94
ch <- cc .total
95
95
}
96
- func (cc * CoresCollector ) Collect (ch chan <- prometheus.Metric ) {
97
- cm := CoresGetMetrics ()
96
+ func (cc * CPUsCollector ) Collect (ch chan <- prometheus.Metric ) {
97
+ cm := CPUsGetMetrics ()
98
98
ch <- prometheus .MustNewConstMetric (cc .alloc , prometheus .GaugeValue , cm .alloc )
99
- ch <- prometheus .MustNewConstMetric (cc .idle , prometheus .GaugeValue , cm .idle )
99
+ ch <- prometheus .MustNewConstMetric (cc .idle , prometheus .GaugeValue , cm .idle )
100
100
ch <- prometheus .MustNewConstMetric (cc .other , prometheus .GaugeValue , cm .other )
101
101
ch <- prometheus .MustNewConstMetric (cc .total , prometheus .GaugeValue , cm .total )
102
102
}
0 commit comments