diff --git a/mqtt2prom/Dockerfile b/mqtt2prom/Dockerfile index f8964e9..44900e1 100644 --- a/mqtt2prom/Dockerfile +++ b/mqtt2prom/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:12 +FROM debian:12 as prepare RUN apt-get update && apt-get upgrade -y RUN apt-get install -y php-dev php-cli php-pear php-mbstring php-curl git build-essential libmosquitto-dev libmosquitto-dev php-sqlite3 WORKDIR /tmp @@ -11,4 +11,12 @@ RUN make install RUN echo "extension=mosquitto.so" > /etc/php/8.2/cli/php.ini ADD run /usr/local/bin/entrypoint RUN chmod +x /usr/local/bin/entrypoint +FROM prepare as make_git_id +WORKDIR /tmp/repo +ADD .git /tmp/repo/.git +RUN git rev-parse HEAD > /tmp/git_id +FROM prepare as runner +ENV GIT_ID=unknown +COPY --from=make_git_id /tmp/git_id /var/lib/git_id + CMD ["/usr/local/bin/entrypoint"] diff --git a/mqtt2prom/run b/mqtt2prom/run index 1d479e8..8f61d95 100755 --- a/mqtt2prom/run +++ b/mqtt2prom/run @@ -14,13 +14,16 @@ pcntl_signal(SIGTERM, "endit"); pcntl_signal(SIGHUP, "endit"); $mqttPort = getEnvWithDefaultInt("MQTT_PORT", 1883); - $mqttUser = getEnvWithDefaultStr("MQTT_USER", ""); $mqttPass = getEnvWithDefaultStr("MQTT_PASS", ""); $mqttClientId = getEnvWithDefaultStr("MQTT_CLIENT_ID", "mqtt2prometheus"); $mqttTopic = getEnvWithDefaultStr("MQTT_TOPIC", "prometheus"); $qos = getEnvWithDefaultInt("MQTT_QOS", 2); $ignoreRetained = getEnvWithDefaultInt("IGNORE_RETAINED", 1) ? 1 : 0; +$gitId="Unknown"; +if (is_file("/var/lib/git_id")) { + $gitId = trim(file_get_contents("/var/lib/git_id")); +} $mqtt = new Mosquitto\Client($mqttClientId); @@ -185,10 +188,11 @@ function precheck(Message $message): bool function output(): void { filter(); - global $data, $stats, $globalCounter; + global $data, $stats, $globalCounter,$gitId; $t = time(); $prom = ""; + $prom .= "# from git-id : $gitId\n"; $prom .= "# service started at : " . STARTED .