studiosite / monitoring-bundle
用于监控项目中简单参数的Bundle
1.0.1
2018-04-23 13:14 UTC
Requires
- php: ^5.5.9 || ^7.0
- symfony/framework-bundle: ^2.7 || ^3.0 || ^4.0
- symfony/templating: ^2.7 || ^3.0 || ^4.0
- symfony/twig-bundle: ^2.7 || ^3.0 || ^4.0
- twig/twig: ^1.28 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^6.0
- symfony/yaml: ^4.0
This package is not auto-updated.
Last update: 2024-09-15 03:03:34 UTC
README
有时使用外部监控系统(例如,zabbix)来监控某些参数变得很有必要。这个Bundle使得这变得非常简单
步骤 1:下载Bundle
打开命令行,进入您的项目目录,然后执行以下命令以下载此Bundle的最新稳定版本
$ composer require studiosite/monitoring-bundle
步骤 2:启用Bundle
然后,通过将其添加到项目app/AppKernel.php
文件中注册的Bundle列表中来启用此Bundle
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new StudioSite\MonitoringBundle\StudioSiteMonitoringBundle(), ); } }
步骤 3:配置
studio_site_monitoring: # path to console file for zabbix config generator # usually the bundle finds the desired path console: "%kernel.root_dir%/../bin/console"
使用示例
考虑一个提供参数值的示例服务
<?php // AppBundle/Service/SomeService.php class SomeService { // Your magic... public function getSomeValue() { return 'teststring'; } public function getCount() { return 100; } public function getSum($a, $b) { return $a + $b; } }
服务描述在DI中
services: app_bundle.some_service: class: AppBundle\Service\SomeService tags: - { name: studiosite_monitoring.parameter, method: getSomeValue, key: app.some_value } - { name: studiosite_monitoring.parameter, method: getCount, key: app.count } - { name: studiosite_monitoring.parameter, method: getSum, key: app.sum }
现在您可以获取参数值
# To see a list of available parameters: $ php bin/console studiosite:monitoring:get The list of available parameters: app.some_value app.count app.sum <a> <b> # To get the value of the parameter: $ php bin/console studiosite:monitoring:get app.some_value teststring $ php bin/console studiosite:monitoring:get app.sum 100 100 200
生成zabbix用户参数配置
此Bundle可以生成所有收集到的参数的zabbix用户参数格式配置
$ php bin/console studiosite:monitoring:zabbix /etc/zabbix/conf.d/symfony.conf Write config to /etc/zabbix/conf.d/symfony.conf? y $ cat /etc/zabbix/conf.d/symfony.conf UserParameter=app.some_value[*], /var/www/dev/bin/console studiosite:monitoring:get app.some_value --no-debug -e prod UserParameter=app.count[*], /var/www/dev/bin/console studiosite:monitoring:get app.count --no-debug -e prod UserParameter=app.sum[*], /var/www/dev/bin/console studiosite:monitoring:get app.sum $1 $2 --no-debug -e prod