flagbit/metrics-bundle
最新稳定版本:2.0.0
Composer 安装命令:
composer require flagbit/metrics-bundle
包简介
FlagbitMetricsBundle provides easy integration of metrics collector services for the Symfony Framework
README 文档
README
About
The FlagbitMetricsBundle provides easy integration for the metrics collector library of Bejamin Eberlei into Symfony2.
Installation
Using Composer
Installation with composer:
composer require flagbit/metrics-bundle
Register the bundle
<?php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Flagbit\Bundle\MetricsBundle\FlagbitMetricsBundle(), // ... ); } }
Usage
Don't forget that this bundle has a dependency on a Metrics library, which you should first integrate and configure. More information can be found here.
For example, just imagine you want to measure some stats over you application.
Create your MetricProvider
<?php namespace Flagbit\ExampleBundle\MetricProvider; use Flagbit\Bundle\MetricsBundle\Collector\CollectorInterface; use Flagbit\Bundle\MetricsBundle\Provider\ProviderInterface; class Provider implements ProviderInterface { public function collectMetrics(CollectorInterface $collector) { $value = random_int(1,9); $collector->measure('foo.bar', $value); } }
Create your Service
Once you have created your metric provider class, let's go to create the service. In order the metric collector service automatically to collect all the metrics of your metric provider service, you just need to use the "metrics.provider" service tag and select so many collectors as you want.
YAML
services: Flagbit\ExampleBundle\MetricProvider\Provider: tags: - { name: metrics.provider, collector: statsd } - { name: metrics.provider, collector: librato }
XML
<?xml version="1.0" encoding="UTF-8" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" > <services> <service id="Flagbit\ExampleBundle\MetricProvider\Provider"> <tag name="metrics.provider" collector="statsd" /> <tag name="metrics.provider" collector="librato" /> </service> </services> </container>
Collect your Metrics
You can collect all metrics by yourself and after flush them to your metric servers or use the command that does it for you instead.
<?php // Collects the metrics of all your tagged services... $container->get('flagbit_metrics.provider_invoker')->collectMetrics(); // ... and flush them $container->get('flagbit_metrics.provider_invoker')->onTerminate();
It is recommended to inject the services into yours instead of using directly the container.
Command
$ php bin/console flagbit:metrics:flush
统计信息
- 总下载量: 1.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-01-20