forked from tinode/chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aforge
committed
Mar 19, 2020
1 parent
7905bf5
commit ccb57e1
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[@]}" |