Skip to content

Commit

Permalink
add lastConsumed and lastDeficit for slurm remote license
Browse files Browse the repository at this point in the history
relates to #108
  • Loading branch information
kbroch-rivosinc committed Dec 16, 2024
1 parent 059f76a commit 349d34e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ profiling and optimization consideration.

### Getting Started

Golang >=20 is required. From there, follow the `justfile` or run `just prod` to start a dev server.
Golang >= 1.20 is required. From there, follow the `justfile` or run `just prod` to start a dev server.
You can also install the exporter directly with `go install github.com/rivosinc/prometheus-slurm-exporter@latest`. Then you can run `prometheus-slurm-exporter -h`.

```bash
Expand Down
16 changes: 8 additions & 8 deletions exporter/fixtures/license_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
},
"licenses": [{
"LicenseName": "AscentLintBase",
"Total": 7,
"Used": 0,
"Free": 7,
"Remote": false,
"Reserved": 0,
"LastConsumed": 0,
"LastDeficit": 0,
"LastUpdate": 0
"Total": 420,
"Used": 213,
"Free": 205,
"Remote": true,
"Reserved": 357,
"LastConsumed": 218,
"LastDeficit": 2,
"LastUpdate": "2024-12-16T08:42:16"
}],
"warnings": [],
"errors": []
Expand Down
50 changes: 32 additions & 18 deletions exporter/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ package exporter
import (
"encoding/json"
"fmt"
"log/slog"
"time"

"github.com/prometheus/client_golang/prometheus"
"log/slog"
)

type LicenseMetric struct {
LicenseName string `json:"LicenseName"`
Total int `json:"Total"`
Used int `json:"Used"`
Free int `json:"Free"`
Remote bool `json:"Remote"`
Reserved int `json:"Reserved"`
LicenseName string `json:"LicenseName"`
Total int `json:"Total"`
Used int `json:"Used"`
Free int `json:"Free"`
Remote bool `json:"Remote"`
Reserved int `json:"Reserved"`
LastConsumed int `json:"LastConsumed"`
LastDeficit int `json:"LastDeficit"`
}

type scontrolLicResponse struct {
Expand Down Expand Up @@ -69,12 +71,14 @@ func (cjl *CliJsonLicMetricFetcher) ScrapeError() prometheus.Counter {
}

type LicCollector struct {
fetcher SlurmMetricFetcher[LicenseMetric]
licTotal *prometheus.Desc
licUsed *prometheus.Desc
licFree *prometheus.Desc
licReserved *prometheus.Desc
licScrapeError prometheus.Counter
fetcher SlurmMetricFetcher[LicenseMetric]
licTotal *prometheus.Desc
licUsed *prometheus.Desc
licFree *prometheus.Desc
licReserved *prometheus.Desc
licLastConsumed *prometheus.Desc
licLastDeficit *prometheus.Desc
licScrapeError prometheus.Counter
}

func NewLicCollector(config *Config) *LicCollector {
Expand All @@ -88,11 +92,13 @@ func NewLicCollector(config *Config) *LicCollector {
}),
}
return &LicCollector{
fetcher: fetcher,
licTotal: prometheus.NewDesc("slurm_lic_total", "slurm license total", []string{"name"}, nil),
licUsed: prometheus.NewDesc("slurm_lic_used", "slurm license used", []string{"name"}, nil),
licFree: prometheus.NewDesc("slurm_lic_free", "slurm license free", []string{"name"}, nil),
licReserved: prometheus.NewDesc("slurm_lic_reserved", "slurm license reserved", []string{"name"}, nil),
fetcher: fetcher,
licTotal: prometheus.NewDesc("slurm_lic_total", "slurm license total", []string{"name"}, nil),
licUsed: prometheus.NewDesc("slurm_lic_used", "slurm license used", []string{"name"}, nil),
licFree: prometheus.NewDesc("slurm_lic_free", "slurm license free", []string{"name"}, nil),
licLastConsumed: prometheus.NewDesc("slurm_lic_last_consumed", "slurm license last_consumed", []string{"name"}, nil),
licLastDeficit: prometheus.NewDesc("slurm_lic_last_deficit", "slurm license last_deficit", []string{"name"}, nil),
licReserved: prometheus.NewDesc("slurm_lic_reserved", "slurm license reserved", []string{"name"}, nil),
licScrapeError: prometheus.NewCounter(prometheus.CounterOpts{
Name: "slurm_lic_scrape_error",
Help: "slurm license scrape error",
Expand All @@ -105,6 +111,8 @@ func (lc *LicCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- lc.licUsed
ch <- lc.licFree
ch <- lc.licReserved
ch <- lc.licLastConsumed
ch <- lc.licLastDeficit
ch <- lc.licScrapeError.Desc()
}

Expand All @@ -131,5 +139,11 @@ func (lc *LicCollector) Collect(ch chan<- prometheus.Metric) {
if lic.Reserved > 0 {
ch <- prometheus.MustNewConstMetric(lc.licReserved, prometheus.GaugeValue, float64(lic.Reserved), lic.LicenseName)
}
if lic.LastConsumed > 0 {
ch <- prometheus.MustNewConstMetric(lc.licLastConsumed, prometheus.GaugeValue, float64(lic.LastConsumed), lic.LicenseName)
}
if lic.Reserved > 0 {
ch <- prometheus.MustNewConstMetric(lc.licLastDeficit, prometheus.GaugeValue, float64(lic.LastDeficit), lic.LicenseName)
}
}
}
2 changes: 1 addition & 1 deletion exporter/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestLicCollect_ColectionE(t *testing.T) {
licMetrics = append(licMetrics, metric)
}

assert.Equal(3, len(licMetrics))
assert.Equal(5, len(licMetrics))
}

func TestLicDescribe(t *testing.T) {
Expand Down

0 comments on commit 349d34e

Please sign in to comment.