okvpn/datadog-symfony
Composer 安装命令:
composer require okvpn/datadog-symfony
包简介
Symfony Datadog integration
README 文档
README
Symfony Datadog integration to monitor and track for application errors and send notifications about them.
Benefits
Use datadog-symfony for:
- Monitor production applications in realtime.
- Application performance insights to see when performance is geting degradated.
- Access to the
okvpn_datadog.clientthrough the container. - Send notification about errors in Slack, email, telegram, etc.
- Create JIRA issue when some alarm/exception triggers using this plugin
Install
Install using composer following the official Composer documentation:
- Install via composer:
composer require okvpn/datadog-symfony
- And add this bundle to your AppKernel:
For Symfony 4+ add bundle to config/bundles.php
<?php return [ ... // bundles Okvpn\Bundle\DatadogBundle\OkvpnDatadogBundle::class => ['all' => true], ... ]
- Base configuration to enable the datadog client in your
config.yml
okvpn_datadog: clients: default: 'datadog://127.0.0.1/namespace' ## More clients i2pd_client: 'datadog://10.10.1.1:8125/app?tags=tg1,tg2' 'null': null://null mock: mock://mock dns: '%env(DD_CLIENT)%'
Where env var looks like:
DD_CLIENT=datadog://127.0.0.1:8125/app1?tags=tg1,tg2
Access to client via DIC:
$client = $this->container->get('okvpn_datadog.client'); // Default public alias // okvpn_datadog.client.default - private services // okvpn_datadog.client.i2pd_client // okvpn_datadog.client.null class FeedController { public function __construct(private DogStatsInterface $dogStats){} // default } class FeedController { public function __construct(private DogStatsInterface $i2pdClient){} // i2pd_client }
class FeedController extends Controller { // Inject via arg for Symfony 4+ #[Route(path: '/', name: 'feeds')] public function feedsAction(DogStatsInterface $dogStats, DogStatsInterface $i2pdClient): Response { $dogStats->decrement('feed'); return $this->render('feed/feeds.html.twig'); } }
Custom metrics that provided by OkvpnDatadogBundle
Where app metrics namespace.
| Name | Type | Description |
|---|---|---|
| app.exception | counter | Track how many exception occurred in application per second |
| app.doctrine.median | gauge | Median execute time of sql query (ms.) |
| app.doctrine.avg | gauge | Avg execute time of sql query (ms.) |
| app.doctrine.count | rate | Count of sql queries per second |
| app.doctrine.95percentile | gauge | 95th percentile of execute time of sql query (ms.) |
| app.exception | event | Event then exception is happens |
| app.http_request | timing | Measure timing how long it takes to fully render a page |
Configuration
A more complex setup look like this config/packages/ddog.yml:
okvpn_datadog:
profiling: true # Default false: enable exception, http request etc.
namespace: app # Metric namespace
port: 8125 # datadog udp port
host: 127.0.0.1
tags: # Default tags which sent with every request
- example.com
- cz1
doctrine: true # Enable timing for sql query
exception: all # Send event on exception
# *all* - handle all exceptions: logger error context, console error, http error.
# *uncaught* - handle uncaught exceptions: console error, http error.
# *none* - disable exceptions handler
dedup_path: null # Path to save duplicates log records across multiple requests.
# Used to prevent send multiple event on the same error
dedup_keep_time: 86400 # Time in seconds during which duplicate entries should be suppressed after a given log is sent through
artifacts_path: null # Long events is aggregate as artifacts, because datadog event size is limited to 4000 characters.
handle_exceptions: # Skip exceptions
skip_instanceof:
- Symfony\Component\Console\Exception\ExceptionInterface
- Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
skip_command: # Skip exception for console command
- okvpn:message-queue:consume
Usage
class FeedController extends Controller { // Inject via arg for Symfony 4+ #[Route(path: '/', name: 'feeds')] public function feedsAction(DogStatsInterface $dogStats): Response { $dogStats->decrement('feed'); return $this->render('feed/feeds.html.twig'); } } // or use service directly for 3.4 $client = $this->container->get('okvpn_datadog.client'); /* * Increment/Decriment * * Counters track how many times something happens per second, such as page views. * @link https://docs.datadoghq.com/developers/dogstatsd/data_types/#counters * * @param string $metrics Metric(s) to increment * @param int $delta Value to decrement the metric by * @param float $sampleRate Sample rate of metric * @param string[] $tags List of tags for this metric * * @return DogStatsInterface */ $client->increment('page.views', 1); $client->increment('page.load', 1, 0.5, ['tag1' => 'http']);
Sets
$consumerPid = getmypid(); $client->set('consumers', $consumerPid);
Timing
$client->timing('http.response_time', 256);
See more metrics here DogStatsInterface
Impact on performance
Datadog bundle use UDP protocol to send custom metrics to DogStatsD collector, that usually running on localhost (127.0.0.1). Because it uses UDP, your application can send metrics without waiting for a response. DogStatsD aggregates multiple data points for each unique metric into a single data point over a period of time called the flush interval and sends it to Datadog where it is stored and available for graphing alongside the rest of your metrics.
Screencasts.
What can be done using datadog.
Datadog custom symfony dashboard
Datadog Anomaly Monitor of running consumers
Live exception event stream
Send notification about errors in telegram.
Create JIRA issue when some alarm/exception triggers
License
MIT License. See LICENSE.
okvpn/datadog-symfony 适用场景与选型建议
okvpn/datadog-symfony 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.03M 次下载、GitHub Stars 达 21, 最近一次更新时间为 2018 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「dogstatsd」 「datadog-symfony」 「php-datadog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 okvpn/datadog-symfony 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 okvpn/datadog-symfony 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 okvpn/datadog-symfony 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 2.03M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-30





