-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
53 lines (43 loc) · 1.13 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 (
"flag"
"fmt"
"os"
"os/signal"
"time"
"github.com/civo/civostatsd/config"
"github.com/civo/civostatsd/gather"
"github.com/civo/civostatsd/send"
)
func main() {
var configFile string
var testMode bool
flag.StringVar(&configFile, "config", "/etc/civostatsd", "Set the location of the configuration file")
flag.BoolVar(&testMode, "test", false, "run a single iteration as a test")
flag.Parse()
configuration := config.Load(configFile)
ticker := time.NewTicker(60 * time.Second)
death := make(chan os.Signal, 1)
signal.Notify(death, os.Interrupt, os.Kill)
fmt.Println("Civostatsd v2.2")
fmt.Println("Using API server: " + configuration.Server)
fmt.Println("Using Token: " + configuration.Token)
fmt.Println("Using Region: " + configuration.Region)
fmt.Println("Using InstanceID: " + configuration.InstanceID)
stats := gather.All()
send.ToAPI(configuration, stats)
if testMode {
fmt.Println(stats.String())
os.Exit(0)
}
for {
select {
case <-ticker.C:
stats := gather.All()
fmt.Println(stats.String())
send.ToAPI(configuration, stats)
case <-death:
os.Exit(0)
}
}
}