/
kafka_exporter_run.sh
executable file
·63 lines (48 loc) · 1.63 KB
/
kafka_exporter_run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -e
set +x
# We don't need LOG_DIR because we write no log files, but setting it to a
# directory avoids trying to create it (and logging a permission denied error)
export LOG_DIR="$KAFKA_EXPORTER_HOME"
if [ -n "$KAFKA_EXPORTER_GROUP_REGEX" ]; then
# shellcheck disable=SC2027
groupregex="--group.filter=\""${KAFKA_EXPORTER_GROUP_REGEX}"\""
fi
if [ -n "$KAFKA_EXPORTER_TOPIC_REGEX" ]; then
# shellcheck disable=SC2027
topicregex="--topic.filter=\""${KAFKA_EXPORTER_TOPIC_REGEX}"\""
fi
if [ "$KAFKA_EXPORTER_ENABLE_SARAMA" = "true" ]; then
saramaenable="--log.enable-sarama"
fi
if [ -n "$KAFKA_EXPORTER_LOGGING" ]; then
loglevel="--verbosity=${KAFKA_EXPORTER_LOGGING}"
fi
# Combine all the certs in the cluster CA into one file
CA_CERTS=/tmp/cluster-ca.crt
for cert in /etc/kafka-exporter/cluster-ca-certs/*.crt; do
sed -z '$ s/\n$//' "$cert" >> "$CA_CERTS"
echo "" >> "$CA_CERTS"
done
# shellcheck disable=SC2027
version="--kafka.version=\""$KAFKA_EXPORTER_KAFKA_VERSION"\""
kafkaserver="--kafka.server="$KAFKA_EXPORTER_KAFKA_SERVER
listenaddress="--web.listen-address=:9404"
allgroups="--offset.show-all"
tls="--tls.enabled --tls.ca-file=$CA_CERTS --tls.cert-file=/etc/kafka-exporter/kafka-exporter-certs/kafka-exporter.crt --tls.key-file=/etc/kafka-exporter/kafka-exporter-certs/kafka-exporter.key"
# starting Kafka Exporter with final configuration
cat <<EOT > /tmp/run.sh
$KAFKA_EXPORTER_HOME/kafka_exporter \
$groupregex \
$topicregex \
$tls \
$kafkaserver \
$saramaenable \
$listenaddress \
$allgroups \
$loglevel \
$version
EOT
chmod +x /tmp/run.sh
set -x
exec /usr/bin/tini -w -e 143 -- /tmp/run.sh