This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.go
62 lines (51 loc) · 1.57 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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"github.com/lovoo/ipmi_exporter/collector"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
)
var (
listenAddress = flag.String("web.listen", ":9289", "Address on which to expose metrics and web interface.")
metricsPath = flag.String("web.path", "/metrics", "Path under which to expose metrics.")
ipmiBinary = flag.String("ipmi.path", "ipmitool", "Path to the ipmi binary")
showVersion = flag.Bool("version", false, "Show version information and exit")
)
func init() {
prometheus.MustRegister(version.NewCollector("ipmi_exporter"))
}
func main() {
flag.Parse()
if *showVersion {
fmt.Fprintln(os.Stdout, version.Print("ipmi_exporter"))
os.Exit(0)
}
log.Infoln("Starting IPMI Exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
prometheus.MustRegister(collector.NewExporter(*ipmiBinary))
handler := promhttp.Handler()
if *metricsPath == "" || *metricsPath == "/" {
http.Handle(*metricsPath, handler)
} else {
http.Handle(*metricsPath, handler)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>IPMI Exporter</title></head>
<body>
<h1>IPMI Exporter</h1>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
})
}
log.Infoln("Listening on", *listenAddress, *metricsPath)
err := http.ListenAndServe(*listenAddress, nil)
if err != nil {
log.Fatal(err)
}
}