Skip to content

Commit

Permalink
Merge pull request #179 from dkanchev/master
Browse files Browse the repository at this point in the history
Pull request for issue "All configs with env variables"
  • Loading branch information
oliver006 authored Aug 21, 2018
2 parents a139cf4 + 14570a7 commit e0b388f
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"runtime"
"strconv"

"github.com/oliver006/redis_exporter/exporter"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -18,18 +19,18 @@ var (
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")
redisPassword = flag.String("redis.password", getEnv("REDIS_PASSWORD", ""), "Password for one or more redis nodes, separated by separator")
redisAlias = flag.String("redis.alias", getEnv("REDIS_ALIAS", ""), "Redis instance alias for one or more redis nodes, separated by separator")
namespace = flag.String("namespace", "redis", "Namespace for metrics")
checkKeys = flag.String("check-keys", "", "Comma separated list of key-patterns to export value and length/size, searched for with SCAN")
checkSingleKeys = flag.String("check-single-keys", "", "Comma separated list of single keys to export value and length/size")
scriptPath = flag.String("script", "", "Path to Lua Redis script for collecting extra metrics")
separator = flag.String("separator", ",", "separator used to split redis.addr, redis.password and redis.alias into several elements.")
listenAddress = flag.String("web.listen-address", ":9121", "Address to listen on for web interface and telemetry.")
metricPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
isDebug = flag.Bool("debug", false, "Output verbose debug information")
logFormat = flag.String("log-format", "txt", "Log format, valid options are txt and json")
namespace = flag.String("namespace", getEnv("REDIS_EXPORTER_NAMESPACE", "redis"), "Namespace for metrics")
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")
checkSingleKeys = flag.String("check-single-keys", getEnv("REDIS_EXPORTER_CHECK_SINGLE_KEYS", ""), "Comma separated list of single keys to export value and length/size")
scriptPath = flag.String("script", getEnv("REDIS_EXPORTER_SCRIPT", ""), "Path to Lua Redis script for collecting extra metrics")
separator = flag.String("separator", getEnv("REDIS_EXPORTER_SEPARATOR", ","), "separator used to split redis.addr, redis.password and redis.alias into several elements.")
listenAddress = flag.String("web.listen-address", getEnv("REDIS_EXPORTER_WEB_LISTEN_ADDRESS", ":9121"), "Address to listen on for web interface and telemetry.")
metricPath = flag.String("web.telemetry-path", getEnv("REDIS_EXPORTER_WEB_TELEMETRY_PATH", "/metrics"), "Path under which to expose metrics.")
isDebug = flag.Bool("debug", getEnvBool("REDIS_EXPORTER_DEBUG"), "Output verbose debug information")
logFormat = flag.String("log-format", getEnv("REDIS_EXPORTER_LOG_FORMAT", "txt"), "Log format, valid options are txt and json")
showVersion = flag.Bool("version", false, "Show version information and exit")
useCfBindings = flag.Bool("use-cf-bindings", false, "Use Cloud Foundry service bindings")
redisMetricsOnly = flag.Bool("redis-only-metrics", false, "Whether to export go runtime metrics also")
useCfBindings = flag.Bool("use-cf-bindings", getEnvBool("REDIS_EXPORTER_USE-CF-BINDINGS"), "Use Cloud Foundry service bindings")
redisMetricsOnly = flag.Bool("redis-only-metrics", getEnvBool("REDIS_EXPORTER_REDIS_ONLY_METRICS"), "Whether to export go runtime metrics also")

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

func getEnvBool(key string) (envValBool bool) {
if envVal, ok := os.LookupEnv(key); ok {
envValBool, _ = strconv.ParseBool(envVal)
}
return
}

func main() {
flag.Parse()

Expand Down

0 comments on commit e0b388f

Please sign in to comment.