Skip to content

Commit 0e0639d

Browse files
authored
major rewrite for version v1.0.0 with a bunch of breaking changes (#256)
1 parent 42235be commit 0e0639d

35 files changed

+2125
-4634
lines changed

.drone.yml

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ services:
1111
image: redis:5
1212
ports:
1313
- 6379
14-
- name: moar-redis
14+
- name: pwd-redis
1515
image: redis:5
16-
commands:
17-
- /usr/local/bin/redis-server --port 6380
16+
commands:
17+
- "/usr/local/bin/redis-server --port 6380 --requirepass redis-password"
1818
ports:
1919
- 6380
2020
- name: redis-cluster
@@ -38,21 +38,21 @@ steps:
3838
environment:
3939
GO111MODULE: on
4040
LOG_LEVEL: "info"
41-
TEST_TILE38_URI: "tile38:9851"
42-
TEST_SECOND_REDIS_URI: "redis://moar-redis:6380"
43-
TEST_REDIS_CLUSTER_MASTER_URI: "redis-cluster:7000"
44-
TEST_REDIS_CLUSTER_SLAVE_URI: "redis-cluster:7005"
41+
TEST_TILE38_URI: "redis://tile38:9851"
42+
TEST_REDIS_URI: "redis://redis:6379"
43+
TEST_PWD_REDIS_URI: "redis://h:redis-password@pwd-redis:6380"
44+
TEST_REDIS_CLUSTER_MASTER_URI: "redis://redis-cluster:7000"
45+
TEST_REDIS_CLUSTER_SLAVE_URI: "redis://redis-cluster:7005"
4546
COVERALLS_TOKEN:
4647
from_secret: coveralls-token
4748
commands:
4849
- 'go build -mod=vendor'
4950
- "sleep 10" # let the redis test instances all come up first
50-
- 'go test -mod=vendor -v -covermode=atomic -cover -race -coverprofile=coverage.txt ./exporter/... --redis.addr=redis'
51+
- 'go test -mod=vendor -v -covermode=atomic -cover -race -coverprofile=coverage.txt .'
5152
- 'echo "checking gofmt"'
52-
- 'echo " ! gofmt -d main.go 2>&1 | read " | bash'
53-
- 'echo " ! gofmt -d exporter/*.go 2>&1 | read " | bash'
53+
- 'echo " ! gofmt -d *.go 2>&1 | read " | bash'
5454
- 'echo "checking gofmt - DONE"'
55-
- 'go vet ./exporter/...'
55+
- 'go vet .'
5656
- 'go get github.com/mattn/goveralls'
5757
- '/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io'
5858
when:
@@ -122,27 +122,3 @@ steps:
122122
when:
123123
event:
124124
- tag
125-
126-
127-
#
128-
# temporary addtl. build step while working on #256
129-
#
130-
- name: release-docker-image-alpine-v1.0.0-rc.1
131-
image: plugins/docker
132-
settings:
133-
tags: "v1.0.0-rc.1"
134-
dockerfile: ./Dockerfile
135-
repo: oliver006/redis_exporter
136-
target: alpine
137-
build_args:
138-
- 'TAG=v1.0.0-rc.1'
139-
- 'SHA1=${DRONE_COMMIT_SHA}'
140-
username:
141-
from_secret: docker_user
142-
password:
143-
from_secret: docker_pass
144-
when:
145-
branch:
146-
- oh_1.0_here_we_come
147-
repo:
148-
- oliver006/redis_exporter

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
redis_exporter
22
coverage.out
3+
coverage.txt
34
dist/
45
pkg/
56
src/

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
FROM golang:1.12-alpine as builder
55
WORKDIR /go/src/github.com/oliver006/redis_exporter/
66

7-
ADD main.go /go/src/github.com/oliver006/redis_exporter/
8-
ADD exporter /go/src/github.com/oliver006/redis_exporter/exporter
7+
ADD *.go /go/src/github.com/oliver006/redis_exporter/
98
ADD vendor /go/src/github.com/oliver006/redis_exporter/vendor
109

1110
ARG SHA1

README.md

Lines changed: 114 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33

44
[![Build Status](https://cloud.drone.io/api/badges/oliver006/redis_exporter/status.svg)](https://cloud.drone.io/oliver006/redis_exporter)
5-
[![Coverage Status](https://coveralls.io/repos/github/oliver006/redis_exporter/badge.svg?branch=master)](https://coveralls.io/github/oliver006/redis_exporter?branch=master) [![codecov](https://codecov.io/gh/oliver006/redis_exporter/branch/master/graph/badge.svg)](https://codecov.io/gh/oliver006/redis_exporter)
5+
[![Coverage Status](https://coveralls.io/repos/github/oliver006/redis_exporter/badge.svg?branch=master)](https://coveralls.io/github/oliver006/redis_exporter?branch=master) [![codecov](https://codecov.io/gh/oliver006/redis_exporter/branch/master/graph/badge.svg)](https://codecov.io/gh/oliver006/redis_exporter) [![docker_pulls](https://img.shields.io/docker/pulls/oliver006/redis_exporter.svg)](https://img.shields.io/docker/pulls/oliver006/redis_exporter.svg)
6+
67

78
Prometheus exporter for Redis metrics.\
89
Supports Redis 2.x, 3.x, 4.x, and 5.x
910

11+
1012
## Building, configuring, and running
1113

14+
### Upgrading from 0.x to 1.x ?
15+
16+
[PR #256](https://github.com/oliver006/redis_exporter/pull/256) introduced breaking changes which were released as version v1.0.0.
17+
18+
If you only scrape one Redis instance and use command line flags `--redis.address`
19+
and `--redis.password` then you're most probably not affected.
20+
Otherwise, please see [PR #256](https://github.com/oliver006/redis_exporter/pull/256) and this README for more information.
21+
22+
23+
1224
### Build and run locally:
1325

1426
```sh
@@ -19,23 +31,89 @@ Supports Redis 2.x, 3.x, 4.x, and 5.x
1931
```
2032

2133

22-
### Prometheus Configuration
34+
35+
### Basic Prometheus Configuration
2336

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

2639
```yaml
2740
scrape_configs:
41+
- job_name: redis_exporter
42+
static_configs:
43+
- targets: ['<<REDIS-EXPORTER-HOSTNAME>>:9121']
44+
```
45+
46+
and adjust the host name accordingly.
47+
48+
49+
50+
### Prometheus Configuration to Scrape Several Hosts
51+
52+
Run the exporter with the command line flag `--redis.addr=` so it won't try to access
53+
the local instance every time the `/metrics` endpoint is scraped.
54+
55+
```yaml
56+
57+
scrape_configs:
58+
## config for the multiple Redis targets that the exporter will scrape
59+
- job_name: 'redis_exporter_targets'
60+
static_configs:
61+
- targets:
62+
- redis://first-redis-host:6379
63+
- redis://second-redis-host:6379
64+
metrics_path: /scrape
65+
relabel_configs:
66+
- source_labels: [__address__]
67+
target_label: __param_target
68+
- source_labels: [__param_target]
69+
target_label: instance
70+
- target_label: __address__
71+
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
72+
73+
## config for scraping the exporter itself
74+
- job_name: 'redis_exporter'
75+
static_configs:
76+
- targets:
77+
- <<REDIS-EXPORTER-HOSTNAME>>:9121
78+
```
2879

29-
...
80+
The Redis instances are listed under `targets`, the Redis exporter hostname is configured via the last relabel_config rule.\
81+
If authentication is needed for the Redis instances then you can set the password via the `--redis.password` command line option of
82+
the exporter (this means you can currently only use one password across the instances you try to scrape this way. Use several
83+
exporters if this is a problem). \
84+
You can also use a file supply multiple targets by using `file_sd_configs` like so:
3085

31-
- job_name: redis_exporter
32-
static_configs:
33-
- targets: ['localhost:9121']
86+
```yaml
3487
35-
...
88+
scrape_configs:
89+
- job_name: 'redis_exporter'
90+
file_sd_configs:
91+
- files:
92+
- targets-redis-instances.json
93+
metrics_path: /scrape
94+
relabel_configs:
95+
- source_labels: [__address__]
96+
target_label: __param_target
97+
- source_labels: [__param_target]
98+
target_label: instance
99+
- target_label: __address__
100+
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
36101
```
37102

38-
and adjust the host name accordingly.
103+
The `targets-redis-instances.json` should look something like this:
104+
105+
```json
106+
[
107+
{
108+
"targets": [ "redis-host-01:6379", "redis-host-02:6379"],
109+
"labels": { }
110+
}
111+
]
112+
```
113+
114+
Prometheus uses file watches and all changes to the json file are applied immediately.
115+
116+
39117

40118
### Run via Docker:
41119

@@ -44,7 +122,6 @@ The latest release is automatically published to the [Docker registry](https://h
44122
You can run it like this:
45123

46124
```sh
47-
$ docker pull oliver006/redis_exporter
48125
$ docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter
49126
```
50127

@@ -55,96 +132,47 @@ in an image that has a shell, etc then you can run the `alpine` image:
55132
$ docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter:alpine
56133
```
57134

58-
If you try to access a redis instance running on the host node, you'll need to add `--network host` so the
135+
If you try to access a Redis instance running on the host node, you'll need to add `--network host` so the
59136
redis_exporter container can access it:
60137

61138
```sh
62139
$ docker run -d --name redis_exporter --network host oliver006/redis_exporter
63140
```
64141

65-
### Run on Kubernetes
66-
67-
[Here](contrib/k8s-redis-and-exporter-deployment.yaml) is an example Kubernetes deployment configuration for how to deploy the redis_exporter as a sidecar with a Redis instance.
68-
69-
70-
### Run on Openshift
71-
72-
In order to deploy the exporter on Openshift environment.
73142

74-
```sh
75-
oc project <myproject>
76-
77-
oc process -f https://raw.githubusercontent.com/oliver006/redis_exporter/master/contrib/openshift-template.yaml \
78-
-p REDIS_ADDR=<redis-service>:<redis-port> \
79-
-p REDIS_PASSWORD=<redis-pass> \
80-
-p REDIS_ALIAS=<redis-alias> \
81-
-p REDIS_FILE=<redis-file> \
82-
| oc create -f -
83-
```
84-
85-
*NOTE*: Some of the parameters can be omitted if no authentication is used or the default redis config is applied.
86-
87-
```sh
88-
oc process -f https://raw.githubusercontent.com/oliver006/redis_exporter/master/contrib/openshift-template.yaml \
89-
-p REDIS_ADDR=<redis-service>:<redis-port> \
90-
| oc create -f -
91-
```
92143

93-
If you are running Prometheus on Openshift on the same cluster, **target** in `prometheus.yml` should point to the correct service name of the exporter
94-
95-
```yaml
96-
scrape_configs:
144+
### Run on Kubernetes
97145

98-
...
146+
[Here](contrib/k8s-redis-and-exporter-deployment.yaml) is an example Kubernetes deployment configuration for how to deploy the redis_exporter as a sidecar to a Redis instance.
99147

100-
- job_name: redis_exporter
101-
static_configs:
102-
- targets: ['<redis-exporter.myproject.svc>:9121']
103148

104-
...
105-
```
106149

107-
### Run on Cloud Foundry
150+
### Flags
108151

109-
```sh
110-
cf push -f contrib/manifest.yml
111-
```
152+
Name | Environment Variable Name | Description
153+
-----------------------|------------------------------------|-----------------
154+
redis.addr | REDIS_ADDR | Address of the Redis instance, defaults to `redis://localhost:6379`.
155+
redis.password | REDIS_PASSWORD | Password of the Redis instance, defaults to `""` (no password).
156+
check-keys | REDIS_EXPORTER_CHECK_KEYS | Comma 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](https://redis.io/commands/scan). Use this option if you need glob pattern matching; `check-single-keys` is faster for non-pattern keys.
157+
check-single-keys | REDIS_EXPORTER_CHECK_SINGLE_KEYS | Comma 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`.
158+
script | REDIS_EXPORTER_SCRIPT | Path to Redis Lua script for gathering extra metrics.
159+
debug | REDIS_EXPORTER_DEBUG | Verbose debug output
160+
log-format | REDIS_EXPORTER_LOG_FORMAT | Log format, valid options are `txt` (default) and `json`.
161+
namespace | REDIS_EXPORTER_NAMESPACE | Namespace for the metrics, defaults to `redis`.
162+
connection-timeout | REDIS_EXPORTER_CONNECTION_TIMEOUT | Timeout for connection to Redis instance, defaults to "15s" (in Golang duration format)
163+
web.listen-address | REDIS_EXPORTER_WEB_LISTEN_ADDRESS | Address to listen on for web interface and telemetry, defaults to `0.0.0.0:9121`.
164+
web.telemetry-path | REDIS_EXPORTER_WEB_TELEMETRY_PATH | Path under which to expose metrics, defaults to `/metrics`.
165+
redis-only-metrics | REDIS_EXPORTER_REDIS_ONLY_METRICS | Whether to also export go runtime metrics, defaults to false.
166+
include-system-metrics | REDIS_EXPORTER_IS_TILE38 | Whether to include system metrics like `total_system_memory_bytes`, defaults to false.
167+
is-tile38 | REDIS_EXPORTER_IS_TILE38 | Whether to scrape Tile38 specific metrics, defaults to false.
112168

169+
Redis instance addresses can be tcp addresses: `redis://localhost:6379`, `redis.example.com:6379` or e.g. unix sockets: `unix:///tmp/redis.sock`.\
170+
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).\
171+
Password-protected instances can be accessed by using the URI format including a password: `redis://h:<<PASSWORD>>@<<HOSTNAME>>:<<PORT>>`
113172

173+
Command line settings take precedence over any configurations provided by the environment variables.
114174

115-
### Flags
116175

117-
Name | Description
118-
--------------------|------------
119-
debug | Verbose debug output
120-
log-format | Log format, valid options are `txt` (default) and `json`.
121-
check-keys | Comma 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](https://redis.io/commands/scan). Use this option if you need glob pattern matching; `check-single-keys` is faster for non-pattern keys.
122-
check-single-keys | Comma 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`.
123-
script | Path to Redis Lua script for gathering extra metrics.
124-
redis.addr | Address of one or more redis nodes, comma separated, defaults to `redis://localhost:6379`.
125-
redis.password | Password to use when authenticating to Redis
126-
redis.password-file | Path to a file containing the password to use when authenticating to Redis (note: this is mutually exclusive with `redis.password`)
127-
redis.alias | Alias for redis node addr, comma separated.
128-
redis.file | Path 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](./contrib/sample_redis_hosts_file.txt) for an example file.
129-
namespace | Namespace for the metrics, defaults to `redis`.
130-
web.listen-address | Address to listen on for web interface and telemetry, defaults to `0.0.0.0:9121`.
131-
web.telemetry-path | Path under which to expose metrics, defaults to `metrics`.
132-
use-cf-bindings | Enable usage of Cloud Foundry service bindings. Defaults to `false`
133-
separator | Separator used to split redis.addr, redis.password and redis.alias into several elements. Defaults to `,`
134-
135-
Redis node addresses can be tcp addresses like `redis://localhost:6379`, `redis.example.com:6379` or unix socket addresses like `unix:///tmp/redis.sock`.\
136-
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).
137-
138-
These settings take precedence over any configurations provided by [environment variables](#environment-variables).
139-
140-
### Environment Variables
141-
142-
Name | Description
143-
-------------------|------------
144-
REDIS_ADDR | Address of Redis node(s)
145-
REDIS_PASSWORD | Password to use when authenticating to Redis
146-
REDIS_ALIAS | Alias name of Redis node(s)
147-
REDIS_FILE | Path to file containing Redis node(s)
148176

149177
### What's exported?
150178

@@ -155,6 +183,8 @@ You can also export values of keys if they're in numeric format by using the `-c
155183

156184
If you require custom metric collection, you can provide a [Redis Lua script](https://redis.io/commands/eval) using the `-script` flag. An example can be found [in the contrib folder](./contrib/sample_collect_script.lua).
157185

186+
187+
158188
### What does it look like?
159189

160190
Example [Grafana](http://grafana.org/) screenshots:\
@@ -163,8 +193,8 @@ Example [Grafana](http://grafana.org/) screenshots:\
163193

164194
Grafana dashboard is available on [grafana.net](https://grafana.net/dashboards/763) and/or [github.com](contrib/grafana_prometheus_redis_dashboard.json).
165195

166-
Grafana dashboard with host & alias selector is available on [github.com](contrib/grafana_prometheus_redis_dashboard_alias.json).
196+
167197

168198
### What else?
169199

170-
Open an issue or PR if you have more suggestions or ideas about what to add.
200+
Open an issue or PR if you have more suggestions, questions or ideas about what to add.

build-github-binaries.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

3+
34
set -u -e -o pipefail
45

56
if [[ -z "${DRONE_TAG}" ]] ; then
@@ -19,17 +20,21 @@ if [[ -f 'go.mod' ]] ; then
1920
go mod tidy
2021
fi
2122

22-
gox -verbose -os="darwin linux freebsd windows netbsd" -arch="386 amd64" -rebuild -ldflags "${GO_LDFLAGS}" -output '.build/{{.OS}}-{{.Arch}}/{{.Dir}}'
23+
gox -verbose -os="darwin linux" -arch="386 amd64" -rebuild -ldflags "${GO_LDFLAGS}" -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}"
2324

2425
mkdir -p dist
2526
for build in $(ls .build); do
2627
echo "Creating archive for ${build}"
27-
if [[ "${build}" =~ ^windows-.*$ ]] ; then
28+
29+
cp LICENSE README.md ".build/${build}/"
30+
31+
if [[ "${build}" =~ windows-.*$ ]] ; then
32+
2833
# Make sure to clear out zip files to prevent zip from appending to the archive.
2934
rm "dist/redis_exporter-${DRONE_TAG}.${build}.zip" || true
30-
cd ".build/${build}" && zip --quiet -9 "../../dist/redis_exporter-${DRONE_TAG}.${build}.zip" 'redis_exporter.exe' && cd ../../
35+
cd ".build/" && zip -r --quiet -9 "../dist/${build}.zip" "${build}" && cd ../
3136
else
32-
tar -C ".build/${build}" -czf "dist/redis_exporter-${DRONE_TAG}.${build}.tar.gz" 'redis_exporter'
37+
tar -C ".build/" -czf "dist/${build}.tar.gz" "${build}"
3338
fi
3439
done
3540

0 commit comments

Comments
 (0)