league/statsd
Composer 安装命令:
composer require league/statsd
包简介
A simple library for working with StatsD in PHP.
README 文档
README
A library for working with StatsD in PHP.
Install
Via Composer:
composer require league/statsd
To use the Statsd Service Provider, you must register the provider when bootstrapping your Laravel application.
Usage
Configuring
$statsd = new League\StatsD\Client(); $statsd->configure([ 'host' => '127.0.0.1', 'port' => 8125, 'namespace' => 'example' ]);
OR
$statsd1 = StatsD\Client::instance('server1')->configure([...]); $statsd2 = StatsD\Client::instance('server2')->configure([...]);
The StatsD client wait for ini_get('default_socket_timeout') seconds when opening the socket by default. To reduce
this timeout, add 'timeout' => <float> to your config.
The StatsD client will throw a ConnectionException if it is unable to send data to the StatsD server. You may choose
to disable these exceptions and log a PHP warning instead if you wish. To do so, include the following in your config:
'throwConnectionExceptions' => false
If omitted, this option defaults to true.
Counters
$statsd->increment('web.pageview'); $statsd->decrement('storage.remaining'); $statsd->increment([ 'first.metric', 'second.metric' ], 2); $statsd->increment('web.clicks', 1, 0.5);
Gauges
$statsd->gauge('api.logged_in_users', 123456);
Sets
$userID = 23; $statsd->set('api.unique_logins', $userID);
Timers
$statsd->timing('api.response_time', 256);
$metrics = array('api.response_time' => 256, 'api.memory' => 4096)); $statsd->timings($metrics);
Timing Blocks
$statsd->time('api.dbcall', function () { // this code execution will be timed and recorded in ms });
Tags
Attention! That functionality support of tags in Datadog format!
You may configure it for all the metrics sending by the client.
$statsd->configure([ 'tags' => ['some_general_tag' => 'value'] ]);
Or you may send it for a single metric.
$statsd->increment('web.clicks', 1, 1, ['host' => $_SERVER['HTTP_HOST']]);
Framework integration
Although this library will work with any PHP framework, below are a few ways to integrate it quickly with the most popular ones via included adapters.
Laravel 4.x
Find the providers key in your app/config/app.php and register the Statsd Service Provider.
'providers' => [ // ... 'League\StatsD\Laravel\Provider\StatsdServiceProvider', ]
Find the aliases key in your app/config/app.php and add the Statsd Facade Alias.
'aliases' => [ // ... 'Statsd' => 'League\StatsD\Laravel\Facade\StatsdFacade', ]
Laravel 5.x
If you are using Laravel >=5.5, statsd uses package discovery to automatically register the service provider and facade.
For older versions of Laravel 5, or if you disable package discovery:
Find the providers key in your config/app.php and register the Statsd Service Provider.
'providers' => [ // ... League\StatsD\Laravel5\Provider\StatsdServiceProvider::class, ]
Find the aliases key in your app/config/app.php and add the Statsd Facade Alias.
'aliases' => [ // ... 'Statsd' => League\StatsD\Laravel5\Facade\StatsdFacade::class, ]
Lumen
Register the provider in your boostrap app file boostrap/app.php
Add the following line in the "Register Service Providers" section at the bottom of the file.
$app->register(\League\StatsD\Laravel5\Provider\StatsdServiceProvider::class);
Copy the config file statsd.php manually from the directory /vendor/league/statsd/config to the directory /config (you may need to create this directory).
Package Configuration
In your .env file, add the configuration:
STATSD_HOST=127.0.0.1 STATSD_PORT=8125 STATSD_NAMESPACE=
Testing
phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
league/statsd 适用场景与选型建议
league/statsd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.44M 次下载、GitHub Stars 达 351, 最近一次更新时间为 2013 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「statsd」 「graphite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 league/statsd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 league/statsd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 league/statsd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library for working with statsd
Collections of statsd collectors with templated metric names
A PHP client for Carbon (Graphite's backend) using the plaintext protocol.
Statsd (Object Oriented) client library for PHP
Provides a statsd client and simple ready-to-use support for #Symfony2 Application
Inbox pattern process implementation for your Laravel Applications
统计信息
- 总下载量: 4.44M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 357
- 点击次数: 30
- 依赖项目数: 15
- 推荐数: 5
其他信息
- 授权协议: MIT
- 更新时间: 2013-07-20