datadog/php-datadogstatsd
Composer 安装命令:
composer require datadog/php-datadogstatsd
包简介
An extremely simple PHP datadogstatsd client
README 文档
README
This is an extremely simple PHP DogStatsD client.
Requires PHP >= 5.6.0.
See CHANGELOG.md for changes.
For a Laravel-specific implementation that wraps this library, check out laravel-datadog-helper.
Installation
Add the following to your composer.json:
"datadog/php-datadogstatsd": "1.6.*"
The first version shipped in composer is 0.0.3
Or manually clone this repository and set it up with require './src/DogStatsd.php'.
Once installed, turn on the socket extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure.
Configuration
To instantiate a DogStatsd object using composer:
<?php require __DIR__ . '/vendor/autoload.php'; use DataDog\DogStatsd; $statsd = new DogStatsd( array('host' => '127.0.0.1', 'port' => 8125, ) );
DogStatsd constructor, takes a configuration array. See the full list of available DogStatsD Client instantiation parameters.
Usage
In order to use DogStatsD metrics, events, and Service Checks the Agent must be running and available.
Metrics
After the client is created, you can start sending custom metrics to Datadog. See the dedicated Metric Submission: DogStatsD documentation to see how to submit all supported metric types to Datadog with working code examples:
- Submit a COUNT metric.
- Submit a GAUGE metric.
- Submit a SET metric
- Submit a HISTOGRAM metric
- Submit a TIMER metric
- Submit a DISTRIBUTION metric
Some options are suppported when submitting metrics, like applying a Sample Rate to your metrics or tagging your metrics with your custom tags.
Events
After the client is created, you can start sending events to your Datadog Event Stream. See the dedicated Event Submission: DogStatsD documentation to see how to submit an event to your Datadog Event Stream.
Service Checks
After the client is created, you can start sending Service Checks to Datadog. See the dedicated Service Check Submission: DogStatsD documentation to see how to submit a Service Check to Datadog.
Origin detection in Kubernetes
Origin detection is a method to detect the pod that DogStatsD packets are coming from and add the pod's tags to the tag list.
Tag cardinality
The tags that can be added to metrics can be found here. The cardinality can be specified globally by setting the DD_CARDINALITY
environment or by passing a 'cardinality' field to the constructor. Cardinality can also be specified per metric by passing the value
in the $cardinality parameter. Valid values for this parameter are "none", "low", "orchestrator" or "high". If an invalid
value is passed, an E_USER_WARNING error is raised. If this error is handled with set_error_handler the metric is sent without a
cardinality field.
Origin detection is achieved in a number of ways:
CGroups
On Linux the container ID can be extracted from procfs entries related to cgroups. The client reads from /proc/self/cgroup or /proc/self/mountinfo to attempt to parse the container id.
In cgroup v2, the container ID can be inferred by resolving the cgroup path from /proc/self/cgroup, combining it with the cgroup mount point from /proc/self/mountinfo]. The resulting directory's inode is sent to the agent. Provided the agent is on the same node as the client, this can be used to identify the pod's UID.
Over UDP
To enable origin detection over UDP, add the following lines to your application manifest
env: - name: DD_ENTITY_ID valueFrom: fieldRef: fieldPath: metadata.uid
The DogStatsD client attaches an internal tag, entity_id. The value of this tag is the content of the DD_ENTITY_ID environment variable, which is the pod's UID.
The agent uses this tag to infer packets' origin, and tag their metrics accordingly.
DD_EXTERNAL_ENV
If the pod is annotated with the label:
admission.datadoghq.com/enabled: "true"
The admissions controller injects an environment variable DD_EXTERNAL_ENV.
The value of this is sent in a field with the metric which can be used by the
agent to determine the metrics origin.
Tests
composer test
Lint
composer lint
Fix lint
composer fix-lint
datadog/php-datadogstatsd 适用场景与选型建议
datadog/php-datadogstatsd 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.82M 次下载、GitHub Stars 达 190, 最近一次更新时间为 2015 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「monitoring」 「check」 「statsd」 「health」 「DataDog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 datadog/php-datadogstatsd 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 datadog/php-datadogstatsd 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 datadog/php-datadogstatsd 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
A Zend Framework module that sets up Monolog for logging in applications.
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Check for holidays - localeaware
统计信息
- 总下载量: 26.82M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 196
- 点击次数: 32
- 依赖项目数: 18
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-25