Skip to content

Commit 3294ea4

Browse files
Merge pull request #354 from ohmydevops
Fix promethus null metrics problem
2 parents cfd64b2 + e8410bb commit 3294ea4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Log/Prometheus.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public function onPhpbuEnd(End $event)
102102
$this->write('# TYPE phpbu_backup_duration gauge' . PHP_EOL);
103103
foreach ($this->backupStats as $backupName => $backupStats) {
104104
$duration = $this->backupStats[$backupName]['timeEnd'] - $this->backupStats[$backupName]['timeStart'];
105+
if ($duration < 0) {
106+
$duration = 0;
107+
}
105108
$this->write('phpbu_backup_duration{name="' . $backupName . '"} ' . $duration . PHP_EOL);
106109
}
107110

@@ -124,7 +127,7 @@ public function onPhpbuEnd(End $event)
124127
foreach ($this->backupStats as $backupName => $backupStats) {
125128
$this->write(
126129
'phpbu_backup_size{name="' . $backupName . '"} ' .
127-
$this->backupStats[$backupName]['size'] .
130+
($this->backupStats[$backupName]['size'] ?? "0") .
128131
PHP_EOL
129132
);
130133
}

0 commit comments

Comments
 (0)