danog/better-prometheus
Composer 安装命令:
composer require danog/better-prometheus
包简介
A better Prometheus library for PHP applications
README 文档
README
A better Prometheus library for PHP applications.
Offers a modern, clean PHP 8.1 API, with support for default label values, based on and compatible with the original promphp/prometheus_client_php library.
Installation
composer require danog/better-prometheus
Usage
<?php require 'vendor/autoload.php'; use danog\BetterPrometheus\BetterCollectorRegistry; use Prometheus\Storage\InMemory; use Prometheus\Storage\Redis; $adapter = new InMemory; // Any other promphp adapter may also be used... // $adapter = new Redis(); $registry = new BetterCollectorRegistry($adapter); // Note the difference with promphp: the labels are keys => values, not just keys. $counter = $registry->getOrRegisterCounter( 'test', 'some_counter', 'it increases', // Note: these are default label key+values, they will be sent verbatim, no changes ['someLabel' => 'defaultValue'] ); // Specify some additional labels post-construction like this (both keys and values)... $counter->incBy(3, ['type' => 'blue']); // ...or add some more default labels to the counter, creating a new counter: $newCounter = $counter->addLabels(['someOtherLabel' => 'someOtherDefaultValue']); assert($newCounter !== $counter); // true $newCounter->incBy(3, ['type' => 'blue']); // Gauges can also be used $gauge = $registry->getOrRegisterGauge( 'test', 'some_gauge', 'it sets', ['someLabel' => 'defaultValue'] ); $gauge->set(2.5, ['type' => 'blue']); // As well as histograms $histogram = $registry->getOrRegisterHistogram( 'test', 'some_histogram', 'it observes', ['someLabel' => 'defaultValue'], // [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9] ); $histogram->observe(3.5, ['type' => 'blue']); // And suummaries $summary = $registry->getOrRegisterSummary( 'test', 'some_summary', 'it observes a sliding window', ['someLabel' => 'defaultValue'], // 84600, // [0.01, 0.05, 0.5, 0.95, 0.99] ); $summary->observe(5, ['type' => 'blue']);
API documentation
See here » for the full API documentation.
danog/better-prometheus 适用场景与选型建议
danog/better-prometheus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 229.27k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2024 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 danog/better-prometheus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danog/better-prometheus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 229.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 27
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-05-03