-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
49 lines (37 loc) · 1.06 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
package main
import (
"context"
"net/http"
"os"
"os/signal"
"github.com/CheerlessCloud/cexporter/collector"
configPackage "github.com/CheerlessCloud/cexporter/config"
_ "github.com/CheerlessCloud/cexporter/logger" // init logger
log "github.com/CheerlessCloud/logrus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var config = configPackage.ConfigSingleton
func main() {
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, os.Kill)
server := &http.Server{
Addr: config.HTTPAddr,
Handler: promhttp.HandlerFor(collector.Registry, promhttp.HandlerOpts{}),
}
go func() {
collector.StartCollectingMetrics(config.FetchInterval, config.FetchTimeout)
}()
go func() {
log.WithFields(log.Fields{"config": config}).Info("http server start")
if err := server.ListenAndServe(); err != nil {
log.Fatal(err)
}
}()
<-stop
log.Info("Shutting down the server...")
if err := server.Shutdown(context.TODO()); err != nil {
log.Error("Server shutting down emit error", err)
} else {
log.Info("Server gracefully stopped")
}
}