Skip to content

Commit

Permalink
Merge pull request #211 from nrvnrvn/shrink-binary-and-image
Browse files Browse the repository at this point in the history
Shrink binary and image
  • Loading branch information
oliver006 committed Dec 22, 2018
2 parents e77a1bd + d0f8ccf commit 1b148d9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -15,18 +15,20 @@ 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" .




#
# 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" ]
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.<br>
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
Expand All @@ -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:

...
Expand All @@ -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 <myproject>

oc process -f https://raw.githubusercontent.com/ivanovaleksandar/redis_exporter/master/contrib/openshift-template.yaml \
Expand All @@ -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=<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:

...
Expand All @@ -82,7 +86,6 @@ scrape_configs:
...
```


### Flags

Name | Description
Expand All @@ -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 <addr>,<password>,<alias>.
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>`.
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`. <br>
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
Expand All @@ -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.<br>
In addition, for every database there are metrics for total keys, expiring keys and the average TTL for keys in the database.<br>
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. <br>
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:<br>
<img width="800" alt="redis_exporter_screen" src="https://cloud.githubusercontent.com/assets/1222339/19412031/897549c6-92da-11e6-84a0-b091f9deb81d.png"><br>

Example [Grafana](http://grafana.org/) screenshots:\
<img width="800" alt="redis_exporter_screen" src="https://cloud.githubusercontent.com/assets/1222339/19412031/897549c6-92da-11e6-84a0-b091f9deb81d.png">\
<img width="800" alt="redis_exporter_screen_02" src="https://cloud.githubusercontent.com/assets/1222339/19412041/dee6d7bc-92da-11e6-84f8-610c025d6182.png">

Grafana dashboard is available on [grafana.net](https://grafana.net/dashboards/763) and/or [github.com](contrib/grafana_prometheus_redis_dashboard.json).
Expand All @@ -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.

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b148d9

Please sign in to comment.