定制 erickskrauch/prometheus 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Latest Version on Packagist Total Downloads Software License Build Status

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
  • 收藏数: 16
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固