diff --git a/README.md b/README.md index e32a693..fc0004c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/exporter/fixtures/license_out.json b/exporter/fixtures/license_out.json index 9d7e249..d92862e 100644 --- a/exporter/fixtures/license_out.json +++ b/exporter/fixtures/license_out.json @@ -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": [] diff --git a/exporter/license.go b/exporter/license.go index 938a1e0..56ca8e9 100644 --- a/exporter/license.go +++ b/exporter/license.go @@ -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 { @@ -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 { @@ -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", @@ -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() } @@ -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) + } } } diff --git a/exporter/license_test.go b/exporter/license_test.go index b9612aa..a219786 100644 --- a/exporter/license_test.go +++ b/exporter/license_test.go @@ -76,7 +76,7 @@ func TestLicCollect_ColectionE(t *testing.T) { licMetrics = append(licMetrics, metric) } - assert.Equal(3, len(licMetrics)) + assert.Equal(7, len(licMetrics)) } func TestLicDescribe(t *testing.T) {