-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
56 lines (50 loc) · 1.28 KB
/
config.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
package main
import (
"flag"
"fmt"
"strings"
"github.com/prometheus/client_golang/prometheus"
)
type NamedValue struct {
Name string
Value string
}
type Config struct {
Labels prometheus.Labels
Listener string
Pattern string
Threshold int
}
func copyLabels(in prometheus.Labels) prometheus.Labels {
out := prometheus.Labels{}
for k, v := range in {
out[k] = v
}
return out
}
func Parse() (*Config, error) {
listener := "0.0.0.0:2198"
pattern := "[b]idule"
labels := "application:prometheus-fd"
threshold := 0
flag.StringVar(&listener, "listener", listener, "listener address")
flag.StringVar(&pattern, "pattern", pattern, "ps query pattern")
flag.StringVar(&labels, "labels", labels, "a list of key:value labels separated by commas")
flag.IntVar(&threshold, "kill-on-threshold", threshold, "send kill -9 when open files are above the threshold")
flag.Parse()
l := strings.Split(labels, ",")
prometheusLabels := prometheus.Labels{}
for _, label := range l {
keyValue := strings.Split(label, ":")
if len(keyValue) != 2 {
return nil, fmt.Errorf("unrecognized label: %s", keyValue)
}
prometheusLabels[keyValue[0]] = keyValue[1]
}
return &Config{
Labels: prometheusLabels,
Listener: listener,
Pattern: pattern,
Threshold: threshold,
}, nil
}