-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
64 lines (51 loc) · 1.1 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/n9e/docker-mon/collect"
"github.com/n9e/docker-mon/config"
"github.com/toolkits/pkg/logger"
)
func InitLogger(l config.LoggerSection) {
lb, err := logger.NewFileBackend(l.Dir)
if err != nil {
fmt.Println("cannot init logger:", err)
os.Exit(1)
}
lb.SetRotateByHour(true)
lb.SetKeepHours(l.KeepHours)
logger.SetLogging(l.Level, lb)
}
func init() {
cfg := flag.String("c", "docker-mon.yml", "configuration file")
version := flag.Bool("v", false, "show version")
flag.Parse()
handleVersion(*version)
handleConfig(*cfg)
InitLogger(config.G.Logger)
}
func main() {
collect.HostIp = collect.HostIpMap{M: make(map[string]string)}
hostIpFile := ".host_ip"
collect.HostIp.Load(hostIpFile)
collect.Collect()
err := collect.HostIp.WriteFile(hostIpFile)
if err != nil {
logger.Error(err)
}
logger.Close()
}
func handleVersion(displayVersion bool) {
if displayVersion {
fmt.Println(config.Version)
os.Exit(0)
}
}
func handleConfig(configFile string) {
err := config.Parse(configFile)
if err != nil {
log.Fatalln(err)
}
}