-
Notifications
You must be signed in to change notification settings - Fork 68
/
burrow-exporter.go
133 lines (116 loc) · 3.03 KB
/
burrow-exporter.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"fmt"
"os"
log "github.com/Sirupsen/logrus"
"github.com/urfave/cli"
"context"
"os/signal"
"syscall"
"github.com/jirwin/burrow_exporter/burrow_exporter"
)
var Version = "0.0.5"
func main() {
app := cli.NewApp()
app.Version = Version
app.Name = "burrow-exporter"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "burrow-addr",
Usage: "Address that burrow is listening on",
EnvVar: "BURROW_ADDR",
},
cli.StringFlag{
Name: "metrics-addr",
Usage: "Address to run prometheus on",
EnvVar: "METRICS_ADDR",
},
cli.IntFlag{
Name: "interval",
Usage: "The interval(seconds) specifies how often to scrape burrow.",
EnvVar: "INTERVAL",
},
cli.IntFlag{
Name: "api-version",
Usage: "Burrow API version to leverage",
Value: 2,
EnvVar: "API_VERSION",
},
cli.BoolFlag{
Name: "skip-partition-status",
Usage: "Skip exporting the per-partition status",
EnvVar: "SKIP_PARTITION_STATUS",
},
cli.BoolFlag{
Name: "skip-group-status",
Usage: "Skip exporting the per-group status",
EnvVar: "SKIP_GROUP_STATUS",
},
cli.BoolFlag{
Name: "skip-partition-lag",
Usage: "Skip exporting the partition lag",
EnvVar: "SKIP_PARTITION_LAG",
},
cli.BoolFlag{
Name: "skip-partition-current-offset",
Usage: "Skip exporting the current offset per partition",
EnvVar: "SKIP_PARTITION_CURRENT_OFFSET",
},
cli.BoolFlag{
Name: "skip-partition-max-offset",
Usage: "Skip exporting the partition max offset",
EnvVar: "SKIP_PARTITION_MAX_OFFSET",
},
cli.BoolFlag{
Name: "skip-total-lag",
Usage: "Skip exporting the total lag",
EnvVar: "SKIP_TOTAL_LAG",
},
cli.BoolFlag{
Name: "skip-topic-partition-offset",
Usage: "Skip exporting topic partition offset",
EnvVar: "SKIP_TOPIC_PARTITION_OFFSET",
},
}
app.Action = func(c *cli.Context) error {
if !c.IsSet("burrow-addr") {
fmt.Println("A burrow address is required (e.g. --burrow-addr http://localhost:8000)")
os.Exit(1)
}
if !c.IsSet("metrics-addr") {
fmt.Println("An address to run prometheus on is required (e.g. --metrics-addr localhost:8080)")
os.Exit(1)
}
if !c.IsSet("interval") {
fmt.Println("A scrape interval is required (e.g. --interval 30)")
os.Exit(1)
}
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
exporter := burrow_exporter.MakeBurrowExporter(
c.String("burrow-addr"),
c.Int("api-version"),
c.String("metrics-addr"),
c.Int("interval"),
c.Bool("skip-partition-status"),
c.Bool("skip-group-status"),
c.Bool("skip-partition-lag"),
c.Bool("skip-partition-current-offset"),
c.Bool("skip-partition-max-offset"),
c.Bool("skip-total-lag"),
c.Bool("skip-topic-partition-offset"))
go exporter.Start(ctx)
<-done
cancel()
exporter.Close()
return nil
}
err := app.Run(os.Args)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("error running burrow-exporter")
os.Exit(1)
}
}