Skip to content

Commit

Permalink
Exporter Docker configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
aforge committed Mar 19, 2020
1 parent 7905bf5 commit ccb57e1
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
30 changes: 29 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ See [instructions](../chatbot/python/).

The chatbot password is generated only when the database is initialized or reset. It's saved to `/botdata` directory in the container. If you want to keep the data available between container changes, such as image upgrades, make sure the `/botdata` is a mounted volume (i.e. you always launch the container with `--volume botdata:/botdata` option).


## Supported environment variables

You can specify the following environment variables when issuing `docker run` command:
Expand Down Expand Up @@ -172,3 +171,32 @@ A convenient way to generate a desired number of random bytes and base64-encode
```
$ openssl rand -base64 <desired length>
```

## Metrics Exporter

See [monitoring/exporter/README](../../monitoring/exporter/README.md) for information on the Exporter.
Container is also available as a part of the Tinode docker distribution: `tinode/exporter`.
Run it with

```
$ docker run -p 6222:6222 -d --name tinode-exporter --network tinode-net \
--env SERVE_FOR=<prometheus|influxdb> \
--env TINODE_ADDR=<tinode metrics endpoint> \
--env LISTEN_AT=":6222" \
... <monitoring service specific vars> \
tinode/exporter:latest
```

Available variables:
| Variable | Type | Default | Function |
| --- | --- | --- | --- |
| `SERVE_FOR` | string | `` | Either `prometheus` or `influxdb` |
| `TINODE_ADDR` | string | `http://localhost/stats/expvar/` | Tinode metrics path |
| `LISTEN_AT` | string | `:6222` | Exporter web server host and port |
| `INFLUXDB_VERSION` | string | `1.7` | InfluxDB version (`1.7` or `2.0`) |
| `INFLUXDB_ORGANIZATION` | string | `org` | InfluxDB organization |
| `INFLUXDB_PUSH_INTERVAL` | int | `60` | Exporter's metrics push interval in seconds |
| `INFLUXDB_PUSH_ADDRESS` | string | `https://mon.tinode.co/intake` | InfluxDB backend url |
| `INFLUXDB_AUTH_TOKEN` | string | `Your-token` | InfluxDB auth token |
| `PROM_NAMESPACE` | string | `tinode` | Prometheus namespace |
| `PROM_METRICS_PATH` | string | `/metrics` | Exporter webserver path that Prometheus server scrapes |
37 changes: 37 additions & 0 deletions docker/exporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM alpine:latest

ARG VERSION=0.16.4
ENV VERSION=$VERSION

ENV SERVE_FOR=""

ENV TINODE_ADDR=http://localhost/stats/expvar/
ENV INSTANCE="exporter-instance"
ENV LISTEN_AT=":6222"

ENV INFLUXDB_VERSION=1.7
ENV INFLUXDB_ORGANIZATION="org"
ENV INFLUXDB_PUSH_INTERVAL=60
ENV INFLUXDB_PUSH_ADDRESS=http://localhost:6222/write
ENV INFLUXDB_AUTH_TOKEN="Your-token"

ENV PROM_NAMESPACE="tinode"
ENV PROM_METRICS_PATH="/metrics"

LABEL maintainer="Tinode Team <info@tinode.co>"
LABEL name="TinodeMetricExporter"
LABEL version=$VERSION

WORKDIR /opt/tinode

RUN apk add --no-cache bash

# Fetch exporter build from Github.
ADD https://github.com/tinode/chat/releases/download/v$VERSION/exporter.linux-amd64 ./exporter

COPY entrypoint.sh .
RUN chmod +x exporter && chmod +x entrypoint.sh

ENTRYPOINT ./entrypoint.sh

EXPOSE 6222
57 changes: 57 additions & 0 deletions docker/exporter/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Check if environment variables (provided as argument list) are set.
function check_vars() {
local varnames=( "$@" )
for varname in "${varnames[@]}"
do
eval value=\$${varname}
if [ -z "$value" ] ; then
echo "$varname env var must be specified."
exit 1
fi
done
}

echo "hosts: files dns" > /etc/nsswitch.conf

# Required env vars.
common_vars=( TINODE_ADDR INSTANCE LISTEN_AT SERVE_FOR )

influx_varnames=( INFLUXDB_VERSION INFLUXDB_ORGANIZATION INFLUXDB_PUSH_INTERVAL \
INFLUXDB_PUSH_ADDRESS INFLUXDB_AUTH_TOKEN )

prometheus_varnames=( PROM_NAMESPACE PROM_METRICS_PATH )

check_vars "${common_vars[@]}"

# Common arguments.
args=("--tinode_addr=${TINODE_ADDR}" "--instance=${INSTANCE}" "--listen_at=${LISTEN_AT}" "--serve_for=${SERVE_FOR}")

# Platform-specific arguments.
case "$SERVE_FOR" in
"prometheus")
check_vars "${prometheus_varnames[@]}"
args+=("--prom_namespace=${PROM_NAMESPACE}" "--prom_metrics_path=${PROM_METRICS_PATH}")
if [ ! -z "$PROM_TIMEOUT" ]; then
args+=("--prom_timeout=${PROM_TIMEOUT}")
fi
;;
"influxdb")
check_vars "${influxdb_varnames[@]}"
args+=("--influx_db_version=${INFLUXDB_VERSION}" \
"--influx_organization=${INFLUXDB_ORGANIZATION}" \
"--influx_push_interval=${INFLUXDB_PUSH_INTERVAL}" \
"--influx_push_addr=${INFLUXDB_PUSH_ADDRESS}" \
"--influx_auth_token=${INFLUXDB_AUTH_TOKEN}")
if [ ! -z "$INFLUXDB_BUCKET" ]; then
args+=("--influx_bucket=${INFLUXDB_BUCKET}")
fi
;;
*)
echo "\$SERVE_FOR must be set to either 'prometheus' or 'influxdb'"
exit 1
;;
esac

./exporter "${args[@]}"

0 comments on commit ccb57e1

Please sign in to comment.