Skip to content

Commit e7064fd

Browse files
committed
Corrected formatting of the project
I found there were inconsistencies in tab characters within the files. So I ran `go fmt` and this is the result.
1 parent a04f2a2 commit e7064fd

File tree

6 files changed

+301
-303
lines changed

6 files changed

+301
-303
lines changed

accounts.go

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
1616
package main
1717

1818
import (
19-
"io/ioutil"
20-
"os/exec"
21-
"log"
22-
"strings"
23-
"strconv"
24-
"regexp"
25-
"github.com/prometheus/client_golang/prometheus"
19+
"github.com/prometheus/client_golang/prometheus"
20+
"io/ioutil"
21+
"log"
22+
"os/exec"
23+
"regexp"
24+
"strconv"
25+
"strings"
2626
)
2727

2828
func AccountsData() []byte {
29-
cmd := exec.Command("squeue","-a","-r","-h","-o %A|%a|%T|%C")
30-
stdout, err := cmd.StdoutPipe()
29+
cmd := exec.Command("squeue", "-a", "-r", "-h", "-o %A|%a|%T|%C")
30+
stdout, err := cmd.StdoutPipe()
3131
if err != nil {
3232
log.Fatal(err)
3333
}
@@ -42,80 +42,80 @@ func AccountsData() []byte {
4242
}
4343

4444
type JobMetrics struct {
45-
pending float64
46-
running float64
47-
running_cpus float64
48-
suspended float64
45+
pending float64
46+
running float64
47+
running_cpus float64
48+
suspended float64
4949
}
5050

5151
func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
52-
accounts := make(map[string]*JobMetrics)
53-
lines := strings.Split(string(input), "\n")
54-
for _, line := range lines {
55-
if strings.Contains(line,"|") {
56-
account := strings.Split(line,"|")[1]
57-
_,key := accounts[account]
58-
if !key {
59-
accounts[account] = &JobMetrics{0,0,0,0}
60-
}
61-
state := strings.Split(line,"|")[2]
62-
state = strings.ToLower(state)
63-
cpus,_ := strconv.ParseFloat(strings.Split(line,"|")[3],64)
64-
pending := regexp.MustCompile(`^pending`)
65-
running := regexp.MustCompile(`^running`)
66-
suspended := regexp.MustCompile(`^suspended`)
67-
switch {
68-
case pending.MatchString(state) == true:
69-
accounts[account].pending++
70-
case running.MatchString(state) == true:
71-
accounts[account].running++
72-
accounts[account].running_cpus += cpus
73-
case suspended.MatchString(state) == true:
74-
accounts[account].suspended++
75-
}
76-
}
77-
}
78-
return accounts
52+
accounts := make(map[string]*JobMetrics)
53+
lines := strings.Split(string(input), "\n")
54+
for _, line := range lines {
55+
if strings.Contains(line, "|") {
56+
account := strings.Split(line, "|")[1]
57+
_, key := accounts[account]
58+
if !key {
59+
accounts[account] = &JobMetrics{0, 0, 0, 0}
60+
}
61+
state := strings.Split(line, "|")[2]
62+
state = strings.ToLower(state)
63+
cpus, _ := strconv.ParseFloat(strings.Split(line, "|")[3], 64)
64+
pending := regexp.MustCompile(`^pending`)
65+
running := regexp.MustCompile(`^running`)
66+
suspended := regexp.MustCompile(`^suspended`)
67+
switch {
68+
case pending.MatchString(state) == true:
69+
accounts[account].pending++
70+
case running.MatchString(state) == true:
71+
accounts[account].running++
72+
accounts[account].running_cpus += cpus
73+
case suspended.MatchString(state) == true:
74+
accounts[account].suspended++
75+
}
76+
}
77+
}
78+
return accounts
7979
}
8080

8181
type AccountsCollector struct {
82-
pending *prometheus.Desc
83-
running *prometheus.Desc
84-
running_cpus *prometheus.Desc
85-
suspended *prometheus.Desc
82+
pending *prometheus.Desc
83+
running *prometheus.Desc
84+
running_cpus *prometheus.Desc
85+
suspended *prometheus.Desc
8686
}
8787

8888
func NewAccountsCollector() *AccountsCollector {
89-
labels := []string{"account"}
90-
return &AccountsCollector{
91-
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
92-
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
93-
running_cpus: prometheus.NewDesc("slurm_account_cpus_running", "Running cpus for account", labels, nil),
94-
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
95-
}
89+
labels := []string{"account"}
90+
return &AccountsCollector{
91+
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
92+
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
93+
running_cpus: prometheus.NewDesc("slurm_account_cpus_running", "Running cpus for account", labels, nil),
94+
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
95+
}
9696
}
9797

9898
func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
99-
ch <- ac.pending
100-
ch <- ac.running
101-
ch <- ac.running_cpus
102-
ch <- ac.suspended
99+
ch <- ac.pending
100+
ch <- ac.running
101+
ch <- ac.running_cpus
102+
ch <- ac.suspended
103103
}
104104

105105
func (ac *AccountsCollector) Collect(ch chan<- prometheus.Metric) {
106-
am := ParseAccountsMetrics(AccountsData())
107-
for a := range am {
108-
if am[a].pending > 0 {
109-
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
110-
}
111-
if am[a].running > 0 {
112-
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
113-
}
114-
if am[a].running_cpus > 0 {
115-
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
116-
}
117-
if am[a].suspended > 0 {
118-
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
119-
}
120-
}
106+
am := ParseAccountsMetrics(AccountsData())
107+
for a := range am {
108+
if am[a].pending > 0 {
109+
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
110+
}
111+
if am[a].running > 0 {
112+
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
113+
}
114+
if am[a].running_cpus > 0 {
115+
ch <- prometheus.MustNewConstMetric(ac.running_cpus, prometheus.GaugeValue, am[a].running_cpus, a)
116+
}
117+
if am[a].suspended > 0 {
118+
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
119+
}
120+
}
121121
}

gpus.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"github.com/prometheus/common/log"
2121
"io/ioutil"
2222
"os/exec"
23-
"strings"
2423
"strconv"
24+
"strings"
2525
)
2626

2727
type GPUsMetrics struct {
@@ -66,7 +66,7 @@ func ParseTotalGPUs() float64 {
6666
descriptor := strings.Fields(line)[1]
6767
descriptor = strings.TrimPrefix(descriptor, "gpu:")
6868
descriptor = strings.Split(descriptor, "(")[0]
69-
node_gpus, _ := strconv.ParseFloat(descriptor, 64)
69+
node_gpus, _ := strconv.ParseFloat(descriptor, 64)
7070
num_gpus += node_gpus
7171
}
7272
}
@@ -111,9 +111,9 @@ func Execute(command string, arguments []string) []byte {
111111

112112
func NewGPUsCollector() *GPUsCollector {
113113
return &GPUsCollector{
114-
alloc: prometheus.NewDesc("slurm_gpus_alloc", "Allocated GPUs", nil, nil),
115-
idle: prometheus.NewDesc("slurm_gpus_idle", "Idle GPUs", nil, nil),
116-
total: prometheus.NewDesc("slurm_gpus_total", "Total GPUs", nil, nil),
114+
alloc: prometheus.NewDesc("slurm_gpus_alloc", "Allocated GPUs", nil, nil),
115+
idle: prometheus.NewDesc("slurm_gpus_idle", "Idle GPUs", nil, nil),
116+
total: prometheus.NewDesc("slurm_gpus_total", "Total GPUs", nil, nil),
117117
utilization: prometheus.NewDesc("slurm_gpus_utilization", "Total GPU utilization", nil, nil),
118118
}
119119
}

main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import (
2525

2626
func init() {
2727
// Metrics have to be registered to be exposed
28-
prometheus.MustRegister(NewAccountsCollector()) // from accounts.go
29-
prometheus.MustRegister(NewCPUsCollector()) // from cpus.go
30-
prometheus.MustRegister(NewGPUsCollector()) // from gpus.go
31-
prometheus.MustRegister(NewNodesCollector()) // from nodes.go
32-
prometheus.MustRegister(NewPartitionsCollector()) // from partitions.go
33-
prometheus.MustRegister(NewQueueCollector()) // from queue.go
34-
prometheus.MustRegister(NewSchedulerCollector()) // from scheduler.go
35-
prometheus.MustRegister(NewFairShareCollector()) // from sshare.go
36-
prometheus.MustRegister(NewUsersCollector()) // from users.go
28+
prometheus.MustRegister(NewAccountsCollector()) // from accounts.go
29+
prometheus.MustRegister(NewCPUsCollector()) // from cpus.go
30+
prometheus.MustRegister(NewGPUsCollector()) // from gpus.go
31+
prometheus.MustRegister(NewNodesCollector()) // from nodes.go
32+
prometheus.MustRegister(NewPartitionsCollector()) // from partitions.go
33+
prometheus.MustRegister(NewQueueCollector()) // from queue.go
34+
prometheus.MustRegister(NewSchedulerCollector()) // from scheduler.go
35+
prometheus.MustRegister(NewFairShareCollector()) // from sshare.go
36+
prometheus.MustRegister(NewUsersCollector()) // from users.go
3737
}
3838

3939
var listenAddress = flag.String(

0 commit comments

Comments
 (0)