gupalo/prometheus-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gupalo/prometheus-helper

Composer 安装命令:

composer require gupalo/prometheus-helper

包简介

Prometheus Helper

README 文档

README

Wrapper for PHP Prometheus library - https://github.com/PromPHP/prometheus_client_php

Install

composer require gupalo/prometheus-helper

Usage

Basic Usage

use Gupalo\PrometheusHelper\FileAdapter;
use Gupalo\PrometheusHelper\Prometheus;

$helper = new Prometheus(new FileAdapter('/var/prom'), 'myapp');

// Counter
$helper->inc('requests_total', 'Total requests');
$helper->inc('requests_total', 'Total requests', ['method' => 'GET']);

// Gauge
$helper->gaugeSet(100, 'temperature', 'Current temperature');
$helper->gaugeInc('active_connections', 'Active connections');
$helper->gaugeDec('active_connections', 'Active connections');

// Histogram
$helper->observe(0.5, 'request_duration_seconds', 'Request duration');

// Render metrics
$response = $helper->render();

With Redis Storage (DSN)

use Gupalo\PrometheusHelper\Prometheus;
use Gupalo\PrometheusHelper\RedisAdapter;

$helper = new Prometheus(new RedisAdapter('redis://redis'), 'myapp');
$helper->inc('requests_total', 'Total requests');

Supported DSN formats:

  • redis://redis - simple hostname
  • redis://redis:6380 - with port
  • redis://:password@redis:6379 - with password
  • redis://user:password@redis:6379/2 - with user, password and database
  • redis://redis:6379/0?timeout=0.5&persistent=true - with options

Symfony Integration

Configure in config/services.yaml:

services:
    Prometheus\Storage\Adapter:
        class: Gupalo\PrometheusHelper\RedisAdapter
        arguments:
            $dsn: '%env(REDIS_DSN)%'
    Gupalo\PrometheusHelper\Prometheus:
        arguments:
            $adapter: '@Prometheus\Storage\Adapter'
            $namespace: 'myapp'

when@dev:
    services:
        Prometheus\Storage\Adapter:
            class: Gupalo\PrometheusHelper\FileAdapter
            arguments:
                $dir: '%kernel.project_dir%/var/prom'

when@test:
    services:
        Prometheus\Storage\Adapter:
            class: Prometheus\Storage\InMemory

Then inject in your services:

class MyService
{
    public function __construct(
        private readonly Prometheus $prometheus,
    ) {}

    public function doSomething(): void
    {
        $this->prometheus->inc('operations_total', 'Total operations');
    }
}

Also see tests for more examples.

Migration from v1 to v2

Ask Claude:

find all PrometheusHelper usages and change to Prometheus
read doc from: vendor/gupalo/prometheus-helper/README.md

Or do it manually:

  • update config/services.yaml - add code from "Symfony Integration" section above
  • change all use Gupalo\PrometheusHelper\PrometheusHelper; to use Gupalo\PrometheusHelper\Prometheus;
  • add to constructor private readonly Prometheus $prometheus,
  • change all PrometheusHelper:: to $this->prometheus->

gupalo/prometheus-helper 适用场景与选型建议

gupalo/prometheus-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.38k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 gupalo/prometheus-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gupalo/prometheus-helper 我们能提供哪些服务?
定制开发 / 二次开发

基于 gupalo/prometheus-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-22