forked from jirwin/burrow_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
burrow-exporter.go
98 lines (81 loc) · 2.1 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
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.4"
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",
},
}
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"))
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)
}
}