diff --git a/Dockerfile b/Dockerfile index af502939..d0f06fe6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # # build container # -FROM golang:1.10 +FROM golang:1-alpine WORKDIR /go/src/github.com/oliver006/redis_exporter/ ADD main.go /go/src/github.com/oliver006/redis_exporter/ @@ -15,7 +15,9 @@ ENV TAG=$TAG ARG DATE ENV DATE=$DATE -RUN CGO_ENABLED=0 GOOS=linux go build -ldflags " -X main.VERSION=$TAG -X main.COMMIT_SHA1=$SHA1 -X main.BUILD_DATE=$DATE " -a -installsuffix cgo -o redis_exporter . +RUN apk --no-cache add ca-certificates +RUN CGO_ENABLED=0 GOOS=linux go build -o /redis_exporter \ + -ldflags "-s -w -extldflags \"-static\" -X main.VERSION=$TAG -X main.COMMIT_SHA1=$SHA1 -X main.BUILD_DATE=$DATE" . @@ -23,10 +25,10 @@ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags " -X main.VERSION=$TAG -X main.C # # release container # -FROM alpine:latest -RUN apk --no-cache add ca-certificates -WORKDIR /bin/ -COPY --from=0 /go/src/github.com/oliver006/redis_exporter/ . +FROM scratch + +COPY --from=0 /redis_exporter /redis_exporter +COPY --from=0 /etc/ssl/certs /etc/ssl/certs EXPOSE 9121 -ENTRYPOINT [ "/bin/redis_exporter" ] +ENTRYPOINT [ "/redis_exporter" ] diff --git a/README.md b/README.md index b82bbf0c..5539f855 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@ # Redis Metrics Exporter + [![Circle CI](https://circleci.com/gh/oliver006/redis_exporter.svg?style=shield)](https://circleci.com/gh/oliver006/redis_exporter) [![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) -Prometheus exporter for Redis metrics.
+Prometheus exporter for Redis metrics.\ Supports Redis 2.x, 3.x, 4.x, and 5.x ## Building, configuring, and running Locally build and run it: -``` +```sh $ go get github.com/oliver006/redis_exporter $ cd $GOPATH/src/github.com/oliver006/redis_exporter $ go build @@ -17,14 +18,14 @@ Locally build and run it: You can also run it via docker: -``` +```sh $ docker pull oliver006/redis_exporter $ docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter ``` Add a block to the `scrape_configs` of your prometheus.yml config file: -``` +```yaml scrape_configs: ... @@ -35,23 +36,24 @@ scrape_configs: ... ``` + and adjust the host name accordingly. To run on Cloud Foundry, use: -``` +```sh cf push -f contrib/manifest.yml ``` -#### Run on Kubernetes +### 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. - -#### Run on Openshift +### Run on Openshift In order to deploy the exporter on Openshift environment. -``` + +```sh oc project oc process -f https://raw.githubusercontent.com/ivanovaleksandar/redis_exporter/master/contrib/openshift-template.yaml \ @@ -63,14 +65,16 @@ oc process -f https://raw.githubusercontent.com/ivanovaleksandar/redis_exporter/ ``` *NOTE*: Some of the parameters can be ommited if no authentication is used or the default redis config is applied. -``` + +```sh oc process -f https://raw.githubusercontent.com/ivanovaleksandar/redis_exporter/contrib/openshift-template.yaml \ -p REDIS_ADDR=: \ | 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: ... @@ -82,7 +86,6 @@ scrape_configs: ... ``` - ### Flags Name | Description @@ -95,19 +98,18 @@ 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.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 ,,. +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 `,,`. 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`.
+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 @@ -120,15 +122,16 @@ REDIS_FILE | Path to file containing Redis node(s) ### What's exported? Most items from the INFO command are exported, -see http://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, etc.
+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, etc. 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). ### What does it look like? -Example [Grafana](http://grafana.org/) screenshots:
-redis_exporter_screen
+ +Example [Grafana](http://grafana.org/) screenshots:\ +redis_exporter_screen\ redis_exporter_screen_02 Grafana dashboard is available on [grafana.net](https://grafana.net/dashboards/763) and/or [github.com](contrib/grafana_prometheus_redis_dashboard.json). @@ -138,4 +141,3 @@ Grafana dashboard with host & alias selector is available on [github.com](contri ### What else? Open an issue or PR if you have more suggestions or ideas about what to add. - diff --git a/build.sh b/build.sh index 3ab77b68..0a51dbea 100755 --- a/build.sh +++ b/build.sh @@ -29,7 +29,7 @@ docker push "oliver006/redis_exporter:latest" echo "Building binaries for Github" echo "" export CGO_ENABLED=0 -export GO_LDFLAGS="-extldflags \"-static\" -X main.VERSION=$CIRCLE_TAG -X main.COMMIT_SHA1=$CIRCLE_SHA1 -X main.BUILD_DATE=$(date +%F-%T)" +export GO_LDFLAGS="-s -w -extldflags \"-static\" -X main.VERSION=$CIRCLE_TAG -X main.COMMIT_SHA1=$CIRCLE_SHA1 -X main.BUILD_DATE=$(date +%F-%T)" echo "GO_LDFLAGS: $GO_LDFLAGS" go get github.com/mitchellh/gox