-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain.go
53 lines (40 loc) · 1.09 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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/ebrianne/adguard-exporter/config"
"github.com/ebrianne/adguard-exporter/internal/adguard"
"github.com/ebrianne/adguard-exporter/internal/metrics"
"github.com/ebrianne/adguard-exporter/internal/server"
)
const (
name = "adguard-exporter"
)
var (
s *server.Server
)
func main() {
conf := config.Load()
metrics.Init()
initAdguardClient(conf.AdguardProtocol, conf.AdguardHostname, conf.AdguardUsername, conf.AdguardPassword, conf.Interval, conf.LogLimit)
initHttpServer(conf.ServerPort)
handleExitSignal()
}
func initAdguardClient(protocol, hostname string, username, password string, interval time.Duration, logLimit string) {
client := adguard.NewClient(protocol, hostname, username, password, interval, logLimit)
go client.Scrape()
}
func initHttpServer(port string) {
s = server.NewServer(port)
go s.ListenAndServe()
}
func handleExitSignal() {
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
<-stop
s.Stop()
fmt.Println(fmt.Sprintf("\n%s HTTP server stopped", name))
}