Skip to content

Commit

Permalink
limit to metrics relevant over time
Browse files Browse the repository at this point in the history
  • Loading branch information
vpenso committed Oct 9, 2020
1 parent d782cc2 commit ca20fec
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func AccountsData() []byte {
}

type JobMetrics struct {
cancelled float64
completed float64
pending float64
running float64
suspended float64
Expand All @@ -56,20 +54,14 @@ func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
account := strings.Split(line,"|")[1]
_,key := accounts[account]
if !key {
accounts[account] = &JobMetrics{0,0,0,0,0}
accounts[account] = &JobMetrics{0,0,0}
}
state := strings.Split(line,"|")[2]
state = strings.ToLower(state)
cancelled := regexp.MustCompile(`^cancelled`)
completed := regexp.MustCompile(`^completed`)
pending := regexp.MustCompile(`^pending`)
running := regexp.MustCompile(`^running`)
suspended := regexp.MustCompile(`^suspended`)
switch {
case cancelled.MatchString(state) == true:
accounts[account].cancelled++
case completed.MatchString(state) == true:
accounts[account].completed++
case pending.MatchString(state) == true:
accounts[account].pending++
case running.MatchString(state) == true:
Expand All @@ -83,8 +75,6 @@ func ParseAccountsMetrics(input []byte) map[string]*JobMetrics {
}

type AccountsCollector struct {
cancelled *prometheus.Desc
completed *prometheus.Desc
pending *prometheus.Desc
running *prometheus.Desc
suspended *prometheus.Desc
Expand All @@ -93,17 +83,13 @@ type AccountsCollector struct {
func NewAccountsCollector() *AccountsCollector {
labels := []string{"account"}
return &AccountsCollector{
cancelled: prometheus.NewDesc("slurm_account_jobs_cancelled", "Cancelled jobs for account", labels, nil),
completed: prometheus.NewDesc("slurm_account_jobs_completed", "Completed jobs for account", labels, nil),
running: prometheus.NewDesc("slurm_account_jobs_running", "Running jobs for account", labels, nil),
pending: prometheus.NewDesc("slurm_account_jobs_pending", "Pending jobs for account", labels, nil),
suspended: prometheus.NewDesc("slurm_account_jobs_suspended", "Suspended jobs for account", labels, nil),
}
}

func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- ac.cancelled
ch <- ac.completed
ch <- ac.pending
ch <- ac.running
ch <- ac.suspended
Expand All @@ -112,8 +98,6 @@ func (ac *AccountsCollector) Describe(ch chan<- *prometheus.Desc) {
func (ac *AccountsCollector) Collect(ch chan<- prometheus.Metric) {
am := ParseAccountsMetrics(AccountsData())
for a := range am {
ch <- prometheus.MustNewConstMetric(ac.cancelled, prometheus.GaugeValue, am[a].cancelled, a)
ch <- prometheus.MustNewConstMetric(ac.completed, prometheus.GaugeValue, am[a].completed, a)
ch <- prometheus.MustNewConstMetric(ac.pending, prometheus.GaugeValue, am[a].pending, a)
ch <- prometheus.MustNewConstMetric(ac.running, prometheus.GaugeValue, am[a].running, a)
ch <- prometheus.MustNewConstMetric(ac.suspended, prometheus.GaugeValue, am[a].suspended, a)
Expand Down

0 comments on commit ca20fec

Please sign in to comment.