forked from jirwin/burrow_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
burrow-exporter.go
78 lines (61 loc) · 1.54 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
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.2"
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",
},
cli.StringFlag{
Name: "metrics-addr",
Usage: "Address to run prometheus on",
},
cli.IntFlag{
Name: "interval",
Usage: "The interval(seconds) specifies how often to scrape burrow.",
},
}
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.String("metrics-addr"), c.Int("interval"))
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)
}
}