erickskrauch/prometheus
最新稳定版本:0.1.0
Composer 安装命令:
composer require erickskrauch/prometheus
包简介
Prometheus instrumentation library for PHP applications.
README 文档
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], ); } }
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-05