Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPU metrics for pending jobs #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add new metric for pending CPUs per account
 * add metric slurm_account_cpus_pending
atombaby committed Apr 20, 2021
commit 5702eacaf26ce4bb42a49f489119bc3048ef594d
10 changes: 9 additions & 1 deletion accounts.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ func AccountsData() []byte {

type JobMetrics struct {
pending float64
pending_cpus float64
running float64
running_cpus float64
suspended float64
@@ -56,7 +57,7 @@ func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
account := strings.Split(line,"|")[1]
_,key := accounts[account]
if !key {
accounts[account] = &JobMetrics{0,0,0,0}
accounts[account] = &JobMetrics{0,0,0,0,0}
}
state := strings.Split(line,"|")[2]
state = strings.ToLower(state)
@@ -67,6 +68,7 @@ func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
switch {
case pending.MatchString(state) == true:
accounts[account].pending++
accounts[account].pending_cpus += cpus
case running.MatchString(state) == true:
accounts[account].running++
accounts[account].running_cpus += cpus
@@ -80,6 +82,7 @@ func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {

type AccountsCollector struct {
pending *prometheus.Desc
pending_cpus *prometheus.Desc
running *prometheus.Desc
running_cpus *prometheus.Desc
suspended *prometheus.Desc
@@ -89,6 +92,7 @@ func NewAccountsCollector() *AccountsCollector {
labels := []string{"account"}
return &AccountsCollector{
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
pending_cpus: prometheus.NewDesc("slurm_account_cpus_pending", "Pending jobs for account", labels, nil),
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
running_cpus: prometheus.NewDesc("slurm_account_cpus_running", "Running cpus for account", labels, nil),
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
@@ -97,6 +101,7 @@ func NewAccountsCollector() *AccountsCollector {

func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- ac.pending
ch <- ac.pending_cpus
ch <- ac.running
ch <- ac.running_cpus
ch <- ac.suspended
@@ -108,6 +113,9 @@ func (ac *AccountsCollector) Collect(ch chan<- prometheus.Metric) {
if am[a].pending > 0 {
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
}
if am[a].pending_cpus > 0 {
ch <- prometheus.MustNewConstMetric(ac.pending_cpus, prometheus.GaugeValue, am[a].pending_cpus, a)
}
if am[a].running > 0 {
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
}