From 522b3bbce2700e70d429737854e0c48d6bbae540 Mon Sep 17 00:00:00 2001 From: Dirk Heilig Date: Thu, 29 Aug 2024 10:40:20 +0200 Subject: [PATCH] add json output --- mqtt2prom/run | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mqtt2prom/run b/mqtt2prom/run index 2f8e02a..d07a798 100755 --- a/mqtt2prom/run +++ b/mqtt2prom/run @@ -187,7 +187,7 @@ function output(): void filter(); global $data, $stats, $globalCounter; $t = time(); - + $json = []; $prom = ""; $prom .= "# service started at : " . @@ -261,6 +261,11 @@ function output(): void ); } } + $json[] = [ + "name" => $entry["name"], + "labels" => $entry["labels"] ?? [], + "value" => $entry["value"], + ]; $labels = implode(", ", $labels); if ($labels != "") { $labels = "{" . $labels . "}"; @@ -269,6 +274,7 @@ function output(): void $prom .= $entry["name"] . $labels . " " . $entry["value"] . "\n"; } file_put_contents("/www/metrics/new.prom", $prom); + file_put_contents("/www/metrics/json", $json); rename("/www/metrics/new.prom", "/www/metrics/index.prom"); // return $prom; }