Skip to content

Commit

Permalink
added examples for the in memory storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Kruljac committed Mar 15, 2017
1 parent 153dcac commit 2f4f7c0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
11 changes: 6 additions & 5 deletions examples/flush_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

$adapter = $_GET['adapter'];

if ($adapter == 'redis') {
if ($adapter === 'redis') {
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');

$redisAdapter = new Prometheus\Storage\Redis(array('host' => REDIS_HOST));
$redisAdapter->flushRedis();
}

if ($adapter == 'apc') {
} elseif ($adapter === 'apc') {
$apcAdapter = new Prometheus\Storage\APC();
$apcAdapter->flushAPC();
}
} elseif ($adapter === 'in-memory') {
$inMemoryAdapter = new Prometheus\Storage\InMemory();
$inMemoryAdapter->flushMemory();
}
7 changes: 4 additions & 3 deletions examples/metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

$adapter = $_GET['adapter'];

if ($adapter == 'redis') {
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') {
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}
$registry = new CollectorRegistry($adapter);
$renderer = new RenderTextFormat();
Expand Down
13 changes: 12 additions & 1 deletion examples/pushgateway.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

use Prometheus\Storage\Redis;
use Prometheus\CollectorRegistry;

$adapter = new Prometheus\Storage\APC();
$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();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}

$registry = new CollectorRegistry($adapter);

$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
Expand Down
9 changes: 4 additions & 5 deletions examples/some_counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
use Prometheus\CollectorRegistry;
use Prometheus\Storage\Redis;

error_log('c='. $_GET['c']);

$adapter = $_GET['adapter'];

if ($adapter == 'redis') {
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') {
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}
$registry = new CollectorRegistry($adapter);

Expand Down
7 changes: 4 additions & 3 deletions examples/some_gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

$adapter = $_GET['adapter'];

if ($adapter == 'redis') {
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') {
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}
$registry = new CollectorRegistry($adapter);

Expand Down
7 changes: 4 additions & 3 deletions examples/some_histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

$adapter = $_GET['adapter'];

if ($adapter == 'redis') {
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') {
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemory();
}
$registry = new CollectorRegistry($adapter);

Expand Down

0 comments on commit 2f4f7c0

Please sign in to comment.