-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (35 loc) · 1.2 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
package main
import (
"net/http"
"os"
"github.com/kalkspace/orno-exporter/config"
"github.com/kalkspace/orno-exporter/exporter"
"github.com/kalkspace/orno-exporter/orno"
"github.com/kalkspace/orno-exporter/orno/models"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
)
var ConfigFile string
func main() {
log := logrus.StandardLogger()
if configFileEnv, ok := os.LookupEnv("ORNO_CONFIG_FILE"); ok {
ConfigFile = configFileEnv
}
config, err := config.LoadConfig("ORNO", ConfigFile)
if err != nil {
log.WithError(err).Error("Failed loading config")
return
}
reader := orno.NewReader(log.WithField("component", "reader"), config.Serial.Address, new(models.WE516))
exporter := exporter.NewExporter(log.WithField("component", "exporter"), reader)
if err := prometheus.Register(exporter); err != nil {
log.WithError(err).Error("Unable to register exporter")
return
}
addr := config.Server.Host + ":" + config.Server.Port
log.WithField("address", addr).Info("Starting http server...")
if err := http.ListenAndServe(addr, promhttp.Handler()); err != nil {
log.WithError(err).Error("HTTP server failed")
}
}