This repository has been archived by the owner on Aug 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
tallier.go
99 lines (82 loc) · 2.38 KB
/
tallier.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"fmt"
"math"
"os"
"runtime"
"time"
"github.com/reddit/tallier/tally"
)
// TODO: let flags that follow this one override flags from the file
var configFlag = flag.String("config", "",
"read flags from this file; overrides any command line settings")
var interfaceFlag = flag.String("interface", "",
"interface to listen for statgrams and status page requests on")
var portFlag = flag.Int("port", 8081,
"udp port to listen for statgrams and tcp port to serve status pages")
var numWorkersFlag = flag.Int("numWorkers",
int(math.Max(1, float64(runtime.NumCPU()-1))),
"number of parallel workers for parsing and accumulating stats")
var flushIntervalFlag = flag.Duration("flushInterval",
time.Duration(4)*time.Second,
"interval at which stats are flushed to graphite")
var graphiteFlag = flag.String("graphite", "",
"address of graphite (carbon) server")
var haroldFlag = flag.String("harold", "",
"base url of harold service (REQUIRES -haroldSecret)")
var haroldSecretFlag = flag.String("haroldSecret", "",
"secret for authenticating with harold service")
var logtoFlag = flag.String("logto", "stdout",
"destination for logging (one of: stdout, stderr, syslog)")
func main() {
flag.Parse()
if *configFlag != "" {
_, err := tally.NewFlagFile(*configFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(2)
}
}
switch *logtoFlag {
case "stdout":
tally.LogTo(os.Stdout)
case "stderr":
tally.LogTo(os.Stderr)
case "syslog":
tally.LogToSyslog()
default:
fmt.Fprintf(os.Stderr,
"error: -logto must be one of stdout, stderr, or syslog\n")
os.Exit(2)
}
if *graphiteFlag == "" {
fmt.Fprintf(os.Stderr, "-graphite is required\n")
os.Exit(2)
}
graphite, err := tally.NewGraphite(*graphiteFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
var harold *tally.Harold
if *haroldFlag != "" {
if *haroldSecretFlag == "" {
fmt.Fprintf(os.Stderr, "harold requires -haroldSecret to be set\n")
os.Exit(2)
}
harold, err = tally.NewHarold(*haroldFlag, *haroldSecretFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}
server := tally.NewServer(
*interfaceFlag, *portFlag, *numWorkersFlag, *flushIntervalFlag,
graphite, harold)
err = server.Loop()
if err != nil {
fmt.Fprintf(os.Stderr, "loop terminated with error: %s\n", err)
os.Exit(1)
}
}