Skip to content
Permalink
Browse files

Move under Enalean\ namespace to avoid conflicts with Jimdo/prometheu…

…s_client_php
  • Loading branch information...
LeSuisse committed Jun 9, 2019
1 parent 76721a6 commit 17a9d827f5a1f29c313e2a4f8da2e9a67a39bf4c
Showing with 362 additions and 363 deletions.
  1. +31 −29 README.md
  2. +4 −3 composer.json
  3. +3 −3 examples/flush_adapter.php
  4. +6 −6 examples/metrics.php
  5. +8 −8 examples/pushgateway.php
  6. +7 −7 examples/some_counter.php
  7. +7 −7 examples/some_gauge.php
  8. +7 −7 examples/some_histogram.php
  9. +1 −1 infection.json.dist
  10. +2 −6 phpcs.xml.dist
  11. +1 −1 phpunit.xml.dist
  12. +4 −4 src/{Prometheus → }/Counter.php
  13. +1 −1 src/{Prometheus → }/Exception/MetricNotFoundException.php
  14. +1 −1 src/{Prometheus → }/Exception/MetricsRegistrationException.php
  15. +4 −4 src/{Prometheus → }/Gauge.php
  16. +4 −4 src/{Prometheus → }/Histogram.php
  17. +3 −3 src/{Prometheus → }/Metric.php
  18. +1 −1 src/{Prometheus → }/MetricFamilySamples.php
  19. +4 −4 src/{Prometheus → }/PushGateway/PSR18Pusher.php
  20. +1 −1 src/{Prometheus → }/PushGateway/PSR18UnexpectedPushGatewayResponse.php
  21. +2 −2 src/{Prometheus → }/PushGateway/Pusher.php
  22. +1 −1 src/{Prometheus → }/PushGateway/UnexpectedPushGatewayResponse.php
  23. +2 −2 src/{Prometheus → }/Registry/Collector.php
  24. +14 −14 src/{Prometheus → }/Registry/CollectorRegistry.php
  25. +9 −9 src/{Prometheus → }/Registry/Registry.php
  26. +2 −2 src/{Prometheus → }/Renderer/MetricsRenderer.php
  27. +3 −3 src/{Prometheus → }/Renderer/RenderTextFormat.php
  28. +1 −1 src/{Prometheus → }/Sample.php
  29. +7 −7 src/{Prometheus → }/Storage/APCUStore.php
  30. +3 −3 src/{Prometheus → }/Storage/CounterStorage.php
  31. +1 −1 src/{Prometheus → }/Storage/FlushableStorage.php
  32. +3 −3 src/{Prometheus → }/Storage/GaugeStorage.php
  33. +3 −3 src/{Prometheus → }/Storage/HistogramStorage.php
  34. +8 −8 src/{Prometheus → }/Storage/InMemoryStore.php
  35. +4 −4 src/{Prometheus → }/Storage/NullStore.php
  36. +6 −6 src/{Prometheus → }/Storage/RedisStore.php
  37. +2 −2 src/{Prometheus → }/Storage/Store.php
  38. +1 −1 src/{Prometheus → }/Value/HistogramLabelNames.php
  39. +1 −1 src/{Prometheus → }/Value/LabelNames.php
  40. +1 −1 src/{Prometheus → }/Value/MetricLabelNames.php
  41. +1 −1 src/{Prometheus → }/Value/MetricName.php
  42. +1 −1 tests/functionnal/BlackBoxTest.php
  43. +3 −3 tests/functionnal/PushGateway/BackboxPusherPSR18Test.php
  44. +6 −6 tests/functionnal/PushGateway/BlackBoxPushGatewayTest.php
  45. +7 −7 tests/unit/{Prometheus → }/CounterTest.php
  46. +7 −7 tests/unit/{Prometheus → }/GaugeTest.php
  47. +7 −7 tests/unit/{Prometheus → }/HistogramTest.php
  48. +4 −4 tests/unit/{Prometheus → }/MetricFamilySamplesTest.php
  49. +0 −17 tests/unit/Prometheus/Storage/APCU/CollectorRegistryTest.php
  50. +0 −16 tests/unit/Prometheus/Storage/InMemory/CollectorRegistryTest.php
  51. +6 −6 tests/unit/{Prometheus → }/PushGateway/PSR18PusherTest.php
  52. +3 −3 tests/unit/{Prometheus → }/PushGateway/PSR18UnexpectedPushGatewayResponseTest.php
  53. +6 −6 tests/unit/{Prometheus → }/Renderer/RenderTextFormatTest.php
  54. +3 −3 tests/unit/{Prometheus → }/SampleTest.php
  55. +17 −0 tests/unit/Storage/APCU/CollectorRegistryTest.php
  56. +2 −2 tests/unit/{Prometheus → }/Storage/APCU/ConfigureAPCUStorage.php
  57. +3 −3 tests/unit/{Prometheus → }/Storage/APCU/CounterTest.php
  58. +3 −3 tests/unit/{Prometheus → }/Storage/APCU/GaugeTest.php
  59. +3 −3 tests/unit/{Prometheus → }/Storage/APCU/HistogramTest.php
  60. +14 −14 tests/unit/{Prometheus → }/Storage/CollectorRegistryBaseTest.php
  61. +10 −10 tests/unit/{Prometheus → }/Storage/CounterBaseTest.php
  62. +9 −9 tests/unit/{Prometheus → }/Storage/GaugeBaseTest.php
  63. +9 −9 tests/unit/{Prometheus → }/Storage/HistogramBaseTest.php
  64. +16 −0 tests/unit/Storage/InMemory/CollectorRegistryTest.php
  65. +2 −2 tests/unit/{Prometheus → }/Storage/InMemory/ConfigureInMemoryStorage.php
  66. +3 −3 tests/unit/{Prometheus → }/Storage/InMemory/CounterTest.php
  67. +3 −3 tests/unit/{Prometheus → }/Storage/InMemory/GaugeTest.php
  68. +3 −3 tests/unit/{Prometheus → }/Storage/InMemory/HistogramTest.php
  69. +7 −7 tests/unit/{Prometheus → }/Storage/Null/NullStoreTest.php
  70. +10 −10 tests/unit/{Prometheus → }/Storage/Redis/CollectorRegistryTest.php
  71. +2 −2 tests/unit/{Prometheus → }/Storage/Redis/ConfigureRedisStorage.php
  72. +3 −3 tests/unit/{Prometheus → }/Storage/Redis/CounterTest.php
  73. +3 −3 tests/unit/{Prometheus → }/Storage/Redis/GaugeTest.php
  74. +3 −3 tests/unit/{Prometheus → }/Storage/Redis/HistogramTest.php
  75. +3 −3 tests/unit/{Prometheus → }/Value/HistogramLabelNamesTest.php
  76. +3 −3 tests/unit/{Prometheus → }/Value/MetricLabelNamesTest.php
  77. +3 −3 tests/unit/{Prometheus → }/Value/MetricNameTest.php
@@ -4,8 +4,6 @@
[![codecov](https://codecov.io/gh/Enalean/php-prometheus-client/branch/master/graph/badge.svg)](https://codecov.io/gh/Enalean/php-prometheus-client)
[![Type Coverage](https://shepherd.dev/github/enalean/php-prometheus-client/coverage.svg)](https://shepherd.dev/github/enalean/php-prometheus-client)

:warning: This a WIP fork of [Jimdo/prometheus_client_php](https://github.com/Jimdo/prometheus_client_php).

This library uses Redis or APCu to do the client side aggregation.
If using Redis, we recommend to run a local Redis instance next to your PHP workers.

@@ -20,63 +18,63 @@ While the first needs a separate binary running, the second just needs the [APC]

A simple counter:
```php
$storage = new \Prometheus\Storage\InMemoryStore();
(new \Prometheus\Registry\CollectorRegistry($storage))
->getOrRegisterCounter(\Prometheus\Value\MetricName::fromName('some_quick_counter'), 'just a quick measurement')
$storage = new \Enalean\Prometheus\Storage\InMemoryStore();
(new \Enalean\Prometheus\Registry\CollectorRegistry($storage))
->getOrRegisterCounter(\Enalean\Prometheus\Value\MetricName::fromName('some_quick_counter'), 'just a quick measurement')
->inc();
```

Write some enhanced metrics:
```php
$storage = new \Prometheus\Storage\InMemoryStore();
$registry = new \Prometheus\Registry\CollectorRegistry($storage);
$storage = new \Enalean\Prometheus\Storage\InMemoryStore();
$registry = new \Enalean\Prometheus\Registry\CollectorRegistry($storage);
$counter = $registry->getOrRegisterCounter(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
'it increases',
\Prometheus\Value\MetricLabelNames::fromNames('type')
\Enalean\Prometheus\Value\MetricLabelNames::fromNames('type')
);
$counter->incBy(3, 'blue');
$gauge = $registry->getOrRegisterGauge(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_gauge'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_gauge'),
'it sets',
\Prometheus\Value\MetricLabelNames::fromNames('type')
\Enalean\Prometheus\Value\MetricLabelNames::fromNames('type')
);
$gauge->set(2.5, 'blue');
$histogram = $registry->getOrRegisterHistogram(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_histogram'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_histogram'),
'it observes',
\Prometheus\Value\HistogramLabelNames::fromNames('type'),
\Enalean\Prometheus\Value\HistogramLabelNames::fromNames('type'),
[0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]
);
$histogram->observe(3.5, 'blue');
```

Manually register and retrieve metrics (these steps are combined in the `getOrRegister...` methods):
```php
$storage = new \Prometheus\Storage\InMemoryStore();
$registry = new \Prometheus\Registry\CollectorRegistry($storage);
$storage = new \Enalean\Prometheus\Storage\InMemoryStore();
$registry = new \Enalean\Prometheus\Registry\CollectorRegistry($storage);
$counterA = $registry->registerCounter(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
'it increases',
\Prometheus\Value\MetricLabelNames::fromNames('type')
\Enalean\Prometheus\Value\MetricLabelNames::fromNames('type')
);
$counterA->incBy(3, 'blue');
// once a metric is registered, it can be retrieved using e.g. getCounter:
$counterB = $registry->getCounter(\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'));
$counterB = $registry->getCounter(\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'));
$counterB->incBy(2, 'red');
```

Expose the metrics:
```php
$storage = new \Prometheus\Storage\InMemoryStore();
$registry = new \Prometheus\Registry\CollectorRegistry($storage);
$storage = new \Enalean\Prometheus\Storage\InMemoryStore();
$registry = new \Enalean\Prometheus\Registry\CollectorRegistry($storage);
$renderer = new \Prometheus\Renderer\RenderTextFormat();
$renderer = new \Enalean\Prometheus\Renderer\RenderTextFormat();
header('Content-type: ' . $renderer->getMimeType());
echo $renderer->render($registry->getMetricFamilySamples());
@@ -86,33 +84,33 @@ Using the Redis storage:
```php
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
$storage = new \Prometheus\Storage\RedisStore();
$storage = new \Enalean\Prometheus\Storage\RedisStore();
$registry = new CollectorRegistry($storage);
$counter = $registry->registerCounter(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
'it increases',
\Prometheus\Value\MetricLabelNames::fromNames('type')
\Enalean\Prometheus\Value\MetricLabelNames::fromNames('type')
);
$counter->incBy(3, 'blue');
$renderer = new \Prometheus\Renderer\RenderTextFormat();
$renderer = new \Enalean\Prometheus\Renderer\RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
```

Using the APCu storage:
```php
$storage = new \Prometheus\Storage\APCUStore();
$storage = new \Enalean\Prometheus\Storage\APCUStore();
$registry = new CollectorRegistry($storage);
$counter = $registry->registerCounter(
\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
\Enalean\Prometheus\Value\MetricName::fromNamespacedName('test', 'some_counter'),
'it increases',
\Prometheus\Value\MetricLabelNames::fromNames('type')
\Enalean\Prometheus\Value\MetricLabelNames::fromNames('type')
);
$counter->incBy(3, 'blue');
$renderer = new \Prometheus\Renderer\RenderTextFormat();
$renderer = new \Enalean\Prometheus\Renderer\RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
```

@@ -174,3 +172,7 @@ Pick the adapter you want to test.
docker-compose exec phpunit env ADAPTER=apcu vendor/bin/phpunit --testsuite=functionnal
docker-compose exec phpunit env ADAPTER=redis vendor/bin/phpunit --testsuite=functionnal
```

## Acknowledgment

This library is based on the work done on [Jimdo/prometheus_client_php](https://github.com/Jimdo/prometheus_client_php).
@@ -1,5 +1,5 @@
{
"name": "tgerbet/prometheus-client",
"name": "enalean/prometheus-client",
"description": "Prometheus instrumentation library",
"license": "Apache-2.0",
"require": {
@@ -25,12 +25,13 @@
},
"autoload": {
"psr-4": {
"Prometheus\\": "src/Prometheus/"
"Enalean\\Prometheus\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\Prometheus\\": ["tests/unit/Prometheus/", "tests/functionnal/"]
"Enalean\\PrometheusTest\\": "tests/unit/",
"Enalean\\PrometheusTestE2E\\": "tests/functionnal/"
}
},
"config": {
@@ -12,15 +12,15 @@
$redis_client = new Redis();
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$storage = new Prometheus\Storage\RedisStore($redis_client);
$storage = new Enalean\Prometheus\Storage\RedisStore($redis_client);
}
if ($adapter === 'apcu') {
$storage = new Prometheus\Storage\APCUStore();
$storage = new Enalean\Prometheus\Storage\APCUStore();
}
if ($adapter === 'in-memory') {
$storage = new Prometheus\Storage\InMemoryStore();
$storage = new Enalean\Prometheus\Storage\InMemoryStore();
}
if ($storage !== null) {
@@ -4,21 +4,21 @@
require __DIR__ . '/../vendor/autoload.php';
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Renderer\RenderTextFormat;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Renderer\RenderTextFormat;
$adapter = (string) $_GET['adapter'] ?? '';
if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
$adapter = new Enalean\Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
$renderer = new RenderTextFormat();
@@ -4,13 +4,13 @@
require __DIR__ . '/../vendor/autoload.php';
use Enalean\Prometheus\PushGateway\PSR18Pusher;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Storage\RedisStore;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Prometheus\PushGateway\PSR18Pusher;
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Storage\RedisStore;
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;
$adapter = (string) $_GET['adapter'] ?? '';
@@ -19,11 +19,11 @@
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
@@ -4,22 +4,22 @@
require __DIR__ . '/../vendor/autoload.php';
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
$adapter = (string) $_GET['adapter'];
if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
$adapter = new Enalean\Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
@@ -4,22 +4,22 @@
require __DIR__ . '/../vendor/autoload.php';
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
$adapter = (string) $_GET['adapter'] ?? '';
if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
$adapter = new Enalean\Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
@@ -4,22 +4,22 @@
require __DIR__ . '/../vendor/autoload.php';
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Value\HistogramLabelNames;
use Prometheus\Value\MetricName;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Value\HistogramLabelNames;
use Enalean\Prometheus\Value\MetricName;
$adapter = (string) $_GET['adapter'] ?? '';
if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
$adapter = new Enalean\Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
$adapter = new Enalean\Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
$adapter = new Enalean\Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
$adapter = new Enalean\Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
@@ -2,7 +2,7 @@
"timeout": 10,
"source": {
"directories": [
"src\/Prometheus"
"src\/"
]
},
"logs": {
@@ -13,12 +13,8 @@

<rule ref="Doctrine"/>

<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming">
<exclude-pattern>src/Prometheus/RendererInterface.php</exclude-pattern>
<exclude-pattern>src/Prometheus/RegistryInterface.php</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix">
<exclude-pattern>src/Prometheus/Exception/MetricNotFoundException.php</exclude-pattern>
<exclude-pattern>src/Prometheus/Exception/MetricsRegistrationException.php</exclude-pattern>
<exclude-pattern>src/Exception/MetricNotFoundException.php</exclude-pattern>
<exclude-pattern>src/Exception/MetricsRegistrationException.php</exclude-pattern>
</rule>
</ruleset>
@@ -17,7 +17,7 @@
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/Prometheus/</directory>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
@@ -2,12 +2,12 @@
declare(strict_types=1);
namespace Prometheus;
namespace Enalean\Prometheus;
use Enalean\Prometheus\Storage\CounterStorage;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
use InvalidArgumentException;
use Prometheus\Storage\CounterStorage;
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;
use function sprintf;
/**
@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Prometheus\Exception;
namespace Enalean\Prometheus\Exception;
use Exception;

0 comments on commit 17a9d82

Please sign in to comment.
You can’t perform that action at this time.