diff --git a/src/Metrics/Exporter/PrometheusExporter.php b/src/Metrics/Exporter/PrometheusExporter.php index 4bdc437..df4c1fa 100644 --- a/src/Metrics/Exporter/PrometheusExporter.php +++ b/src/Metrics/Exporter/PrometheusExporter.php @@ -10,6 +10,11 @@ class PrometheusExporter extends Exporter { + public function toFile(string $path, string $prefix = '', array $labels = []): void + { + file_put_contents($path, $this->toString($prefix, $labels)); + } + public function toString(string $prefix = '', array $labels = []): string { $info = []; diff --git a/src/Metrics/Importer/PrometheusImporter.php b/src/Metrics/Importer/PrometheusImporter.php index 0c1fdfa..8a5a52e 100644 --- a/src/Metrics/Importer/PrometheusImporter.php +++ b/src/Metrics/Importer/PrometheusImporter.php @@ -12,6 +12,10 @@ class PrometheusImporter public function __construct(private Registry $registry, private Info $info) { } + public function fromFile(string $path, string $prefix = ''): self + { + return $this->fromString(file_get_contents($path), $prefix); + } public function fromString(string $string, string $prefix = ''): self { diff --git a/tests/Metrics/ImporterTest.php b/tests/Metrics/ImporterTest.php index 53af9f3..e48d3d2 100644 --- a/tests/Metrics/ImporterTest.php +++ b/tests/Metrics/ImporterTest.php @@ -33,7 +33,12 @@ public function test(): void $registry2 = new Registry(); $info2 = new Info(); $importer = new PrometheusImporter($registry2, $info2); - $importer->fromString($exporter->toString('tester_'), 'tester_'); + $filename = '/tmp/' . bin2hex(random_bytes(32)); + + $exporter->toFile($filename, 'tester_'); + $importer->fromFile($filename, 'tester_'); + + unlink($filename); $keys = [ ['memory_usage', []],