Skip to content

Commit e0b388f

Browse files
authored
Merge pull request #179 from dkanchev/master
Pull request for issue "All configs with env variables"
2 parents a139cf4 + 14570a7 commit e0b388f

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

main.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"runtime"
9+
"strconv"
910

1011
"github.com/oliver006/redis_exporter/exporter"
1112
"github.com/prometheus/client_golang/prometheus"
@@ -18,18 +19,18 @@ var (
1819
redisFile = flag.String("redis.file", getEnv("REDIS_FILE", ""), "Path to file containing one or more redis nodes, separated by newline. NOTE: mutually exclusive with redis.addr")
1920
redisPassword = flag.String("redis.password", getEnv("REDIS_PASSWORD", ""), "Password for one or more redis nodes, separated by separator")
2021
redisAlias = flag.String("redis.alias", getEnv("REDIS_ALIAS", ""), "Redis instance alias for one or more redis nodes, separated by separator")
21-
namespace = flag.String("namespace", "redis", "Namespace for metrics")
22-
checkKeys = flag.String("check-keys", "", "Comma separated list of key-patterns to export value and length/size, searched for with SCAN")
23-
checkSingleKeys = flag.String("check-single-keys", "", "Comma separated list of single keys to export value and length/size")
24-
scriptPath = flag.String("script", "", "Path to Lua Redis script for collecting extra metrics")
25-
separator = flag.String("separator", ",", "separator used to split redis.addr, redis.password and redis.alias into several elements.")
26-
listenAddress = flag.String("web.listen-address", ":9121", "Address to listen on for web interface and telemetry.")
27-
metricPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
28-
isDebug = flag.Bool("debug", false, "Output verbose debug information")
29-
logFormat = flag.String("log-format", "txt", "Log format, valid options are txt and json")
22+
namespace = flag.String("namespace", getEnv("REDIS_EXPORTER_NAMESPACE", "redis"), "Namespace for metrics")
23+
checkKeys = flag.String("check-keys", getEnv("REDIS_EXPORTER_CHECK_KEYS", ""), "Comma separated list of key-patterns to export value and length/size, searched for with SCAN")
24+
checkSingleKeys = flag.String("check-single-keys", getEnv("REDIS_EXPORTER_CHECK_SINGLE_KEYS", ""), "Comma separated list of single keys to export value and length/size")
25+
scriptPath = flag.String("script", getEnv("REDIS_EXPORTER_SCRIPT", ""), "Path to Lua Redis script for collecting extra metrics")
26+
separator = flag.String("separator", getEnv("REDIS_EXPORTER_SEPARATOR", ","), "separator used to split redis.addr, redis.password and redis.alias into several elements.")
27+
listenAddress = flag.String("web.listen-address", getEnv("REDIS_EXPORTER_WEB_LISTEN_ADDRESS", ":9121"), "Address to listen on for web interface and telemetry.")
28+
metricPath = flag.String("web.telemetry-path", getEnv("REDIS_EXPORTER_WEB_TELEMETRY_PATH", "/metrics"), "Path under which to expose metrics.")
29+
isDebug = flag.Bool("debug", getEnvBool("REDIS_EXPORTER_DEBUG"), "Output verbose debug information")
30+
logFormat = flag.String("log-format", getEnv("REDIS_EXPORTER_LOG_FORMAT", "txt"), "Log format, valid options are txt and json")
3031
showVersion = flag.Bool("version", false, "Show version information and exit")
31-
useCfBindings = flag.Bool("use-cf-bindings", false, "Use Cloud Foundry service bindings")
32-
redisMetricsOnly = flag.Bool("redis-only-metrics", false, "Whether to export go runtime metrics also")
32+
useCfBindings = flag.Bool("use-cf-bindings", getEnvBool("REDIS_EXPORTER_USE-CF-BINDINGS"), "Use Cloud Foundry service bindings")
33+
redisMetricsOnly = flag.Bool("redis-only-metrics", getEnvBool("REDIS_EXPORTER_REDIS_ONLY_METRICS"), "Whether to export go runtime metrics also")
3334

3435
// VERSION, BUILD_DATE, GIT_COMMIT are filled in by the build script
3536
VERSION = "<<< filled in by build >>>"
@@ -44,6 +45,13 @@ func getEnv(key string, defaultVal string) string {
4445
return defaultVal
4546
}
4647

48+
func getEnvBool(key string) (envValBool bool) {
49+
if envVal, ok := os.LookupEnv(key); ok {
50+
envValBool, _ = strconv.ParseBool(envVal)
51+
}
52+
return
53+
}
54+
4755
func main() {
4856
flag.Parse()
4957

0 commit comments

Comments
 (0)