/
flags.go
47 lines (40 loc) · 1.01 KB
/
flags.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
package prometheus
import (
"fmt"
"os"
"strings"
)
// EnvToPrometheusFlags converts environmental variables into a string of
// flags to be used with prometheus v2 CLI
func EnvToPrometheusFlags(prefix string) []string {
flags := []string{}
for _, e := range os.Environ() {
if key, value := getArgFromEnv(e, "ARG"); len(key) > 0 {
key = strings.Replace(key, "_", ".", -1)
if key == "web.enable-remote-shutdown" {
if value == "true" {
key = "web.enable-lifecycle"
value = ""
} else {
continue
}
} else if key == "storage.local.path" {
key = "storage.tsdb.path"
} else if key == "storage.local.retention" {
key = "storage.tsdb.retention"
} else if key == "query.staleness-delta" {
key = "query.lookback-delta"
} else if key == "alertmanager.url" {
continue
}
var flag string
if len(value) > 0 {
flag = fmt.Sprintf("--%s=\"%s\"", key, value)
} else {
flag = fmt.Sprintf("--%s", key)
}
flags = append(flags, flag)
}
}
return flags
}