-
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 (
"flag"
"net/http"
"net/http/pprof"
"path"
"go.uber.org/zap"
"github.com/mxlxm/common/utils"
"github.com/mxlxm/exporters/config"
"github.com/mxlxm/exporters/exporter"
)
var (
err error
cfg config.ExportersConfig
log *zap.SugaredLogger
mux *http.ServeMux
conf = flag.String("conf", path.Clean(utils.ExecDir()+"/../conf/exporters.toml"), "exporters config file")
)
func init() {
flag.Parse()
cfg = config.LoadCFG(*conf)
if log, err = utils.SugarInit(utils.InitLogConfig(cfg.Log)); err != nil {
panic(err)
}
exporter.SetLogger(log)
exporter.BuildAuth(cfg)
}
func main() {
defer func() {
log.Sync()
}()
mux = http.NewServeMux()
mux.HandleFunc(cfg.ScrapePath, exporter.ScrapeHandler)
mux.Handle(cfg.MetricPath, exporter.MetricHandler)
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
http.ListenAndServe(cfg.Listen, mux)
}