diff --git a/src/Prometheus/CollectorRegistry.php b/src/Prometheus/CollectorRegistry.php index 9ff18e3..fc604b4 100644 --- a/src/Prometheus/CollectorRegistry.php +++ b/src/Prometheus/CollectorRegistry.php @@ -49,6 +49,14 @@ public static function getDefault() return self::$defaultRegistry; } + /** + * @return boolean + */ + public function initialized() + { + return $this->storageAdapter->initialized(); + } + /** * @return MetricFamilySamples[] */ diff --git a/src/Prometheus/Storage/APC.php b/src/Prometheus/Storage/APC.php index b5a9c4b..c317f87 100644 --- a/src/Prometheus/Storage/APC.php +++ b/src/Prometheus/Storage/APC.php @@ -10,6 +10,14 @@ class APC implements Adapter { const PROMETHEUS_PREFIX = 'prom'; + /** + * @return boolean + */ + public function initialized() + { + return !apc_add(self::PROMETHEUS_PREFIX . ":initialized", true); + } + /** * @return MetricFamilySamples[] */ diff --git a/src/Prometheus/Storage/Adapter.php b/src/Prometheus/Storage/Adapter.php index e280f13..03818a5 100644 --- a/src/Prometheus/Storage/Adapter.php +++ b/src/Prometheus/Storage/Adapter.php @@ -11,6 +11,11 @@ interface Adapter const COMMAND_INCREMENT_FLOAT = 2; const COMMAND_SET = 3; + /** + * @return boolean + */ + public function initialized(); + /** * @return MetricFamilySamples[] */ diff --git a/src/Prometheus/Storage/InMemory.php b/src/Prometheus/Storage/InMemory.php index 37c24b1..7972381 100644 --- a/src/Prometheus/Storage/InMemory.php +++ b/src/Prometheus/Storage/InMemory.php @@ -11,6 +11,19 @@ class InMemory implements Adapter private $counters = []; private $gauges = []; private $histograms = []; + private $initialized = false; + + /** + * @return boolean + */ + public function initialized() + { + if(!$this->initialized){ + $this->initialized = true; + return false; + } + return $this->initialized; + } /** * @return MetricFamilySamples[] @@ -28,6 +41,7 @@ public function flushMemory() $this->counters = []; $this->gauges = []; $this->histograms = []; + $this->initialized = false; } private function collectHistograms() diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index f38391b..459d08d 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -19,6 +19,11 @@ class Redis implements Adapter private $options; private $redis; + public function initialized() + { + return $this->redis->getSet(self::$prefix . 'INITIALIZED', 1); + } + public function __construct(array $options = array()) { // with php 5.3 we cannot initialize the options directly on the field definition