forked from jakubjastrabik/smartctl_ssacli_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
45 lines (34 loc) · 1.64 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
package main
import (
"flag"
"net/http"
"github.com/go-kit/log/level"
"github.com/john-craig/smartctl_ssacli_exporter/exporter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
)
var (
listenAddr = flag.String("web.listen-address", ":9633", "Address for exporter")
metricsPath = flag.String("web.telemetry-path", "/metrics", "URL path for surfacing collected metrics")
smartctlPath = flag.String("smartctl.path", "/usr/bin/smartctl", "Path to smartctl binary")
ssacliPath = flag.String("ssacli.path", "/usr/bin/ssacli", "Path to ssacli binary")
lsscsiPath = flag.String("lsscsi.path", "/usr/bin/lsscsci", "Path to lsscsi binary")
sudoPath = flag.String("sudo.path", "/usr/bin/sudo", "Path to sudo binary")
logLevel = flag.String("log.level", "info", "Filter for log level, accepts: info, debug, info, warn, error")
)
func main() {
flag.Parse()
promlogConfig := &promlog.Config{}
logger := promlog.New(promlogConfig)
logger = level.NewFilter(logger, level.Allow(level.ParseDefault(*logLevel, level.InfoValue())))
prometheus.MustRegister(exporter.New(logger, *smartctlPath, *ssacliPath, *lsscsiPath, *sudoPath))
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, *metricsPath, http.StatusMovedPermanently)
})
level.Info(logger).Log("msg", "Beginning to serve exporter", "port", *listenAddr, "metricsPath", *metricsPath)
if err := http.ListenAndServe(*listenAddr, nil); err != nil {
level.Error(logger).Log("msg", "Cannot start exporter", "err", err)
}
}