Skip to content

Commit

Permalink
set-client-name flag (oliver006#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Fawcett authored and oliver006 committed Dec 16, 2019
1 parent e15c7d2 commit 14dda66
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export-client-list | REDIS_EXPORTER_EXPORT_CLIENT_LIST | Whether to scrap
skip-tls-verification | REDIS_EXPORTER_SKIP_TLS_VERIFICATION | Whether to to skip TLS verification
tls-client-key-file | REDIS_EXPORTER_TLS_CLIENT_KEY_FILE | Name of the client key file (including full path) if the server requires TLS client authentication
tls-client-cert-file | REDIS_EXPORTER_TLS_CLIENT_CERT_FILE | Name the client cert file (including full path) if the server requires TLS client authentication
set-client-name | REDIS_EXPORTER_SET_CLIENT_NAME | Whether to set client name to redis_exporter, defaults to true.

Redis instance addresses can be tcp addresses: `redis://localhost:6379`, `redis.example.com:6379` or e.g. unix sockets: `unix:///tmp/redis.sock`.\
SSL is supported by using the `rediss://` schema, for example: `rediss://azure-ssl-enabled-host.redis.cache.windows.net:6380` (note that the port is required when connecting to a non-standard 6379 port, e.g. with Azure Redis instances).\
Expand Down
7 changes: 5 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type ExporterOptions struct {
ClientCertificates []tls.Certificate
InclSystemMetrics bool
SkipTLSVerification bool
SetClientName bool
IsTile38 bool
ExportClientList bool
ConnectionTimeouts time.Duration
Expand Down Expand Up @@ -1138,8 +1139,10 @@ func (e *Exporter) scrapeRedisHost(ch chan<- prometheus.Metric) error {

log.Debugf("connected to: %s", e.redisAddr)

if _, err := doRedisCmd(c, "CLIENT", "SETNAME", "redis_exporter"); err != nil {
log.Errorf("Couldn't set client name, err: %s", err)
if e.options.SetClientName {
if _, err := doRedisCmd(c, "CLIENT", "SETNAME", "redis_exporter"); err != nil {
log.Errorf("Couldn't set client name, err: %s", err)
}
}

dbCount := 0
Expand Down
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ func getEnv(key string, defaultVal string) string {
return defaultVal
}

func getEnvBool(key string) (res bool) {
func getEnvBool(key string, defaultVal bool) bool {
if envVal, ok := os.LookupEnv(key); ok {
res, _ = strconv.ParseBool(envVal)
envBool, err := strconv.ParseBool(envVal)
if err == nil {
return envBool
}
}
return res
return defaultVal
}

func main() {
Expand All @@ -50,13 +53,14 @@ func main() {
connectionTimeout = flag.String("connection-timeout", getEnv("REDIS_EXPORTER_CONNECTION_TIMEOUT", "15s"), "Timeout for connection to Redis instance")
tlsClientKeyFile = flag.String("tls-client-key-file", getEnv("REDIS_EXPORTER_TLS_CLIENT_KEY_FILE", ""), "Name of the client key file (including full path) if the server requires TLS client authentication")
tlsClientCertFile = flag.String("tls-client-cert-file", getEnv("REDIS_EXPORTER_TLS_CLIENT_CERT_FILE", ""), "Name of the client certificate file (including full path) if the server requires TLS client authentication")
isDebug = flag.Bool("debug", getEnvBool("REDIS_EXPORTER_DEBUG"), "Output verbose debug information")
isTile38 = flag.Bool("is-tile38", getEnvBool("REDIS_EXPORTER_IS_TILE38"), "Whether to scrape Tile38 specific metrics")
exportClientList = flag.Bool("export-client-list", getEnvBool("REDIS_EXPORTER_EXPORT_CLIENT_LIST"), "Whether to scrape Client List specific metrics")
isDebug = flag.Bool("debug", getEnvBool("REDIS_EXPORTER_DEBUG", false), "Output verbose debug information")
setClientName = flag.Bool("set-client-name", getEnvBool("REDIS_EXPORTER_SET_CLIENT_NAME", true), "Whether to set client name to redis_exporter")
isTile38 = flag.Bool("is-tile38", getEnvBool("REDIS_EXPORTER_IS_TILE38", false), "Whether to scrape Tile38 specific metrics")
exportClientList = flag.Bool("export-client-list", getEnvBool("REDIS_EXPORTER_EXPORT_CLIENT_LIST", false), "Whether to scrape Client List specific metrics")
showVersion = flag.Bool("version", false, "Show version information and exit")
redisMetricsOnly = flag.Bool("redis-only-metrics", getEnvBool("REDIS_EXPORTER_REDIS_ONLY_METRICS"), "Whether to also export go runtime metrics")
inclSystemMetrics = flag.Bool("include-system-metrics", getEnvBool("REDIS_EXPORTER_INCL_SYSTEM_METRICS"), "Whether to include system metrics like e.g. redis_total_system_memory_bytes")
skipTLSVerification = flag.Bool("skip-tls-verification", getEnvBool("REDIS_EXPORTER_SKIP_TLS_VERIFICATION"), "Whether to to skip TLS verification")
redisMetricsOnly = flag.Bool("redis-only-metrics", getEnvBool("REDIS_EXPORTER_REDIS_ONLY_METRICS", false), "Whether to also export go runtime metrics")
inclSystemMetrics = flag.Bool("include-system-metrics", getEnvBool("REDIS_EXPORTER_INCL_SYSTEM_METRICS", false), "Whether to include system metrics like e.g. redis_total_system_memory_bytes")
skipTLSVerification = flag.Bool("skip-tls-verification", getEnvBool("REDIS_EXPORTER_SKIP_TLS_VERIFICATION", false), "Whether to to skip TLS verification")
)
flag.Parse()

Expand Down Expand Up @@ -122,6 +126,7 @@ func main() {
CheckSingleKeys: *checkSingleKeys,
LuaScript: ls,
InclSystemMetrics: *inclSystemMetrics,
SetClientName: *setClientName,
IsTile38: *isTile38,
ExportClientList: *exportClientList,
SkipTLSVerification: *skipTLSVerification,
Expand Down

0 comments on commit 14dda66

Please sign in to comment.