Sign inSign up

psbarrales/redis-metrics

By psbarrales

•Updated over 7 years ago

Image
0

2.0K

psbarrales/redis-metrics repository overview

⁠Redis Metrics

Build Status Coverage Status codecov

Prometheus exporter for Redis metrics.
With built in redis server Supports Redis 2.x, 3.x, 4.x, and 5.x

⁠Building, configuring, and running

⁠Build and run locally:
    $ go get github.com/psbarrales/redis-metrics
    $ cd $GOPATH/src/github.com/psbarrales/redis-metrics
    $ go build
    $ ./redis_exporter <flags>
⁠Prometheus Configuration

Add a block to the scrape_configs of your prometheus.yml config file:

scrape_configs:

...

- job_name: redis_exporter
  static_configs:
  - targets: ['localhost:9121']

...

and adjust the host name accordingly.

⁠Run via Docker:

The latest release is automatically published to the Docker registry⁠.

You can run it like this:

    $ docker pull psbarrales/redis-metrics
    $ docker run -d --name redis-metrics -p 9121:9121 psbarrales/redis-metrics

The latest docker image contains only the exporter binary. If, e.g. for debugging purposes, you need the exporter running in an image that has a shell, etc then you can run the alpine image:

    $ docker run -d --name redis_exporter -p 9121:9121 psbarrales/redis-metrics:alpine

If you try to access a redis instance running on the host node, you'll need to add --network host so the redis_exporter container can access it:

    $ docker run -d --name redis_exporter --network host psbarrales/redis-metrics
⁠Flags
NameDescription
debugVerbose debug output
log-formatLog format, valid options are txt (default) and json.
check-keysComma separated list of key patterns to export value and length/size, eg: db3=user_count will export key user_count from db 3. db defaults to 0 if omitted. The key patterns specified with this flag will be found using SCAN⁠. Use this option if you need glob pattern matching; check-single-keys is faster for non-pattern keys.
check-single-keysComma separated list of keys to export value and length/size, eg: db3=user_count will export key user_count from db 3. db defaults to 0 if omitted. The keys specified with this flag will be looked up directly without any glob pattern matching. Use this option if you don't need glob pattern matching; it is faster than check-keys.
scriptPath to Redis Lua script for gathering extra metrics.
redis.addrAddress of one or more redis nodes, comma separated, defaults to redis://localhost:6379.
redis.passwordPassword to use when authenticating to Redis
redis.password-filePath to a file containing the password to use when authenticating to Redis (note: this is mutually exclusive with redis.password)
redis.aliasAlias for redis node addr, comma separated.
redis.filePath to file containing one or more redis nodes, separated by newline. This option is mutually exclusive with redis.addr. Each line can optionally be comma-separated with the fields <addr>,<password>,<alias>. See here⁠ for an example file.
namespaceNamespace for the metrics, defaults to redis.
web.listen-addressAddress to listen on for web interface and telemetry, defaults to 0.0.0.0:9121.
web.telemetry-pathPath under which to expose metrics, defaults to metrics.
use-cf-bindingsEnable usage of Cloud Foundry service bindings. Defaults to false
separatorSeparator used to split redis.addr, redis.password and redis.alias into several elements. Defaults to ,

Redis node addresses can be tcp addresses like redis://localhost:6379, redis.example.com:6379 or unix socket addresses like 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).

These settings take precedence over any configurations provided by environment variables⁠.

⁠Environment Variables
NameDescription
REDIS_ADDRAddress of Redis node(s)
REDIS_PASSWORDPassword to use when authenticating to Redis
REDIS_ALIASAlias name of Redis node(s)
REDIS_FILEPath to file containing Redis node(s)
⁠What's exported?

Most items from the INFO command are exported, see https://redis.io/commands/info⁠ for details.
In addition, for every database there are metrics for total keys, expiring keys and the average TTL for keys in the database.
You can also export values of keys if they're in numeric format by using the -check-keys flag. The exporter will also export the size (or, depending on the data type, the length) of the key. This can be used to export the number of elements in (sorted) sets, hashes, lists, streams, etc.

If you require custom metric collection, you can provide a Redis Lua script⁠ using the -script flag. An example can be found in the contrib folder⁠.

⁠What does it look like?

Example Grafana⁠ screenshots:
redis_exporter_screen
redis_exporter_screen_02

Grafana dashboard is available on grafana.net⁠ and/or github.com⁠.

Grafana dashboard with host & alias selector is available on github.com⁠.

⁠What else?

Open an issue or PR if you have more suggestions or ideas about what to add.

Tag summary

Content type

Image

Digest

Size

20.1 MB

Last updated

over 7 years ago

docker pull psbarrales/redis-metrics