-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (78 loc) · 2.19 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/activesphere/kqm/monitor"
log "github.com/sirupsen/logrus"
)
var description = `
kqm [OPTIONS] host:port [host:port]...
KQM is a command line tool to monitor Apache Kafka for lags.
It also comes with an option to send the lag statistics to Statsd.
Option Description
------ -----------
--statsd-addr Use this option if you need to send
the lag statistics to Statsd.
Default: localhost:8125
--statsd-prefix Set a prefix for the data being sent
to Statsd.
Default: kqm
--interval Specify the interval of calculating
the lag statistics (in seconds).
Default: 60 seconds
--log-level Specify the level of severity of the
logger. Levels are as follows:
0 - Panic
1 - Fatal
2 - Error (Default)
3 - Warn
4 - Info
5 - Debug
Example Command Usage:
kqm --log-level=5 \
--interval=30 \
--statsd-addr localhost:8125 \
--statsd-prefix prefix_demo \
localhost:9092
`
func parseCommand() (*monitor.QMConfig, error) {
var (
brokers []string
interval, logLevel *int
statsdAddr, statsdPrefix *string
)
interval = flag.Int("interval", 60, "")
statsdAddr = flag.String("statsd-addr", "localhost:8125", "")
statsdPrefix = flag.String("statsd-prefix", "kqm", "")
logLevel = flag.Int("log-level", 2, "")
flag.Usage = func() {
fmt.Println(description)
}
flag.Parse()
brokers = flag.Args()
if len(brokers) == 0 {
return nil, fmt.Errorf("Please specify brokers")
}
cfg := &monitor.QMConfig{
KafkaCfg: monitor.KafkaConfig{
Brokers: brokers,
},
StatsdCfg: monitor.StatsdConfig{
Addr: *statsdAddr,
Prefix: *statsdPrefix,
},
Interval: time.Duration(*interval) * time.Second,
}
log.SetLevel(log.AllLevels[*logLevel])
return cfg, nil
}
func main() {
cfg, err := parseCommand()
if err != nil {
fmt.Printf("%s\n%s", err, description)
os.Exit(1)
}
monitor.Start(cfg)
}