oven-exporter/main.go

52 lines
1.1 KiB
Go
Raw Normal View History

2021-07-20 12:18:00 +02:00
package main
import (
2021-07-20 12:25:05 +02:00
"flag"
2021-07-21 01:33:54 +02:00
"net/http"
2021-07-20 12:18:00 +02:00
"dev.sum7.eu/genofire/golang-lib/file"
2021-07-21 01:33:54 +02:00
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
2021-09-29 14:03:25 +02:00
"go.uber.org/zap"
2021-07-21 00:15:57 +02:00
"dev.sum7.eu/genofire/oven-exporter/api"
2021-07-20 12:18:00 +02:00
)
type configData struct {
2021-09-29 14:03:25 +02:00
log *zap.Logger
Log *zap.Config `toml:"log"`
2021-07-21 01:33:54 +02:00
API *api.Client `toml:"api"`
Listen string `toml:"listen"`
2021-07-20 12:18:00 +02:00
}
func main() {
configPath := "config.toml"
log, _ := zap.NewProduction()
2021-09-29 14:03:25 +02:00
2021-07-20 12:18:00 +02:00
flag.StringVar(&configPath, "c", configPath, "path to configuration file")
flag.Parse()
config := &configData{}
if err := file.ReadTOML(configPath, config); err != nil {
2021-09-29 14:03:25 +02:00
log.Panic("open config file", zap.Error(err))
}
if config.Log != nil {
l, err := config.Log.Build()
if err != nil {
log.Panic("generate logger from config", zap.Error(err))
}
log = l
2021-07-20 12:18:00 +02:00
}
2021-09-29 14:03:25 +02:00
config.log = log
//config.SetLogger(log)
2021-07-21 00:15:57 +02:00
config.API.SetToken(config.API.Token)
2021-07-21 01:33:54 +02:00
prometheus.MustRegister(config)
http.Handle("/metrics", promhttp.Handler())
2021-09-29 14:03:25 +02:00
if err := http.ListenAndServe(config.Listen, nil); err != nil {
log.Fatal("crash webserver", zap.Error(err))
}
2021-07-20 12:18:00 +02:00
}