erickskrauch / prometheus
Prometheus instrumentation library for PHP applications.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/erickskrauch/prometheus
Requires
- php: ^8.1
- ext-json: *
Requires (Dev)
- ext-redis: >=6
- ely/php-code-style: ^1
- ergebnis/composer-normalize: ^2.48
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/extension-installer: ^1
- phpstan/phpstan: ^2
- phpstan/phpstan-phpunit: ^2
- phpstan/phpstan-strict-rules: ^2
- phpunit/phpunit: ^10
- predis/predis: ^2 || ^3
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-12-05 16:50:40 UTC
README
Prometheus metrics collector and exporter for PHP. Storage is abstracted to allow better integration with your infrastructure.
Installation
Install it as Composer dependency:
composer require erickskrauch/prometheus
Usage
use ErickSkrauch\Prometheus\CollectorRegistry; use ErickSkrauch\Prometheus\NamespacedRegistry; use ErickSkrauch\Prometheus\Storage\Redis; use ErickSkrauch\Prometheus\Storage\Redis\PHPRedis; $redisClientImplementation = PHPRedis::create(['host' => 'localhost', 'port' => 6379]); $storage = new Redis($redisClientImplementation); $registry = new CollectorRegistry($storage); // Might be useful to prefix all metrics in your app // $registry = new NamespacedRegistry('github', $registry); $registry->counter('readme_readers_total')->inc() $registry->gauge('stars_count', 'How many people read this code example and helped promote the project')->set(1_000); $registry->histogram('delay_before_decision_to_install_seconds', [1, 5, 10, 20, 60] ['trafficSource'])->observe(5.78, ['google']);
In addition to the PHPRedis extension, it also offers an implementation for the Predis library. You can easily write your own adapter for any Redis client by implementing the \ErickSkrauch\Prometheus\Storage\Redis\RedisClient interface.
An in-memory storage driver is also available via \ErickSkrauch\Prometheus\Storage\InMemory.
To expose metrics, register a route in your framework, such as this example for Symfony:
use ErickSkrauch\Prometheus\RegistryInterface; use ErickSkrauch\Prometheus\Renderer\RenderTextFormat; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class MetricsController { #[Route('/metrics', name: 'prometheus_metrics')] public function expose(RegistryInterface $registry): Response { $renderer = new RenderTextFormat(); return new Response( $renderer->render($registry->collectMetrics()), headers: ['Content-Type' => RenderTextFormat::MIME_TYPE], ); } }