-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (58 loc) · 1.62 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
package main
import (
"net/http"
"os"
"github.com/SquareFactory/exoscale_exporter/config"
"github.com/SquareFactory/exoscale_exporter/exoscale"
"github.com/SquareFactory/exoscale_exporter/log"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
)
var (
collector *exoscale.Collector
)
func main() {
var configFile string
var listenAddress string
log.InitLogger()
app := &cli.App{
Name: "exoscale_exporter",
Usage: "Fetches statistics from Exoscale API",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config.file",
Value: "config.yaml",
Usage: "Path to configuration file.",
Destination: &configFile,
EnvVars: []string{"CONFIG_FILE"},
},
&cli.StringFlag{
Name: "web.listen-address",
Value: ":9116",
Usage: "Address to listen on for web interface and telemetry.",
Destination: &listenAddress,
EnvVars: []string{"LISTEN_ADDRESS"},
},
},
Action: func(*cli.Context) error {
config, err := config.LoadFile(configFile)
if err != nil {
return err
}
computeAPI := exoscale.NewComputeAPI(config.ExoscaleConfig.Key, config.ExoscaleConfig.Secret)
collector = exoscale.NewCollector(computeAPI)
go collector.RecordMetrics()
http.Handle("/metrics", promhttp.Handler())
log.Logger.Info(
"Serving http server",
zap.String("web.listen-address", listenAddress),
zap.String("config.file", configFile),
)
return http.ListenAndServe(listenAddress, nil)
},
}
if err := app.Run(os.Args); err != nil {
log.Logger.Fatal("App crashed", zap.Error(err))
}
}