-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (45 loc) · 1.49 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
package main
import (
"flag"
"net/http"
"time"
"github.com/marevers/power-datacenter-exporter/pkg/pdc"
log "github.com/sirupsen/logrus"
)
var (
logLevel = flag.String("log.level", "info", "Log level for logging.")
listenAddr = flag.String("web.listen-address", ":8080", "The address to listen on for HTTP requests.")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
baseUrl = flag.String("pdc.baseurl", "", "Base URL to use.")
username = flag.String("pdc.username", "", "Username for logging in.")
password = flag.String("pdc.password", "", "Password for logging in.")
serialNumber = flag.String("pdc.serialnumber", "", "Serial number of device.")
interval = flag.Int("pdc.interval", 60, "Interval in seconds for data polling.")
)
func main() {
flag.Parse()
if level, err := log.ParseLevel(*logLevel); err != nil {
log.Fatalln(err)
} else {
log.SetLevel(level)
}
ses := pdc.NewSession(*baseUrl, *serialNumber)
if err := ses.Login(*username, *password); err != nil {
log.Fatalln(err)
}
exporter := &exporter{
Reg: createRegistry(),
Session: ses,
}
exporter.registerMetrics(labels)
srv := &http.Server{
Addr: *listenAddr,
Handler: exporter.routes(),
}
go startMetricsTicker(exporter, time.Duration(*interval)*time.Second)
log.Println("Starting power-datacenter Exporter at", *listenAddr)
err := srv.ListenAndServe()
if err != nil {
log.Fatalln("Error starting HTTP server:", err)
}
}