yuanlj-tea/metric
Composer 安装命令:
composer require yuanlj-tea/metric
包简介
metric component
README 文档
README
Installation
Use composer:
composer require yuanlj-tea/metric
Usage
配置文件
配置文件模板路径,复制一份到自己的项目:
/publish/metric.php
配置文件内容:
'default' => 'prometheus', // 配置使用的适配器
'default_metric_interval' => 5,
'metric' => [
'prometheus' => [
'driver' => \Metric\Adapter\Prometheus\MetricFactory::class, // prometheus使用的class
'mode' => \Metric\Adapter\Prometheus\Constants::SCRAPE_MODE, // 模式,抓取模式或主动推送模式
'storage_adapter' => 'redis', // 数据存储方式
'namespace' => 'app-name', // config namespace
'scrape_host' => '0.0.0.0', // 抓取模式时的host
'scrape_port' => '9502', // 抓取模式时的port
'scrape_path' => '/metrics', // 抓取模式时的请求接口
'push_host' => '0.0.0.0', // 主动推送模式的host
'push_port' => '9091', // 主动推送模式的port
'push_interval' => 5, // 主动推送模式的间隔时间
],
],
'redis' => [ // 使用redis存储时的redis相关配置
'host' => '127.0.0.1',
'port' => 6379,
'password' => 123456,
'timeout' => 1, // in seconds
'read_timeout' => '10', // in seconds
'persistent_connections' => false
],
useage demo
<?php namespace Metric; use Metric\Timer; use Metric\Contract\MetricFactoryInterface; use Metric\MetricFactory; class Metric { /** * @var MetricFactoryInterface */ private static $metric; /** * @param array $config * @return Metric */ public static function getMetric(array $config = []): self { self::$metric = MetricFactory::getFactory($config); return new self(); } public function count(string $name, ?int $delta = 1, ?array $labels = []) { self::$metric->makeCounter($name, array_keys($labels)) ->with(...array_values($labels)) ->add($delta); } public function gauge(string $name, float $value, ?array $labels = []) { self::$metric->makeGauge($name, array_keys($labels)) ->with(...array_values($labels)) ->set($value); } public function put(string $name, float $sample, ?array $labels = []) { self::$metric->makeHistogram($name, array_keys($labels)) ->with(...array_values($labels)) ->put($sample); } public function time(string $name, callable $func, ?array $args = [], ?array $labels = []) { $timer = new Timer(self::$metric, $name, $labels); return $func(...$args); } public function show() { self::$metric->handle(); } }
yuanlj-tea/metric 适用场景与选型建议
yuanlj-tea/metric 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yuanlj-tea/metric 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yuanlj-tea/metric 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-06