-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.07 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
package main
import (
"errors"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/xperimental/steam-exporter/internal/collector"
"github.com/xperimental/steam-exporter/internal/config"
"github.com/xperimental/steam-exporter/internal/web"
)
var (
Version = ""
GitCommit = ""
log = logrus.New()
)
func main() {
cfg, err := config.Get(os.Args[0], os.Args[1:])
switch {
case errors.Is(err, pflag.ErrHelp):
return
case err != nil:
log.Fatalf("Error reading configuration: %s", err)
}
if cfg.Verbose {
log.SetLevel(logrus.DebugLevel)
}
c, err := collector.New(log, cfg.Servers, cfg.DataTimeout)
if err != nil {
log.Fatalf("Can not create collector: %s", err)
}
if err := prometheus.Register(c); err != nil {
log.Fatalf("Can not register collector: %s", err)
}
r := web.Handler(log, GitCommit, Version)
log.Infof("Listening on %s ...", cfg.ListenAddress)
if err := http.ListenAndServe(cfg.ListenAddress, r); err != nil {
log.Fatalf("Error creating listener: %s", err)
}
}