From 5d8dc93e745c235c9c25eb393b74f87b142e1465 Mon Sep 17 00:00:00 2001 From: gdm-maha <159897970+gdm-maha@users.noreply.github.com> Date: Tue, 5 May 2026 08:30:16 +0200 Subject: [PATCH 1/4] change calculatesteps to take into account checkinterval and fallback to 1s fallback might have to change later --- .../Perfdatagraphsprometheus/Client/Prometheus.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/Perfdatagraphsprometheus/Client/Prometheus.php b/library/Perfdatagraphsprometheus/Client/Prometheus.php index 034b85f..6ba3475 100644 --- a/library/Perfdatagraphsprometheus/Client/Prometheus.php +++ b/library/Perfdatagraphsprometheus/Client/Prometheus.php @@ -115,14 +115,19 @@ protected function getAuth(): array } /** - * calculateSteps uses the start and end timestamps to calculate the step parameter + * calculateSteps uses the start and end timestamps to calculate the step parameter. + * + * The step is never smaller than $checkInterval to avoid repeated identical + * values caused by Prometheus gap-filling within the lookback window. */ - protected function calculateSteps(int $start, int $end, int $maxDataPoints): string + protected function calculateSteps(int $start, int $end, int $maxDataPoints, int $checkInterval = 0): string { $totalSeconds = $end - $start; $stepSeconds = $totalSeconds / $maxDataPoints; - // NOTE: This means we can never get a resolution below 60s, even if Icinga2 would send data every 15s - $stepSeconds = max($stepSeconds, 60); + // Use the check interval as the minimum step so we don't over-sample. + // Fall back to 1s when no check interval is available. + $minStep = $checkInterval > 0 ? $checkInterval : 1; + $stepSeconds = max($stepSeconds, $minStep); return (int)round($stepSeconds) . 's'; } From 42bba2ed37c9f7a1b62e4de3854676228529f023 Mon Sep 17 00:00:00 2001 From: gdm-maha <159897970+gdm-maha@users.noreply.github.com> Date: Tue, 5 May 2026 08:34:52 +0200 Subject: [PATCH 2/4] add get check interval --- .../ProvidedHook/Perfdatagraphs/PerfdataSource.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/Perfdatagraphsprometheus/ProvidedHook/Perfdatagraphs/PerfdataSource.php b/library/Perfdatagraphsprometheus/ProvidedHook/Perfdatagraphs/PerfdataSource.php index 45a1fa3..686e247 100644 --- a/library/Perfdatagraphsprometheus/ProvidedHook/Perfdatagraphs/PerfdataSource.php +++ b/library/Perfdatagraphsprometheus/ProvidedHook/Perfdatagraphs/PerfdataSource.php @@ -45,7 +45,8 @@ public function fetchData(PerfdataRequest $req): PerfdataResponse $req->getDuration(), $req->isHostCheck(), $req->getIncludeMetrics(), - $req->getExcludeMetrics() + $req->getExcludeMetrics(), + $req->getCheckInterval() ); } catch (ConnectException $e) { $perfdataresponse->addError($e->getMessage()); From e7ca9e6215b624d0eef3e9ffb337bf7788fae7fe Mon Sep 17 00:00:00 2001 From: gdm-maha <159897970+gdm-maha@users.noreply.github.com> Date: Tue, 5 May 2026 08:36:26 +0200 Subject: [PATCH 3/4] cast values to float, fix threshold lookup, use check_interval as minimum step --- .../Client/Transformer.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/Perfdatagraphsprometheus/Client/Transformer.php b/library/Perfdatagraphsprometheus/Client/Transformer.php index 45933b0..e003e8f 100644 --- a/library/Perfdatagraphsprometheus/Client/Transformer.php +++ b/library/Perfdatagraphsprometheus/Client/Transformer.php @@ -46,8 +46,8 @@ protected static function preparePerfdataResponse(array $results, PerfdataRespon $timestamps = []; foreach ($result['values'] as $point) { - $timestamps[] = $point[0]; - $values[] = $point[1]; + $timestamps[] = (int) $point[0]; + $values[] = is_numeric($point[1]) ? (float) $point[1] : null; } $valuesSeries = new PerfdataSeries('value', $values); @@ -95,11 +95,15 @@ protected static function appendThresholds(array $results, PerfdataResponse $pfr } $ts = $dataset->getTimestamps(); - $valueMap = array_column($result['values'], 1, 0); - // Get the matching threshold value for the given timestamp otherwise use null + // Build a map of timestamp (int) => float value for fast lookup. + $valueMap = []; + foreach ($result['values'] as $point) { + $valueMap[(int) $point[0]] = is_numeric($point[1]) ? (float) $point[1] : null; + } + // Align threshold values to the stored timestamps; use null for gaps. $thresholds = []; foreach ($ts as $timestamp) { - $thresholds[] = $valueMap[$timestamp] ?? null; + $thresholds[] = $valueMap[(int) $timestamp] ?? null; } $thresholdSeries = new PerfdataSeries($thresholdType, $thresholds); From 58e58fa0ebb08b8b5d0eb87b61bbf2748c60cca3 Mon Sep 17 00:00:00 2001 From: gdm-maha <159897970+gdm-maha@users.noreply.github.com> Date: Tue, 5 May 2026 08:54:48 +0200 Subject: [PATCH 4/4] fix check interval --- library/Perfdatagraphsprometheus/Client/Prometheus.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/Perfdatagraphsprometheus/Client/Prometheus.php b/library/Perfdatagraphsprometheus/Client/Prometheus.php index 6ba3475..57bc2d4 100644 --- a/library/Perfdatagraphsprometheus/Client/Prometheus.php +++ b/library/Perfdatagraphsprometheus/Client/Prometheus.php @@ -139,7 +139,8 @@ public function getMetrics( string $from, bool $isHostCheck, array $includeMetrics, - array $excludeMetrics + array $excludeMetrics, + int $checkInterval = 0 ): Response { $endTime = new DateTimeImmutable(); $startTime = $endTime->sub(new DateInterval($from)); @@ -150,7 +151,7 @@ public function getMetrics( $start = $startTime->getTimestamp(); $end = $endTime->getTimestamp(); - $step = $this->calculateSteps($start, $end, $this->maxDataPoints); + $step = $this->calculateSteps($start, $end, $this->maxDataPoints, $checkInterval); $query = [ 'query' => [