/** * @test */ public function pushGatewayShouldWork() { $adapter = new APC(); $registry = new CollectorRegistry($adapter); $counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']); $counter->incBy(6, ['blue']); $pushGateway = new PushGateway('pushgateway:9091'); $pushGateway->push($registry, 'my_job', array('instance' => 'foo')); $httpClient = new Client(); $metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents(); $this->assertContains('# HELP test_some_counter it increases # TYPE test_some_counter counter test_some_counter{instance="foo",job="my_job",type="blue"} 6', $metrics); $pushGateway->delete('my_job', array('instance' => 'foo')); $httpClient = new Client(); $metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents(); $this->assertNotContains('# HELP test_some_counter it increases # TYPE test_some_counter counter test_some_counter{instance="foo",job="my_job",type="blue"} 6', $metrics); }
<?php require __DIR__ . '/../vendor/autoload.php'; use Prometheus\CollectorRegistry; use Prometheus\Storage\Redis; error_log('c=' . $_GET['c']); $adapter = $_GET['adapter']; if ($adapter == 'redis') { Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1')); $adapter = new Prometheus\Storage\Redis(); } if ($adapter == 'apc') { $adapter = new Prometheus\Storage\APC(); } $registry = new CollectorRegistry($adapter); $counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']); $counter->incBy($_GET['c'], ['blue']); echo "OK\n";
/** * @test * @expectedException \Prometheus\Exception\MetricsRegistrationException */ public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels() { $registry = new CollectorRegistry($this->adapter); $registry->registerCounter('foo', 'metric', 'help', array("foo", "bar")); $registry->registerCounter('foo', 'metric', 'help', array("spam", "eggs")); }