forked from davidtannock/beanstalkd_exporter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
104 lines (85 loc) · 2.75 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
95
96
97
98
99
100
101
102
103
104
package main
import (
"os"
"path/filepath"
"strings"
"github.com/davidtannock/beanstalkd_exporter/pkg/server"
"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)
type options struct {
listenAddress *string
metricsPath *string
beanstalkdAddress *string
beanstalkdSystemMetrics *string
beanstalkdAllTubes *bool
beanstalkdTubes *string
beanstalkdTubeMetrics *string
}
func initApplication(app *kingpin.Application) *options {
opts := &options{}
opts.listenAddress = app.Flag(
"web.listen-address",
"Address to listen on for web interface and telemetry.",
).Default(":8080").String()
opts.metricsPath = app.Flag(
"web.telemetry-path",
"Path under which to expose metrics.",
).Default("/metrics").String()
opts.beanstalkdAddress = app.Flag(
"beanstalkd.address",
"Address of beanstalkd instance.",
).Default("localhost:11300").String()
opts.beanstalkdSystemMetrics = app.Flag(
"beanstalkd.systemMetrics",
"Comma separated beanstalkd system metrics to collect. All metrics will be collected if this is not set.",
).Default("").String()
opts.beanstalkdAllTubes = app.Flag(
"beanstalkd.allTubes",
"Collect metrics for all tubes. Default false.",
).Default("false").Bool()
opts.beanstalkdTubes = app.Flag(
"beanstalkd.tubes",
"Comma separated beanstalkd tubes for which to collect metrics. Ignored when \"beanstalkd.allTubes\" is true.",
).Default("").String()
opts.beanstalkdTubeMetrics = app.Flag(
"beanstalkd.tubeMetrics",
"Comma separated beanstalkd tube metrics to collect for the specified tubes. All metrics will be collected if this is not set.",
).Default("").String()
log.AddFlags(app)
return opts
}
func main() {
logger := log.Base()
app := kingpin.New(filepath.Base(os.Args[0]), "")
opts := initApplication(app)
_, err := app.Parse(os.Args[1:])
if err != nil {
app.Fatalf("%s, try --help", err)
}
logger.Infof("Starting beanstalkd_exporter")
// Fetching all tubes overrides specific tubes.
beanstalkdTubes := *opts.beanstalkdTubes
if *opts.beanstalkdAllTubes {
beanstalkdTubes = ""
}
sOpts := server.Opts{
ListenAddress: *opts.listenAddress,
MetricsPath: *opts.metricsPath,
BeanstalkdAddress: *opts.beanstalkdAddress,
BeanstalkdSystemMetrics: toStringArray(*opts.beanstalkdSystemMetrics),
BeanstalkdAllTubes: *opts.beanstalkdAllTubes,
BeanstalkdTubes: toStringArray(beanstalkdTubes),
BeanstalkdTubeMetrics: toStringArray(*opts.beanstalkdTubeMetrics),
}
server.ListenAndServe(sOpts, logger)
}
func toStringArray(flag string) []string {
flags := []string{}
for _, part := range strings.Split(flag, ",") {
if s := strings.Trim(part, " "); s != "" {
flags = append(flags, s)
}
}
return flags
}