From 80a3dcc9e97d98ca31fa4b2aabb9d54bb62bf7d4 Mon Sep 17 00:00:00 2001 From: Oleksii Grudev Date: Fri, 20 Sep 2019 16:42:22 +0300 Subject: [PATCH] [mysql-exporter] Use flags depending on version This patch adds functionality to check current version of mysql_exporter binary and to modify configuration flags depending on version Change-Id: Ic1f42fbf5c99203d6e2fca4fc345632b64e5dc0a --- .../prometheus/bin/_mysqld-exporter.sh.tpl | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/mariadb/templates/monitoring/prometheus/bin/_mysqld-exporter.sh.tpl b/mariadb/templates/monitoring/prometheus/bin/_mysqld-exporter.sh.tpl index b639c5bdc..fa3986d68 100644 --- a/mariadb/templates/monitoring/prometheus/bin/_mysqld-exporter.sh.tpl +++ b/mariadb/templates/monitoring/prometheus/bin/_mysqld-exporter.sh.tpl @@ -18,7 +18,42 @@ limitations under the License. set -ex +compareVersions() { +echo $1 $2 | \ +awk '{ split($1, a, "."); + split($2, b, "."); + res = -1; + for (i = 1; i <= 3; i++){ + if (a[i] < b[i]) { + res =-1; + break; + } else if (a[i] > b[i]) { + res = 1; + break; + } else if (a[i] == b[i]) { + if (i == 3) { + res = 0; + break; + } else { + continue; + } + } + } + print res; + }' +} + +MYSQL_EXPORTER_VER=`/bin/mysqld_exporter --version 2>&1 | grep "mysqld_exporter" | awk '{print $3}'` + +#in versions greater than 0.10.0 different configuration flags are used: +#https://github.com/prometheus/mysqld_exporter/commit/66c41ac7eb90a74518a6ecf6c6bb06464eb68db8 +compverResult=`compareVersions "${MYSQL_EXPORTER_VER}" "0.10.0"` +CONFIG_FLAG_PREFIX='-' +if [ ${compverResult} -gt 0 ]; then + CONFIG_FLAG_PREFIX='--' +fi + exec /bin/mysqld_exporter \ - -config.my-cnf=/etc/mysql/mysql_user.cnf \ - -web.listen-address="${POD_IP}:${LISTEN_PORT}" \ - -web.telemetry-path="$TELEMETRY_PATH" + ${CONFIG_FLAG_PREFIX}config.my-cnf=/etc/mysql/mysql_user.cnf \ + ${CONFIG_FLAG_PREFIX}web.listen-address="${POD_IP}:${LISTEN_PORT}" \ + ${CONFIG_FLAG_PREFIX}web.telemetry-path="$TELEMETRY_PATH"