Skip to content

Commit

Permalink
partial rewrite for version v1.0.0 with lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed May 10, 2019
1 parent 42235be commit 36cdf48
Show file tree
Hide file tree
Showing 33 changed files with 1,994 additions and 4,533 deletions.
17 changes: 9 additions & 8 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ services:
image: redis:5
ports:
- 6379
- name: moar-redis
- name: pwd-redis
image: redis:5
commands:
- /usr/local/bin/redis-server --port 6380
commands:
- "/usr/local/bin/redis-server --port 6380 --requirepass redis-password"
ports:
- 6380
- name: redis-cluster
Expand All @@ -38,16 +38,17 @@ steps:
environment:
GO111MODULE: on
LOG_LEVEL: "info"
TEST_TILE38_URI: "tile38:9851"
TEST_SECOND_REDIS_URI: "redis://moar-redis:6380"
TEST_REDIS_CLUSTER_MASTER_URI: "redis-cluster:7000"
TEST_REDIS_CLUSTER_SLAVE_URI: "redis-cluster:7005"
TEST_TILE38_URI: "redis://tile38:9851"
TEST_REDIS_URI: "redis://redis:6379"
TEST_PWD_REDIS_URI: "redis://h:redis-password@pwd-redis:6380"
TEST_REDIS_CLUSTER_MASTER_URI: "redis://redis-cluster:7000"
TEST_REDIS_CLUSTER_SLAVE_URI: "redis://redis-cluster:7005"
COVERALLS_TOKEN:
from_secret: coveralls-token
commands:
- 'go build -mod=vendor'
- "sleep 10" # let the redis test instances all come up first
- 'go test -mod=vendor -v -covermode=atomic -cover -race -coverprofile=coverage.txt ./exporter/... --redis.addr=redis'
- 'go test -mod=vendor -v -covermode=atomic -cover -race -coverprofile=coverage.txt ./exporter/...'
- 'echo "checking gofmt"'
- 'echo " ! gofmt -d main.go 2>&1 | read " | bash'
- 'echo " ! gofmt -d exporter/*.go 2>&1 | read " | bash'
Expand Down
167 changes: 85 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,83 @@ Supports Redis 2.x, 3.x, 4.x, and 5.x
```


### Prometheus Configuration
### Basic Prometheus Configuration

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

```yaml
scrape_configs:
- job_name: redis_exporter
static_configs:
- targets: ['<<REDIS-EXPORTER-HOSTNAME>>:9121']
```
and adjust the host name accordingly.
...
### Prometheus Configuration to Scrape Several Hosts
- job_name: redis_exporter
static_configs:
- targets: ['localhost:9121']
Run the exporter with the command line flag `--redis.addr=` so it won't try to scrape
the local instance when the `/metrics` endpoint is hit.

```yaml
...
scrape_configs:
## config for the multiple redis targets that the exporter will scrape
- job_name: 'redis_exporter_targets'
static_configs:
- targets:
- redis://first-redis-host:6379
- redis://h:password@second-redis-host:6379
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- <<REDIS-EXPORTER-HOSTNAME>>:9121
```

and adjust the host name accordingly.
The redis instances are listed under `targets`, the redis exporter hostname is configured via the last relabel_config rule.\

You can also use a file supply multiple targets by using `file_sd_configs` like so:

```yaml
scrape_configs:
- job_name: 'redis_exporter'
file_sd_configs:
- files:
- targets-redis-instances.json
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: <<REDIS-EXPORTER-HOSTNAME>>:9121
```

The `targets-redis-instances.json` should look something like this:

```json
[
{
"targets": [ "redis-host-01:6379", "redis-host-02:6379"],
"labels": { }
}
]
```

Prometheus uses file watches and all changes to the json file are applied immediately.


### Run via Docker:

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

```sh
$ docker pull oliver006/redis_exporter
$ docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter
```

Expand All @@ -64,88 +123,34 @@ redis_exporter container can access it:

### Run on Kubernetes

[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.

[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.

### Run on Openshift

In order to deploy the exporter on Openshift environment.

```sh
oc project <myproject>

oc process -f https://raw.githubusercontent.com/oliver006/redis_exporter/master/contrib/openshift-template.yaml \
-p REDIS_ADDR=<redis-service>:<redis-port> \
-p REDIS_PASSWORD=<redis-pass> \
-p REDIS_ALIAS=<redis-alias> \
-p REDIS_FILE=<redis-file> \
| oc create -f -
```

*NOTE*: Some of the parameters can be omitted if no authentication is used or the default redis config is applied.

```sh
oc process -f https://raw.githubusercontent.com/oliver006/redis_exporter/master/contrib/openshift-template.yaml \
-p REDIS_ADDR=<redis-service>:<redis-port> \
| oc create -f -
```

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

```yaml
scrape_configs:

...
### Flags

- job_name: redis_exporter
static_configs:
- targets: ['<redis-exporter.myproject.svc>:9121']
Name | Environment Variable Name | Description
--------------------|------------------------------------|-----------------
redis.addr | REDIS_ADDR | Address of the redis instance, defaults to `redis://localhost:6379`.
debug | REDIS_EXPORTER_DEBUG | Verbose debug output
log-format | REDIS_EXPORTER_LOG_FORMAT | Log format, valid options are `txt` (default) and `json`.
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.
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`.
script | REDIS_EXPORTER_SCRIPT | Path to Redis Lua script for gathering extra metrics.
namespace | REDIS_EXPORTER_NAMESPACE | Namespace for the metrics, defaults to `redis`.
web.listen-address | REDIS_EXPORTER_WEB_LISTEN_ADDRESS | Address to listen on for web interface and telemetry, defaults to `0.0.0.0:9121`.
web.telemetry-path | REDIS_EXPORTER_WEB_TELEMETRY_PATH | Path under which to expose metrics, defaults to `/metrics`.
redis-only-metrics | REDIS_EXPORTER_REDIS_ONLY_METRICS | Whether to also export go runtime metrics

...
```

### Run on Cloud Foundry
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).\
Password-protected instances can be accessed by using the URI format including a password: `redis://h:<<PASSWORD>>@<<HOSTNAME>>:<<PORT>>`

```sh
cf push -f contrib/manifest.yml
```
Command line settings take precedence over any configurations provided by the environment variables.



### Flags

Name | Description
--------------------|------------
debug | Verbose debug output
log-format | Log format, valid options are `txt` (default) and `json`.
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.
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`.
script | Path to Redis Lua script for gathering extra metrics.
redis.addr | Address of one or more redis nodes, comma separated, defaults to `redis://localhost:6379`.
redis.password | Password to use when authenticating to Redis
redis.password-file | Path to a file containing the password to use when authenticating to Redis (note: this is mutually exclusive with `redis.password`)
redis.alias | Alias for redis node addr, comma separated.
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.
namespace | Namespace for the metrics, defaults to `redis`.
web.listen-address | Address to listen on for web interface and telemetry, defaults to `0.0.0.0:9121`.
web.telemetry-path | Path under which to expose metrics, defaults to `metrics`.
use-cf-bindings | Enable usage of Cloud Foundry service bindings. Defaults to `false`
separator | Separator 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).

### Environment Variables

Name | Description
-------------------|------------
REDIS_ADDR | Address of Redis node(s)
REDIS_PASSWORD | Password to use when authenticating to Redis
REDIS_ALIAS | Alias name of Redis node(s)
REDIS_FILE | Path to file containing Redis node(s)

### What's exported?

Most items from the INFO command are exported,
Expand All @@ -163,8 +168,6 @@ Example [Grafana](http://grafana.org/) screenshots:\

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

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

### What else?

Open an issue or PR if you have more suggestions or ideas about what to add.
13 changes: 9 additions & 4 deletions build-github-binaries.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash


set -u -e -o pipefail

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

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

mkdir -p dist
for build in $(ls .build); do
echo "Creating archive for ${build}"
if [[ "${build}" =~ ^windows-.*$ ]] ; then

cp LICENSE README.md ".build/${build}/"

if [[ "${build}" =~ windows-.*$ ]] ; then

# Make sure to clear out zip files to prevent zip from appending to the archive.
rm "dist/redis_exporter-${DRONE_TAG}.${build}.zip" || true
cd ".build/${build}" && zip --quiet -9 "../../dist/redis_exporter-${DRONE_TAG}.${build}.zip" 'redis_exporter.exe' && cd ../../
cd ".build/" && zip -r --quiet -9 "../dist/${build}.zip" "${build}" && cd ../
else
tar -C ".build/${build}" -czf "dist/redis_exporter-${DRONE_TAG}.${build}.tar.gz" 'redis_exporter'
tar -C ".build/" -czf "dist/${build}.tar.gz" "${build}"
fi
done

Expand Down
27 changes: 27 additions & 0 deletions contrib/docker-compose-for-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
redis:
image: 'redis:5-alpine'
ports:
- '6379:6379'

pwd-redis:
image: 'redis:5-alpine'
command: '/usr/local/bin/redis-server --port 6380 --requirepass redis-password'
ports:
- '6380:6380'

redis-cluster:
image: 'grokzen/redis-cluster'
ports:
- 7000
- 7001
- 7002
- 7003
- 7004
- 7005

tile38:
image: "tile38/tile38:latest"
ports:
- 9851
Loading

0 comments on commit 36cdf48

Please sign in to comment.