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

Adding Running jobs per partition #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
38 changes: 37 additions & 1 deletion partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ func PartitionsData() []byte {
return out
}


func PartitionsRunningJobsData() []byte {
cmd := exec.Command("squeue","-a","-r","-h","-o%P","--states=RUNNING")
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
if err := cmd.Start(); err != nil {
log.Fatal(err)
}
out, _ := ioutil.ReadAll(stdout)
if err := cmd.Wait(); err != nil {
log.Fatal(err)
}
return out
}


func PartitionsPendingJobsData() []byte {
cmd := exec.Command("squeue","-a","-r","-h","-o%P","--states=PENDING")
stdout, err := cmd.StdoutPipe()
Expand All @@ -61,6 +79,7 @@ type PartitionMetrics struct {
idle float64
other float64
pending float64
running float64
total float64
}

Expand All @@ -73,7 +92,7 @@ func ParsePartitionsMetrics() map[string]*PartitionMetrics {
partition := strings.Split(line,",")[0]
_,key := partitions[partition]
if !key {
partitions[partition] = &PartitionMetrics{0,0,0,0,0}
partitions[partition] = &PartitionMetrics{0,0,0,0,0,0}
}
states := strings.Split(line,",")[1]
allocated,_ := strconv.ParseFloat(strings.Split(states,"/")[0],64)
Expand All @@ -96,6 +115,17 @@ func ParsePartitionsMetrics() map[string]*PartitionMetrics {
}
}

// get list of running jobs by partition name
list_r := strings.Split(string(PartitionsRunningJobsData()),"\n")
for _,partition := range list_r {
// accumulate the number of running jobs
_,key := partitions[partition]
if key {
partitions[partition].running += 1
}
}



return partitions
}
Expand All @@ -105,6 +135,7 @@ type PartitionsCollector struct {
idle *prometheus.Desc
other *prometheus.Desc
pending *prometheus.Desc
running *prometheus.Desc
total *prometheus.Desc
}

Expand All @@ -115,6 +146,7 @@ func NewPartitionsCollector() *PartitionsCollector {
idle: prometheus.NewDesc("slurm_partition_cpus_idle", "Idle CPUs for partition", labels,nil),
other: prometheus.NewDesc("slurm_partition_cpus_other", "Other CPUs for partition", labels,nil),
pending: prometheus.NewDesc("slurm_partition_jobs_pending", "Pending jobs for partition", labels,nil),
running: prometheus.NewDesc("slurm_partition_jobs_running", "Running jobs for partition", labels,nil),
total: prometheus.NewDesc("slurm_partition_cpus_total", "Total CPUs for partition", labels,nil),
}
}
Expand All @@ -124,6 +156,7 @@ func (pc *PartitionsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- pc.idle
ch <- pc.other
ch <- pc.pending
ch <- pc.running
ch <- pc.total
}

Expand All @@ -142,6 +175,9 @@ func (pc *PartitionsCollector) Collect(ch chan<- prometheus.Metric) {
if pm[p].pending > 0 {
ch <- prometheus.MustNewConstMetric(pc.pending, prometheus.GaugeValue, pm[p].pending, p)
}
if pm[p].running > 0 {
ch <- prometheus.MustNewConstMetric(pc.running, prometheus.GaugeValue, pm[p].running, p)
}
if pm[p].total > 0 {
ch <- prometheus.MustNewConstMetric(pc.total, prometheus.GaugeValue, pm[p].total, p)
}
Expand Down