-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (51 loc) · 1.57 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
// vim: ts=2:nowrap
package main
import (
"flag"
"github.com/deliverous/docker-stats-to-backstop/server"
"log"
"os"
"time"
)
var (
help = flag.Bool("help", false, "Get help")
backstopURL = flag.String("backstop", env("SRV_BACKSTOP", ""), "URL for connecting backsop server")
dockerURL = flag.String("docker", env("SRV_DOCKER", "unix:///var/run/docker.sock"), "URL for connecting docker server")
rulesDefinition = flag.String("rules", env("SRV_RULES", ""), "JSON containing 'regexp','into' and 'category' to rewrite the container name into graphite identifier")
pollDefinition = flag.String("poll", env("SRV_POLL", "5m"), "Set the poll delay. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'")
verbose = flag.Bool("verbose", false, "Enable the verbose mode")
)
func main() {
flag.Parse()
if *help {
flag.Usage()
os.Exit(0)
}
poll, err := time.ParseDuration(*pollDefinition)
if err != nil {
log.Fatalf("ERROR: cannot parse duration '%s': %s", *pollDefinition, err)
}
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("ERROR: cannot get hostname : %s", err)
}
rules, err := server.LoadRules(*rulesDefinition)
if err != nil {
log.Fatalf("ERROR: cannot load rules '%s' : %s", *rulesDefinition, err)
}
srv := &server.Server{
Hostname: hostname,
DockerURL: *dockerURL,
BackstopURL: *backstopURL,
Poll: poll,
Rules: rules,
Verbose: *verbose,
}
srv.Serve()
}
func env(key string, missing string) string {
if value := os.Getenv(key); value != "" {
return value
}
return missing
}