Skip to content

Commit df2b3c6

Browse files
committed
Changed cores to CPUs
1 parent 18a5511 commit df2b3c6

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PROJECT_NAME = prometheus-slurm-exporter
22
ifndef GOPATH
33
GOPATH=$(shell pwd):/usr/share/gocode
44
endif
5-
GOFILES=cores.go main.go nodes.go queue.go scheduler.go
5+
GOFILES=cpus.go main.go nodes.go queue.go scheduler.go
66
GOBIN=bin/$(PROJECT_NAME)
77

88
build:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Prometheus collector and exporter for metrics extracted from the [Slurm](https:/
44

55
## Exported Metrics
66

7-
### State of the Cores
7+
### State of the CPUs
88

9-
* **Allocated**: cores which have been allocated to a job.
10-
* **Idle**: cores not allocated to a job and thus available for use.
11-
* **Other**: cores which are unavailable for use at the moment.
12-
* **Total**: total number of cores.
9+
* **Allocated**: CPUs which have been allocated to a job.
10+
* **Idle**: CPUs not allocated to a job and thus available for use.
11+
* **Other**: CPUs which are unavailable for use at the moment.
12+
* **Total**: total number of CPUs.
1313

1414
[Information extracted from the SLURM **sinfo** command](https://slurm.schedmd.com/sinfo.html)
1515

cpus.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ import (
2424
"strings"
2525
)
2626

27-
type CoresMetrics struct {
27+
type CPUsMetrics struct {
2828
alloc float64
2929
idle float64
3030
other float64
3131
total float64
3232
}
3333

34-
func CoresGetMetrics() *CoresMetrics {
35-
return ParseCoresMetrics(CoresData())
34+
func CPUsGetMetrics() *CPUsMetrics {
35+
return ParseCPUsMetrics(CPUsData())
3636
}
3737

38-
func ParseCoresMetrics(input []byte) *CoresMetrics {
39-
var cm CoresMetrics
38+
func ParseCPUsMetrics(input []byte) *CPUsMetrics {
39+
var cm CPUsMetrics
4040
if strings.Contains(string(input), "/") {
4141
splitted := strings.Split(strings.TrimSpace(string(input)), "/")
4242
cm.alloc, _ = strconv.ParseFloat(splitted[0], 64)
@@ -48,7 +48,7 @@ func ParseCoresMetrics(input []byte) *CoresMetrics {
4848
}
4949

5050
// Execute the sinfo command and return its output
51-
func CoresData() []byte {
51+
func CPUsData() []byte {
5252
cmd := exec.Command("sinfo", "-h", "-o %C")
5353
stdout, err := cmd.StdoutPipe()
5454
if err != nil {
@@ -70,33 +70,33 @@ func CoresData() []byte {
7070
* https://godoc.org/github.com/prometheus/client_golang/prometheus#Collector
7171
*/
7272

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),
7979
}
8080
}
8181

82-
type CoresCollector struct {
82+
type CPUsCollector struct {
8383
alloc *prometheus.Desc
8484
idle *prometheus.Desc
8585
other *prometheus.Desc
8686
total *prometheus.Desc
8787
}
8888

8989
// Send all metric descriptions
90-
func (cc *CoresCollector) Describe(ch chan<- *prometheus.Desc) {
90+
func (cc *CPUsCollector) Describe(ch chan<- *prometheus.Desc) {
9191
ch <- cc.alloc
9292
ch <- cc.idle
9393
ch <- cc.other
9494
ch <- cc.total
9595
}
96-
func (cc *CoresCollector) Collect(ch chan<- prometheus.Metric) {
97-
cm := CoresGetMetrics()
96+
func (cc *CPUsCollector) Collect(ch chan<- prometheus.Metric) {
97+
cm := CPUsGetMetrics()
9898
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)
100100
ch <- prometheus.MustNewConstMetric(cc.other, prometheus.GaugeValue, cm.other)
101101
ch <- prometheus.MustNewConstMetric(cc.total, prometheus.GaugeValue, cm.total)
102102
}

cpus_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
"io/ioutil"
2222
)
2323

24-
func TestCoresMetrics(t *testing.T) {
24+
func TestCPUsMetrics(t *testing.T) {
2525
// Read the input data from a file
26-
file, err := os.Open("test_data/sinfo_cores.txt")
26+
file, err := os.Open("test_data/sinfo_cpus.txt")
2727
if err != nil { t.Fatalf("Can not open test data: %v", err) }
2828
data, err := ioutil.ReadAll(file)
29-
t.Logf("%+v", ParseCoresMetrics(data))
29+
t.Logf("%+v", ParseCPUsMetrics(data))
3030
}
3131

32-
func TestCoresGetMetrics(t *testing.T) {
33-
t.Logf("%+v", CoresGetMetrics())
32+
func TestCPUssGetMetrics(t *testing.T) {
33+
t.Logf("%+v", CPUsGetMetrics())
3434
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func init() {
2828
prometheus.MustRegister(NewSchedulerCollector()) // from scheduler.go
2929
prometheus.MustRegister(NewQueueCollector()) // from queue.go
3030
prometheus.MustRegister(NewNodesCollector()) // from nodes.go
31-
prometheus.MustRegister(NewCoresCollector()) // from cores.go
31+
prometheus.MustRegister(NewCPUsCollector()) // from cpus.go
3232
}
3333

3434
var listenAddress = flag.String(

0 commit comments

Comments
 (0)