Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add redis_exporter role #299

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 43 additions & 0 deletions roles/redis_exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<p><img src="https://www.circonus.com/wp-content/uploads/2015/03/sol-icon-itOps.png" alt="graph logo" title="graph" align="right" height="60" /></p>

# Ansible Role: redis_exporter

## Description

Deploy prometheus [redis_exporter](https://github.com/oliver006/redis_exporter/) using ansible.

## Requirements

- Ansible >= 2.9 (It might work on previous versions, but we cannot guarantee it)
- gnu-tar on Mac deployer host (`brew install gnu-tar`)

## Role Variables

All variables which can be overridden are stored in [defaults/main.yml](defaults/main.yml) file as well as in [meta/argument_specs.yml](meta/argument_specs.yml).
Please refer to the [collection docs](https://prometheus-community.github.io/ansible/branch/main/redis_exporter_role.html) for description and default values of the variables.

## Example

### Demo site

We provide demo site for full monitoring solution based on prometheus and grafana. Repository with code and links to running instances is [available on github](https://github.com/prometheus/demo-site) and site is hosted on [DigitalOcean](https://digitalocean.com).

## Local Testing

The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/ansible-community/molecule) (v3.x). You will have to install Docker on your system. See "Get started" for a Docker package suitable to for your system. Running your tests is as simple as executing `molecule test`.

## Continuous Intergation

Combining molecule and circle CI allows us to test how new PRs will behave when used with multiple ansible versions and multiple operating systems. This also allows use to create test scenarios for different role configurations. As a result we have a quite large test matrix which can take more time than local testing, so please be patient.

## Contributing

See [contributor guideline](CONTRIBUTING.md).

## Troubleshooting

See [troubleshooting](TROUBLESHOOTING.md).

## License

This project is licensed under MIT License. See [LICENSE](/LICENSE) for more details.
51 changes: 51 additions & 0 deletions roles/redis_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
redis_exporter_version: 1.58.0
redis_exporter_binary_local_dir: ""
redis_exporter_binary_url: "https://github.com/{{ _redis_exporter_repo }}/releases/download/v{{ redis_exporter_version }}/\
redis_exporter-v{{ redis_exporter_version }}.linux-{{ go_arch }}.tar.gz"
redis_exporter_checksums_url: "https://github.com/{{ _redis_exporter_repo }}/releases/download/v{{ redis_exporter_version }}/sha256sums.txt"
redis_exporter_skip_install: false

# https://github.com/oliver006/redis_exporter?tab=readme-ov-file#command-line-flags
redis_exporter_addr: "redis://localhost:6379"
redis_exporter_user: ""
redis_exporter_password: ""
redis_exporter_passwords: {}
redis_exporter_check_keys: []
redis_exporter_check_single_keys: []
redis_exporter_check_streams: []
redis_exporter_check_single_streams: []
redis_exporter_check_keys_batch_size: 1000
redis_exporter_count_keys: []
redis_exporter_script: []
redis_exporter_debug: false
redis_exporter_log_format: "txt"
redis_exporter_namespace: "redis"
redis_exporter_connection_timeout: "15s"
redis_exporter_web_listen_address: "0.0.0.0:9121"
redis_exporter_web_telemetry_path: "/metrics"
redis_exporter_redis_only_metrics: false
redis_exporter_incl_config_metrics: false
redis_exporter_incl_system_metrics: false
redis_exporter_redact_config_metrics: false
redis_exporter_ping_on_connect: false
redis_exporter_is_tile38: false
redis_exporter_is_cluster: false
redis_exporter_export_client_list: false
redis_exporter_export_client_port: false
redis_exporter_skip_tls_verification: false
redis_exporter_tls_client_key_file: ""
redis_exporter_tls_client_cert_file: ""
redis_exporter_tls_server_key_file: ""
redis_exporter_tls_server_cert_file: ""
redis_exporter_tls_server_ca_cert_file: ""
redis_exporter_tls_server_min_version: "TLS1.2"
redis_exporter_tls_ca_cert_file: ""
redis_exporter_set_client_name: true
redis_exporter_check_key_groups: []
redis_exporter_max_distinct_key_groups: 100
redis_exporter_config_command: "CONFIG"

redis_exporter_binary_install_dir: "/usr/local/bin"
redis_exporter_system_group: "redis-exp"
redis_exporter_system_user: "{{ redis_exporter_system_group }}"
10 changes: 10 additions & 0 deletions roles/redis_exporter/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Restart redis_exporter
listen: "restart redis_exporter"
become: true
ansible.builtin.systemd:
daemon_reload: true
name: redis_exporter
state: restarted
when:
- not ansible_check_mode
181 changes: 181 additions & 0 deletions roles/redis_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
---
# yamllint disable rule:line-length
argument_specs:
main:
short_description: "Prometheus redis_exporter"
description:
- "Deploy prometheus L(redis exporter,https://github.com/oliver006/redis_exporter) using ansible"
author:
- "Prometheus Community"
options:
redis_exporter_version:
description: "redis_exporter package version. Also accepts latest as parameter."
default: "1.58.0"
redis_exporter_skip_install:
description: "redis_exporter installation tasks gets skipped when set to true."
type: bool
default: false
redis_exporter_binary_local_dir:
description:
- "Enables the use of local packages instead of those distributed on github."
- "The parameter may be set to a directory where the C(redis_exporter) binary is stored on the host where ansible is run."
- "This overrides the I(redis_exporter_version) parameter"
redis_exporter_binary_url:
description: "URL of the redis_exporter binaries .tar.gz file"
default: "https://github.com/{{ _redis_exporter_repo }}/releases/download/v{{ redis_exporter_version }}/redis_exporter-v{{ redis_exporter_version }}.linux-{{ go_arch }}.tar.gz"
redis_exporter_checksums_url:
description: "URL of the redis_exporter checksums file"
default: "https://github.com/{{ _redis_exporter_repo }}/releases/download/v{{ redis_exporter_version }}/sha256sums.txt"
redis_exporter_addr:
description: "Address of the Redis instance"
default: "redis://localhost:6379"
redis_exporter_user:
description: "User name to use for authentication (Redis ACL for Redis 6.0 and newer)"
default: ""
redis_exporter_password:
description: "Password of the Redis instance"
default: ""
redis_exporter_passwords:
description:
- "Dictionary with passwords for instances."
- "Read more official L(documentation, https://github.com/oliver006/redis_exporter?tab=readme-ov-file#authenticating-with-redis)"
type: "dict"
default: {}
redis_exporter_check_keys:
description: "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. Warning: using --check-keys to match a very large number of keys can slow down the exporter to the point where it doesn't finish scraping the redis instance."
type: "list"
default: []
redis_exporter_check_single_keys:
description: "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."
type: "list"
default: []
redis_exporter_check_streams:
description: "List of stream-patterns to export info about streams, groups and consumers. Syntax is the same as check-keys."
type: "list"
default: []
redis_exporter_check_single_streams:
description: "List of streams to export info about streams, groups and consumers. The streams 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-streams."
type: "list"
default: []
redis_exporter_check_keys_batch_size:
description: "Approximate number of keys to process in each execution. This is basically the COUNT option that will be passed into the SCAN command as part of the execution of the key or key group metrics, see COUNT option. Larger value speeds up scanning. Still Redis is a single-threaded app, huge COUNT can affect production environment."
type: "int"
default: 1000
redis_exporter_count_keys:
description: "List of patterns to count, eg: db3=sessions:* will count all keys with prefix sessions: from db 3. db defaults to 0 if omitted. Warning: The exporter runs SCAN to count the keys. This might not perform well on large databases."
type: "list"
default: []
redis_exporter_script:
description: "List of path(s) to Redis Lua script(s) for gathering extra metrics."
type: "list"
default: []
redis_exporter_debug:
description: "Verbose debug output"
type: bool
default: false
redis_exporter_log_format:
description: "Output format of log messages. One of: [txt, json]"
default: "txt"
redis_exporter_namespace:
description: "Namespace for the metrics"
default: "redis"
redis_exporter_connection_timeout:
description: "Timeout for connection to Redis instance"
default: "15s"
redis_exporter_web_listen_address:
description: "Address to listen on for web interface and telemetry"
default: "0.0.0.0:9121"
redis_exporter_web_telemetry_path:
description: "Path under which to expose metrics"
default: "/metrics"
redis_exporter_redis_only_metrics:
description: "Whether to also export go runtime metrics"
type: bool
default: false
redis_exporter_incl_config_metrics:
description: "Whether to include all config settings as metrics"
type: bool
default: false
redis_exporter_incl_system_metrics:
description: "Whether to include system metrics like total_system_memory_bytes"
type: bool
default: false
redis_exporter_redact_config_metrics:
description: "Whether to redact config settings that include potentially sensitive information like passwords."
type: bool
default: false
redis_exporter_ping_on_connect:
description: "Whether to ping the redis instance after connecting and record the duration as a metric."
type: bool
default: false
redis_exporter_is_tile38:
description: "Whether to scrape Tile38 specific metrics"
type: bool
default: false
redis_exporter_is_cluster:
description: "Whether this is a redis cluster (Enable this if you need to fetch key level data on a Redis Cluster)."
type: bool
default: false
redis_exporter_export_client_list:
description: "Whether to scrape Client List specific metrics"
type: bool
default: false
redis_exporter_export_client_port:
description: "Whether to include the client's port when exporting the client list. Warning: including the port increases the number of metrics generated and will make your Prometheus server take up more memory"
type: bool
default: false
redis_exporter_skip_tls_verification:
description: "Whether to to skip TLS verification when the exporter connects to a Redis instance"
type: bool
default: false
redis_exporter_tls_client_key_file:
description: "Name of the client key file (including full path) if the server requires TLS client authentication"
default: ""
redis_exporter_tls_client_cert_file:
description: "Name the client cert file (including full path) if the server requires TLS client authentication"
default: ""
redis_exporter_tls_server_key_file:
description: "Name of the server key file (including full path) if the web interface and telemetry should use TLS"
default: ""
redis_exporter_tls_server_cert_file:
description: "Name of the server certificate file (including full path) if the web interface and telemetry should use TLS"
default: ""
redis_exporter_tls_server_ca_cert_file:
description: "Name of the CA certificate file (including full path) if the web interface and telemetry should use TLS"
default: ""
redis_exporter_tls_server_min_version:
description: "Minimum TLS version that is acceptable by the web interface and telemetry when using TLS"
default: "TLS1.2"
redis_exporter_tls_ca_cert_file:
description: "Name of the CA certificate file (including full path) if the server requires TLS client authentication"
default: ""
redis_exporter_set_client_name:
description: "Whether to set client name to redis_exporter"
type: bool
default: true
redis_exporter_check_key_groups:
description: "List of LUA regexes for classifying keys into groups. The regexes are applied in specified order to individual keys, and the group name is generated by concatenating all capture groups of the first regex that matches a key. A key will be tracked under the unclassified group if none of the specified regexes matches it."
type: "list"
default: []
redis_exporter_max_distinct_key_groups:
description: "Maximum number of distinct key groups that can be tracked independently per Redis database. If exceeded, only key groups with the highest memory consumption within the limit will be tracked separately, all remaining key groups will be tracked under a single overflow key group."
type: "int"
default: 100
redis_exporter_config_command:
description: "What to use for the CONFIG command"
default: "CONFIG"
redis_exporter_binary_install_dir:
description:
- "I(Advanced)"
- "Directory to install redis_exporter binary"
default: "/usr/local/bin"
redis_exporter_system_group:
description:
- "I(Advanced)"
- "System group for redis_exporter"
default: "redis-exp"
redis_exporter_system_user:
description:
- "I(Advanced)"
- "redis_exporter user"
default: "redis-exp"
31 changes: 31 additions & 0 deletions roles/redis_exporter/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
galaxy_info:
author: "Prometheus Community"
description: "Prometheus redis_exporter"
license: "Apache"
min_ansible_version: "2.9"
platforms:
- name: "Ubuntu"
versions:
- "focal"
- "jammy"
- name: "Debian"
versions:
- "bullseye"
- "buster"
- name: "EL"
versions:
- "7"
- "8"
- "9"
- name: "Fedora"
versions:
- "37"
- '38'
galaxy_tags:
- "monitoring"
- "prometheus"
- "exporter"
- "metrics"
- "system"
- "redis"
13 changes: 13 additions & 0 deletions roles/redis_exporter/molecule/alternative/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
provisioner:
inventory:
group_vars:
all:
redis_exporter_binary_local_dir: "/tmp/redis_exporter-linux-amd64"
redis_exporter_web_listen_address: "127.0.0.1:8080"

redis_exporter_tls_server_ca_cert_file: /etc/redis_exporter/tls.cert
redis_exporter_tls_server_cert_file: /etc/redis_exporter/tls.cert
redis_exporter_tls_server_key_file: /etc/redis_exporter/tls.key
go_arch: amd64
redis_exporter_version: 1.58.0