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

Update code to follow prometheus library and build system #99

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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
GOTESTFLAGS =

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
Expand All @@ -23,6 +29,7 @@ test: go/modules/pkg/mod $(GOFILES)
run: $(GOBIN)
$(GOBIN)

.PHONY: clean
clean:
go clean -modcache
rm -fr bin/ go/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package main

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"log"
"io/ioutil"
"os/exec"
"strings"
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
78 changes: 35 additions & 43 deletions packages/rpm/prometheus-slurm-exporter.spec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
make all GOFLAGS=%{gobuildflags}


%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 || \
Expand All @@ -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 <[email protected]> - 0.3
- Fix issue #4
* Wed Jan 31 2018 Matteo <[email protected]> - 0.2
- Fix issue #3
* Mon Dec 04 2017 Matteo <[email protected]> - 0.1
- Full commit history: https://github.com/vpenso/prometheus-slurm-exporter/commits/master
%autochangelog