okvpn / datadog-symfony
Symfony Datadog集成
1.0.0
2024-01-07 16:45 UTC
Requires
- php: >=7.4
- graze/dog-statsd: ^0.4 || ^1.0
- symfony/framework-bundle: ^4.4 || ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- ext-pdo_sqlite: *
- doctrine/doctrine-bundle: ^2.6
- doctrine/orm: ^2.7
- phpunit/phpunit: ^8.5 || ^9.0 || ^10.0
- symfony/browser-kit: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/console: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/flex: ^1.10 || ^2.0
- symfony/monolog-bundle: ^3.2
- symfony/phpunit-bridge: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/security-bundle: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/var-dumper: ^4.4 || ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^4.4 || ^5.4 || ^6.0 || ^7.0
README
Symfony Datadog集成,用于监控和跟踪应用程序错误,并发送有关它们的通知。
优点
使用datadog-symfony进行
- 实时监控生产应用程序。
- 应用性能洞察,以查看性能何时开始下降。
- 通过容器访问
okvpn_datadog.client
。 - 在Slack、电子邮件、Telegram等发送错误通知。
- 当某些警报/异常触发时,使用此插件创建JIRA问题
安装
- 通过composer安装
composer require okvpn/datadog-symfony
- 并将此bundle添加到您的AppKernel
对于Symfony 4+,将bundle添加到config/bundles.php
<?php return [ ... // bundles Okvpn\Bundle\DatadogBundle\OkvpnDatadogBundle::class => ['all' => true], ... ]
- 基础配置以在您的
config.yml
中启用datadog客户端
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)%'
环境变量看起来像
DD_CLIENT=datadog://127.0.0.1:8125/app1?tags=tg1,tg2
通过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'); } }
由OkvpnDatadogBundle提供的自定义度量
其中app
度量命名空间。
配置
更复杂的设置如下所示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
用法
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']);
设置
$consumerPid = getmypid(); $client->set('consumers', $consumerPid);
计时
$client->timing('http.response_time', 256);
更多度量指标请参阅DogStatsInterface
对性能的影响
Datadog bundle使用UDP协议将自定义度量发送到DogStatsD收集器,通常运行在本地主机(127.0.0.1)。因为它使用UDP,所以您的应用程序可以在不等待响应的情况下发送度量。DogStatsD将每个唯一度量的多个数据点聚合为单个数据点,在称为刷新间隔的期间,然后将其发送到Datadog,在那里它被存储并可用于与您的其他度量一起绘图。
屏幕录像。
可以使用datadog做什么。
Datadog自定义symfony仪表板
Datadog运行消费者异常监控器
实时异常事件流
在Telegram中发送错误通知。
当某些警报/异常触发时创建JIRA问题
许可
MIT许可。请参阅LICENSE。