forked from smancke/insantus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.15 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 (
"log"
"net/http"
_ "net/http/pprof"
)
var store *Store
func main() {
cfg, err := getConfig()
if err != nil {
log.Fatalf("error reading configuration %v\n", err)
}
profiler(cfg)
store, err = NewStore(cfg, NewNotificationGateway(cfg))
if err != nil {
log.Fatalf("error opening database %v\n", err)
}
resultCallback := make(chan []Result, 50)
startChecking(cfg, resultCallback)
httpServer := NewHttpServer(cfg, store)
go httpServer.Start()
for results := range resultCallback {
for _, result := range results {
err := store.InsertResult(result)
if err != nil {
log.Printf("error storing check result: %v\n", err)
}
if result.Status == StatusUp {
log.Printf("%v: %v/%v (%vms)\n", result.Status, result.Environment, result.Check, result.Duration)
} else {
log.Printf("%v: %v/%v (%vms): %v\n", result.Status, result.Environment, result.Check, result.Duration, result.Message)
}
}
}
}
func profiler(cfg *Config) {
if !cfg.Pprof {
return
}
pprofMux := http.DefaultServeMux
http.DefaultServeMux = http.NewServeMux()
go func() {
log.Fatal(http.ListenAndServe(cfg.PprofListen, pprofMux))
}()
}