beberlei/metrics
Composer 安装命令:
composer require beberlei/metrics
包简介
Simple library to talk to metrics collector services.
README 文档
README
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics API that doesn't cause vendor lock-in.
It also ships with a Symfony Bundle. This is not a library for displaying metrics.
Currently supported backends:
- Doctrine DBAL
- Graphite
- InfluxDB
- Telegraf
- Librato
- Logger (Psr\Log\LoggerInterface)
- Null (Dummy that does nothing)
- Prometheus
- StatsD
- Zabbix
- DogStatsD
Installation
Using Composer:
composer require beberlei/metrics
API
You can instantiate clients:
<?php $collector = \Beberlei\Metrics\Factory::create('statsd');
You can measure stats:
<?php $collector->increment('foo.bar'); $collector->decrement('foo.bar'); $start = microtime(true); $diff = microtime(true) - $start; $collector->timing('foo.bar', $diff); $value = 1234; $collector->measure('foo.bar', $value);
Some backends defer sending and aggregate all information, make sure to call flush:
<?php $collector->flush();
Configuration
<?php $statsd = \Beberlei\Metrics\Factory::create('statsd'); $zabbix = \Beberlei\Metrics\Factory::create('zabbix', array( 'hostname' => 'foo.beberlei.de', 'server' => 'localhost', 'port' => 10051, )); $zabbixConfig = \Beberlei\Metrics\Factory::create('zabbix_file', array( 'hostname' => 'foo.beberlei.de', 'file' => '/etc/zabbix/zabbix_agentd.conf' )); $librato = \Beberlei\Metrics\Factory::create('librato', array( 'hostname' => 'foo.beberlei.de', 'username' => 'foo', 'password' => 'bar', )); $null = \Beberlei\Metrics\Factory::create('null');
Symfony Bundle Integration
Register Bundle into Kernel:
<?php class AppKernel extends Kernel { public function registerBundles() { //.. $bundles[] = new \Beberlei\Bundle\MetricsBundle\BeberleiMetricsBundle(); //.. } }
Do Configuration:
# app/config/config.yml beberlei_metrics: default: foo collectors: foo: type: statsd bar: type: zabbix prefix: foo.beberlei.de host: localhost port: 10051 baz: type: zabbix_file prefix: foo.beberlei.de file: /etc/zabbix/zabbix_agentd.conf librato: type: librato username: foo password: bar source: hermes10 dbal: type: doctrine_dbal connection: metrics # using the connection named "metrics" monolog: type: monolog influxdb: type: influxdb influxdb_client: influxdb_client_service # using the InfluxDB client service named "influxdb_client_service" tags: dc: "west" node_instance: "hermes10" prometheus: type: prometheus prometheus_collector_registry: prometheus_collector_registry_service # using the Prometheus collector registry service named "prometheus_collector_registry_service" namespace: app_name # optional tags: dc: "west" node_instance: "hermes10"
This adds collectors to the Metrics registry. The functions are automatically included in the Bundle class so that in your code you can just start using the convenient functions. Metrics are also added as services:
<?php $metrics = $container->get('beberlei_metrics.collector.foo');
and the default collector can be fetched:
<?php $metrics = $container->get('beberlei_metrics.collector');
beberlei/metrics 适用场景与选型建议
beberlei/metrics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.23M 次下载、GitHub Stars 达 322, 最近一次更新时间为 2012 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「Metrics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beberlei/metrics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beberlei/metrics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beberlei/metrics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
A abstraction for generating metrics in Laravel.
Laravel SDK for working with prometheus metrics
Production-ready Laravel Prometheus metrics package with built-in collectors for HTTP, database, cache, queue, events, errors, filesystem, and mail monitoring
统计信息
- 总下载量: 1.23M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 325
- 点击次数: 20
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-05-23