graze/dog-statsd
Composer 安装命令:
composer require graze/dog-statsd
包简介
DataDog StatsD Client
README 文档
README
Client to talk to DataDogs StatsD Agent Forked from: League/StatsD
For more information on the metric, see: Datadogs metrics guide.
Install
Via Composer
$ composer require graze/dog-statsd
Usage
Configuring
$statsd = new Graze\DogStatsD\Client(); $statsd->configure([ 'host' => '127.0.0.1', 'port' => 8125, 'namespace' => 'example', ]);
OR
$statsd1 = DogStatsD\Client::instance('server1')->configure([...]); $statsd2 = DogStatsD\Client::instance('server2')->configure([...]);
The StatsD client waits for ini_get('default_socket_timeout') seconds when opening the socket by default. To reduce
this timeout, add 'timeout' => <int> to your config.
The StatsD client will either throw a ConnectionException, throw a warning or ignore all errors if it is unable to
send data to the StatsD server. This can be configured using the onError property
'onError' => 'error' // 'error', 'exception' or 'ignore'
By default this is set to 'error'
Core StatsD implementation
To use this with a core statsd implementation (without the extra features DataDog have added) include the following in your configuration:
'dataDog' => false
Methods
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);
Histogram
$result = $db->fetch(); $statsd->histogram('db.results', count($result), 0.5);
Timers
$statsd->timing('api.response_time', 256);
Timing Blocks
$statsd->time('api.dbcall', function () { // this code execution will be timed and recorded in ms });
Tags
$statsd->increment('web.pageview', 1, ['page' => 'some/page']); $statsd->guage('api.logged_in_users', 123456, ['environement' => 'live']); $statsd->set('api.unique_logins', $userID, ['tag']); $statsd->timing('api.response_time', 245, ['end-point' => 'page', 'env' => 'test']);
Tags Processors
You can add tag processors to inject tags at runtime for each metric.
$statsd->addTagProcessor(function (array $tags) { $tags['new-key'] = 'new-value'; return $tags; });
Events
$statsd->event( 'build.success', 'The build super_awesome_application_build_1 has completed', [ 'time' => time(), 'alert' => Client::ALERT_SUCCESS, ], [ 'environment' => 'live', ] );
Service Check
$statsd->serviceCheck( 'service.api.account', Client::STATUS_OK, [ 'host' => 'this.hostname.com', 'time' => time(), ], [ 'environment' => 'staging', ] );
Default Tags
Send the same base tags with every request
$client = new Client(); $client->configure([ 'tags' => [ 'env' => 'live', 'release' => 'app-2.3.1', ], ]);
Testing
$ make test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email security@graze.com instead of using the issue tracker.
Credits
Forked from thephpleague/statsd:
License
The MIT License (MIT). Please see License File for more information.
graze/dog-statsd 适用场景与选型建议
graze/dog-statsd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.17M 次下载、GitHub Stars 达 41, 最近一次更新时间为 2016 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「statsd」 「DataDog」 「graze」 「dogstatsd」 「dog-statsd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 graze/dog-statsd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 graze/dog-statsd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 graze/dog-statsd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Merge arrays recusively using custom value choosers
Monolog Handler that uses Datadog
Collections of statsd collectors with templated metric names
Monolog DataDog processor
Retry tasks that fail due to transient faults
run a pool of processes simultaneously
统计信息
- 总下载量: 3.17M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 22
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-10