kislayphp/metrics
Composer 安装命令:
pie install kislayphp/metrics
包简介
High-performance C++ PHP extension providing comprehensive metrics collection and monitoring for PHP microservices
关键字:
README 文档
README
Application metrics for PHP microservices. Counter, gauge, histogram, and timer types with zero instrumentation overhead. Prometheus-compatible export.
Part of the KislayPHP ecosystem.
✨ What It Does
kislayphp/metrics provides C++-backed metrics primitives for PHP applications. All metric operations use atomic operations — measuring your code doesn't slow it down.
<?php $metrics = new Kislay\Metrics\Collector(); $metrics->counter('requests_total')->increment(); $metrics->histogram('request_duration_ms')->observe($ms); echo $metrics->export(); // Prometheus text format
📦 Installation
pie install kislayphp/metrics
Enable in php.ini:
extension=kislayphp_metrics.so
🚀 Quick Start
<?php $metrics = new Kislay\Metrics\Collector(); // Counter — monotonically increasing $metrics->counter('http_requests_total', ['method' => 'GET', 'status' => '200']) ->increment(); // Gauge — value that goes up and down $metrics->gauge('active_connections')->set(42); $metrics->gauge('queue_depth')->increment(); $metrics->gauge('queue_depth')->decrement(); // Histogram — distribution of values $start = microtime(true); // ... handle request ... $metrics->histogram('request_duration_seconds') ->observe(microtime(true) - $start); // Timer (convenience wrapper for histogram) $timer = $metrics->timer('db_query_seconds')->start(); // ... run query ... $timer->stop(); // Export as Prometheus text format $app->get('/metrics', function($req, $res) use ($metrics) { $res->send($metrics->export(), 'text/plain; version=0.0.4'); });
📖 Public API
namespace Kislay\Metrics; class Collector { public function counter(string $name, array $labels = []): Counter; public function gauge(string $name, array $labels = []): Gauge; public function histogram(string $name, array $labels = [], array $buckets = []): Histogram; public function timer(string $name, array $labels = []): Timer; public function export(): string; // Prometheus text format public function reset(): void; } class Counter { public function increment(float $by = 1): void; public function get(): float; } class Gauge { public function set(float $value): void; public function increment(float $by = 1): void; public function decrement(float $by = 1): void; public function get(): float; } class Histogram { public function observe(float $value): void; } class Timer { public function start(): TimerHandle; } class TimerHandle { public function stop(): float; }
Legacy aliases: KislayPHP\Metrics\*
🔗 Ecosystem
core · gateway · discovery · metrics · queue · eventbus
📄 License
kislayphp/metrics 适用场景与选型建议
kislayphp/metrics 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「microservices」 「php-extension」 「php-echo-system」 「cpp-extension」 「php-metrics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kislayphp/metrics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kislayphp/metrics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kislayphp/metrics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The Listener component of the RabbitEvents library.
The Publisher component of the RabbitEvents package.
Laravel common
Laravel support for additional blueprint methods
Laravel comment system
Laravel support for GELF logging
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 42
- 依赖项目数: 0
- 推荐数: 7
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-02-15