-
Notifications
You must be signed in to change notification settings - Fork 58
/
main.go
74 lines (57 loc) · 1.46 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
67
68
69
70
71
72
73
74
package main
import (
"encoding/json"
"flag"
"os"
"os/signal"
"syscall"
"net/http"
_ "net/http/pprof"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
var (
version = "0.0.0"
)
func main() {
cfgFile := flag.String("config", "", "Path to a config file")
flag.Parse()
cfg, err := configLoad(*cfgFile)
if err != nil {
log.Fatal(err)
}
if cfg.ListenPprof != "" {
go func() {
if err := http.ListenAndServe(cfg.ListenPprof, nil); err != nil {
log.Fatalf("Unable to listen on %s: %s", cfg.ListenPprof, err)
}
}()
}
go func() {
http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(cfg.ListenMetricsAddress, nil); err != nil {
log.Fatalf("Unable to listen on %s: %s", cfg.ListenMetricsAddress, err)
}
}()
lvl, err := log.ParseLevel(cfg.LogLevel)
if err != nil {
log.Fatalf("Unable to parse log level: %s", err)
}
log.SetLevel(lvl)
cfgJSON, _ := json.Marshal(cfg)
log.Warnf("Effective config: %+v", string(cfgJSON))
proc := newProcessor(*cfg)
if err = proc.run(); err != nil {
log.Fatalf("Unable to start: %s", err)
}
log.Warnf("Listening on %s, sending to %s", cfg.Listen, cfg.Target)
log.Warnf("Started v%s", version)
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGTERM, os.Interrupt)
<-ch
log.Warn("Shutting down, draining requests")
if err = proc.close(); err != nil {
log.Errorf("Error during shutdown: %s", err)
}
log.Warnf("Finished")
}