-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (68 loc) · 2.86 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2017-2022 Victor Penso, Matteo Dessalvi, Joeri Hermans
package main
import (
"flag"
"fmt"
"net/http"
"log"
"github.com/MarshallWace/slurm-exporter/pkg/slurm"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
appropriateLegalNotice = `
Copyright 2017-2022 Victor Penso, Matteo Dessalvi, Joeri Hermans, Marhall Wace
Victor Penso, Matteo Dessalvi, Joeri Hermans, Marhall Wace LICENSES THE LICENSED SOFTWARE "AS IS," AND MAKES NO EXPRESS OR IMPLIED WARRANTY OF ANY KIND. Victor Penso, Matteo Dessalvi, Joeri Hermans, Marhall Wace SPECIFICALLY DISCLAIMS ALL INDIRECT OR IMPLIED WARRANTIES TO THE FULL EXTENT ALLOWED BY APPLICABLE LAW, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF, NON-INFRINGEMENT, MERCHANTABILITY, TITLE OR FITNESS FOR ANY PARTICULAR PURPOSE. NO ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY Victor Penso, Matteo Dessalvi, Joeri Hermans, Marhall Wace, ITS AGENTS OR EMPLOYEES SHALL CREATE A WARRANTY.
`
)
var listenAddress = flag.String(
"listen-address",
":8080",
"The address to listen on for HTTP requests.")
// Turn on GPUs accounting only if the corresponding command line option is set to true.
var gpuAcct = flag.Bool(
"gpus-acct",
false,
"Enable GPUs accounting")
var execTimeoutSeconds = flag.Int(
"exec-timeout",
10,
"Timeout when executing shell commands")
var nodeAddressSuffix = flag.String(
"address-suffix",
"",
"Suffix to add the node address when reporting metrics")
var ldapServer = flag.String(
"ldap-address",
"",
"Address to contact ldap server. if this is not set, this feature will be disable. if configured please configure --ldap-base-search as well")
var ldapBaseSearch = flag.String(
"ldap-base-search",
"",
"Base search for the ldap server (e.g. dc=example,dc=com)")
func main() {
flag.Parse()
fmt.Println(appropriateLegalNotice)
if *gpuAcct {
prometheus.MustRegister(slurm.NewGPUsCollector()) // from gpus.go
}
if *ldapServer != "" && *ldapBaseSearch == "" {
log.Fatalln("--ldap-address is configured but --ldap-base-search is not. please configure --ldap-base-search (e.g. dc=example,dc=com) ")
}
reg, err := slurm.NewRegistry(*gpuAcct, *execTimeoutSeconds, *nodeAddressSuffix, *ldapServer, *ldapBaseSearch)
if err != nil {
log.Fatalln(err)
}
// Adding more collectors to the registry
reg.MustRegister(
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
collectors.NewGoCollector(),
)
// The Handler function provides a default handler to expose metrics
// via an HTTP server. "/metrics" is the usual endpoint for that.
log.Printf("Starting Server: %s", *listenAddress)
log.Printf("GPUs Accounting: %t", *gpuAcct)
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}