-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (60 loc) · 1.33 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
package main
import (
"flag"
"net/http"
"time"
log "github.com/sirupsen/logrus"
)
var (
monitor = flag.String(
"monitor-host",
"",
"Host and port were monitor (Prometheus) is listening.",
)
addr = flag.String(
"listen-address",
":8079",
"The address to listen on for HTTP requests.",
)
workDir = flag.String(
"work-dir",
"./",
"Work directory where config.json file is located.",
)
logLevel = flag.String(
"log-level",
"error",
"Level of log output.",
)
// Global variables of the orchestrator
config = LoadConfig()
memory *Memory
)
func main() {
flag.Parse()
// Add to workDir ending / if not present
if (*workDir)[len(*workDir)-1] != '/' {
*workDir += "/"
}
// Parse and set log lovel
level, err := log.ParseLevel(*logLevel)
if err == nil {
log.SetLevel(level)
} else {
log.SetLevel(log.WarnLevel)
log.Warnf("Log level %s not recognized, setting \"warn\" as default.")
}
// Flags check
if *monitor == "" {
flag.Usage()
log.Fatalln("A host and port must be provided to connect to Prometheus.")
}
config = LoadConfig()
memory = NewMemory()
if err := memory.LoadFromFile(config.StorageFileName); err != nil {
log.Warningf("Couldn't load memory file: %s", err.Error())
}
memory.StartHealing(30 * time.Second)
router := NewRouter()
log.Fatal(http.ListenAndServe(*addr, router))
}