forked from Jimdo/prometheus_client_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build up a test scenario with guzzle async
- Loading branch information
1 parent
f81f264
commit 9c2d970
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$redisAdapter = new \Prometheus\RedisAdapter('localhost'); | ||
$redisAdapter->flushRedis(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
use Prometheus\RedisAdapter; | ||
use Prometheus\Registry; | ||
|
||
$redisAdapter = new RedisAdapter('localhost'); | ||
$registry = new Registry($redisAdapter); | ||
$result = $registry->toText(); | ||
|
||
header('Content-type: text/plain; version=0.0.4'); | ||
echo $result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$redisAdapter = new \Prometheus\RedisAdapter('localhost'); | ||
$registry = new \Prometheus\Registry($redisAdapter); | ||
$counter = $registry->registerGauge('test', 'some_gauge', 'it sets', ['type']); | ||
$counter->set(234, ['blue']); | ||
$counter->set(123, ['red']); | ||
|
||
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']); | ||
$counter->increaseBy(1, ['blue']); | ||
$counter->increaseBy(2, ['red']); | ||
|
||
$histogram = $registry->registerHistogram('test', 'some_histogram', 'it observes', ['type'], [1, 2, 3.5, 4]); | ||
$histogram->observe(2.5, ['blue']); | ||
|
||
$registry->flush(); | ||
|
||
echo "OK\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace Test; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Promise; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class BlackBoxTest extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function countersShouldIncrementAtomically() | ||
{ | ||
$client = new Client(['base_uri' => 'http://localhost:8080/']); | ||
$client->get('/examples/flush_redis.php'); | ||
|
||
$start = microtime(true); | ||
$promises = [ | ||
$client->getAsync('/examples/some_request_uri.php?0'), | ||
$client->getAsync('/examples/some_request_uri.php?1'), | ||
$client->getAsync('/examples/some_request_uri.php?2'), | ||
$client->getAsync('/examples/some_request_uri.php?3'), | ||
$client->getAsync('/examples/some_request_uri.php?4'), | ||
$client->getAsync('/examples/some_request_uri.php?5'), | ||
$client->getAsync('/examples/some_request_uri.php?6'), | ||
$client->getAsync('/examples/some_request_uri.php?7'), | ||
$client->getAsync('/examples/some_request_uri.php?8'), | ||
$client->getAsync('/examples/some_request_uri.php?9'), | ||
]; | ||
|
||
Promise\settle($promises)->wait(); | ||
$end = microtime(true); | ||
echo "time: " . ($end - $start) . "\n"; | ||
|
||
$metricsResult = $client->get('/examples/metrics.php'); | ||
var_dump((string)$metricsResult->getBody()); | ||
} | ||
} |