From 1c356660b7b6c5f23a6ab3d29fac25c91215dcac Mon Sep 17 00:00:00 2001 From: Dirk Heilig Date: Thu, 15 Aug 2024 18:55:28 +0200 Subject: [PATCH] add globals counter --- mqtt2prom/run | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mqtt2prom/run b/mqtt2prom/run index dff5ad7..ba6523c 100755 --- a/mqtt2prom/run +++ b/mqtt2prom/run @@ -61,7 +61,9 @@ $stats = [ "metrics" => [], ]; $news = true; -$mqtt->onMessage(function ($message) use (&$data, &$stats, &$news) { +$globalCounter=0; +$mqtt->onMessage(function ($message) use (&$data, &$stats, &$news,&$globalCounter) { + $globalCounter++; $stats["messages"][] = time(); if (!precheck($message)) { $stats["errors"][] = time(); @@ -80,6 +82,7 @@ $mqtt->subscribe($mqttTopic, $qos); echo "Subscribed\n"; $timer = 0; + echo "Started listening for incoming messages\n will wait 60 seconds before starting to export data\n"; $realStart = time() + 15; echo "waiting till " . @@ -166,7 +169,7 @@ function precheck(Message $message): bool function output(): void { filter(); - global $data, $stats; + global $data, $stats,$globalCounter; $t = time(); $prom = ""; @@ -216,7 +219,8 @@ function output(): void $prom .= "# $fkey in the last $fname: $count\n"; } } - + $prom .= "# \n"; + $prom .= "# global counter: $globalCounter\n"; $filteredData=[]; foreach($data as $entry){