From fa72fcba3cbb4b08c65437c8d056dfa571aaf854 Mon Sep 17 00:00:00 2001 From: Jonathan MERCIER Date: Tue, 18 Apr 2023 10:26:06 +0200 Subject: [PATCH 1/5] Replace deprecated module github.com/prometheus/common/log by log --- gpus.go | 2 +- main.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gpus.go b/gpus.go index ca3bcaf..7887d38 100644 --- a/gpus.go +++ b/gpus.go @@ -17,7 +17,7 @@ package main import ( "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/common/log" + "log" "io/ioutil" "os/exec" "strings" diff --git a/main.go b/main.go index 48291fc..dbb4097 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "flag" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/log" + "log" "net/http" ) @@ -56,8 +56,8 @@ func main() { // The Handler function provides a default handler to expose metrics // via an HTTP server. "/metrics" is the usual endpoint for that. - log.Infof("Starting Server: %s", *listenAddress) - log.Infof("GPUs Accounting: %t", *gpuAcct) + log.Printf("Starting Server: %s", *listenAddress) + log.Printf("GPUs Accounting: %t", *gpuAcct) http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(*listenAddress, nil)) } From bbac82d190dfbc98eddc939b4292491f9b4063ae Mon Sep 17 00:00:00 2001 From: Jonathan MERCIER Date: Tue, 18 Apr 2023 10:27:01 +0200 Subject: [PATCH 2/5] Update Makefile in order to allow user to provides go build flags and download module only if needed --- Makefile | 20 +++++++++++++------- README.md | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d7d24bc..8dddaa0 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,22 @@ PROJECT_NAME = prometheus-slurm-exporter -SHELL := $(shell which bash) -eu -o pipefail - -GOPATH := $(shell pwd)/go/modules +ROOTDIR := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) +SRCDIR := $(ROOTDIR) +GOPATH := $(SRCDIR)/go/modules GOBIN := bin/$(PROJECT_NAME) -GOFILES := $(shell ls *.go) +GOFILES := $(wildcard $(SRCIR)/*.go) +GOFLAGS = -v + +all: $(GOBIN) + +download: go/modules/pkg/mod .PHONY: build -build: test $(GOBIN) +build: $(GOBIN) -$(GOBIN): go/modules/pkg/mod $(GOFILES) +$(GOBIN): $(GOFILES) mkdir -p bin @echo "Building $(GOBIN)" - go build -v -o $(GOBIN) + go build $(GOFLAGS) -o $(GOBIN) go/modules/pkg/mod: go.mod go mod download @@ -23,6 +28,7 @@ test: go/modules/pkg/mod $(GOFILES) run: $(GOBIN) $(GOBIN) +.PHONY: clean clean: go clean -modcache rm -fr bin/ go/ diff --git a/README.md b/README.md index 5bfe42a..16d1678 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,23 @@ Prometheus collector and exporter for metrics extracted from the [Slurm](https://slurm.schedmd.com/overview.html) resource scheduling system. +## Build from source + + +with dependencies downloaded: +- github.com/prometheus/client_golang +- github.com/prometheus/common +- github.com/stretchr/testify +```bash +make download +make all +``` + +with dependencies already installed: +```bash +make all +``` + ## Exported Metrics ### State of the CPUs From 47ef503167328802e9cf430a2f9a569776438756 Mon Sep 17 00:00:00 2001 From: Jonathan MERCIER Date: Tue, 18 Apr 2023 10:28:38 +0200 Subject: [PATCH 3/5] Update spec file --- packages/rpm/prometheus-slurm-exporter.spec | 78 +++++++++------------ 1 file changed, 35 insertions(+), 43 deletions(-) diff --git a/packages/rpm/prometheus-slurm-exporter.spec b/packages/rpm/prometheus-slurm-exporter.spec index 2728969..283bdee 100644 --- a/packages/rpm/prometheus-slurm-exporter.spec +++ b/packages/rpm/prometheus-slurm-exporter.spec @@ -1,17 +1,20 @@ -%define __spec_install_post %{nil} -%define debug_package %{nil} -%define __os_install_post %{_dbpath}/brp-compress - -Name: prometheus-slurm-exporter -Version: 0.3 -Release: 1%{?dist} +%define debug_package %{nil} +%global shortname prometheus-slurm-exporter +%global goipath github.com/vpenso/prometheus-slurm-exporter +Version: 0.20 +%gometa +%global golicenses LICENSE +%global godocs README.md + +Name: %{goname} +Release: %autorelease Summary: Prometheus exporter for SLURM metrics Group: Monitoring License: GPL 3.0 -URL: https://github.com/vpenso/prometheus-slurm-exporter +URL: %{gourl} -Source0: https://github.com/vpenso/prometheus-slurm-exporter/releases/download/%{version}/slurm_exporter-%{version}.linux-amd64.tar.gz +Source0: %{gosource} Source1: prometheus-slurm-exporter.service Source2: LICENSE Source3: README.md @@ -22,34 +25,29 @@ Requires(post): systemd Requires(preun): systemd Requires(postun): systemd %{?systemd_requires} -BuildRequires: systemd - -BuildRoot: %{_tmppath}/%{name}-%{version}-1-root +BuildRequires: systemd-rpm-macros +BuildRequires: golang(github.com/prometheus/client_golang/prometheus) +BuildRequires: golang-github-prometheus-common-devel %description A Prometheus exporter for metrics extracted from the Slurm resource scheduling system. %prep -%setup -q +%goprep +%autosetup -N -T -D -a 0 -n %{shortname}-%{version} %build -# Empty section. +%gobuild -o bin/%{shortname} + %install -rm -rf %{buildroot} -mkdir -vp %{buildroot} -mkdir -vp %{buildroot}%{_unitdir}/ -mkdir -vp %{buildroot}/usr/bin -mkdir -vp %{buildroot}/usr/share/doc/prometheus-slurm-exporter-%{version} -mkdir -vp %{buildroot}/var/lib/prometheus -install -m 755 prometheus-slurm-exporter %{buildroot}/usr/bin/prometheus-slurm-exporter -install -m 644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/prometheus-slurm-exporter.service -install -m 644 %{SOURCE2} %{buildroot}/usr/share/doc/prometheus-slurm-exporter-%{version}/LICENSE -install -m 644 %{SOURCE3} %{buildroot}/usr/share/doc/prometheus-slurm-exporter-%{version}/README.md - -%clean -rm -rf %{buildroot} - +install -m 0755 -vd %{buildroot}%{_bindir} +install -m 0755 bin/%{shortname} %{buildroot}%{_bindir} + +install -m 0755 -vd %{buildroot}%{_unitdir}/ +install -m 0755 -vd %{buildroot}/%{_sharedstatedir}/prometheus +install -m 644 %{SOURCE1} %{buildroot}/%{_unitdir}/%{shortname}.service + %pre getent group prometheus >/dev/null || groupadd -r prometheus getent passwd prometheus >/dev/null || \ @@ -58,27 +56,21 @@ getent passwd prometheus >/dev/null || \ exit 0 %post -systemctl enable %{name}.service -systemctl start %{name}.service +systemctl enable --now %{shortname}.service +%systemd_post %{shortname}.service %preun -%systemd_preun %{name}.service +%systemd_preun %{shortname}.service %postun -%systemd_postun_with_restart %{name}.service +%systemd_postun_with_restart %{shortname}.service %files -%defattr(-,root,root,-) -%doc LICENSE +%license LICENSE %doc README.md -%{_bindir}/prometheus-slurm-exporter -%{_unitdir}/%{name}.service -%attr(755, prometheus, prometheus)/var/lib/prometheus +%{_bindir}/%{shortname} +%{_unitdir}/%{shortname}.service +%attr(755, prometheus, prometheus)/%{_sharedstatedir}/prometheus %changelog -* Fri Feb 16 2018 Matteo - 0.3 -- Fix issue #4 -* Wed Jan 31 2018 Matteo - 0.2 -- Fix issue #3 -* Mon Dec 04 2017 Matteo - 0.1 -- Full commit history: https://github.com/vpenso/prometheus-slurm-exporter/commits/master +%autochangelog From b393d5ff56e4e700c6f4223756aa701f91f8970c Mon Sep 17 00:00:00 2001 From: Jonathan MERCIER Date: Tue, 18 Apr 2023 11:02:27 +0200 Subject: [PATCH 4/5] Allow to provides go flags for test stage --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 8dddaa0..c2d89d5 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ GOPATH := $(SRCDIR)/go/modules GOBIN := bin/$(PROJECT_NAME) GOFILES := $(wildcard $(SRCIR)/*.go) GOFLAGS = -v +GOTESTFLAGS = all: $(GOBIN) From fb6524beb3e4c91f141f2772ecd1ce4a0c48d6a7 Mon Sep 17 00:00:00 2001 From: Jonathan MERCIER Date: Tue, 18 Apr 2023 11:02:51 +0200 Subject: [PATCH 5/5] SPEC file use the make file --- packages/rpm/prometheus-slurm-exporter.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rpm/prometheus-slurm-exporter.spec b/packages/rpm/prometheus-slurm-exporter.spec index 283bdee..2c95efa 100644 --- a/packages/rpm/prometheus-slurm-exporter.spec +++ b/packages/rpm/prometheus-slurm-exporter.spec @@ -37,7 +37,7 @@ A Prometheus exporter for metrics extracted from the Slurm resource scheduling s %autosetup -N -T -D -a 0 -n %{shortname}-%{version} %build -%gobuild -o bin/%{shortname} +make all GOFLAGS=%{gobuildflags} %install