2017 © Pedro Peláez
 

symfony-bundle metrics-bundle

Symfony Bundle for Metrics management

image

troopers/metrics-bundle

Symfony Bundle for Metrics management

  • Friday, August 4, 2017
  • by lenybernard
  • Repository
  • 3 Watchers
  • 9 Stars
  • 8,385 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 10 Versions
  • 3 % Grown

The README.md

Troopers, (*1)

License Version Packagist DL Build Status SensioLabsInsight Twitter Follow, (*2)

MetricsBundle

Synopsis

This bundle works with Monolog and is used to improve monitoring or metric logging process thanks to ELK (Elasticsearch, Logstash, Kibana)., (*3)

Install

composer require troopers/metrics-bundle and registrer in AppKernel, (*4)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new Troopers\MetricsBundle\MetricsBundle(),
            ...
        );

        return $bundles

Be sure some serializer is enabled:, (*5)

Processors

UserProcessor

This processor will automatically add user informations to every log. Among availables informations, we can know if the user is authenticated (_authenticated: true/false_), when appropriate his id and username. Furthermore, this processor will check if you defined some serializer groups in the metrics.serializer_user_groups config., (*6)

The config below will tell the symfony serializer to serialize the authenticated user by using the profile group:, (*7)

metrics:
    serializer_user_groups:
      - profile

By default, this processor, is only available for the app channel, you can add an other or ovveride the service declaration to use on other handler or channel., (*8)

The results will be prefixed by user_ (user_id, user_city...) and you don't need to give any additional context., (*9)

ContextSerializerProcessor

This processor stands for serializing objects in order to avoid you to pass serializer every where you need to log something. To communicate with this processor and tell it to do its job, you'll need to wrap your objects in a ContextSerializerProcessor and give them to the contexts like below:, (*10)

$logger->info('a log with some context object', [
    new SerializeContextItem($someObject, ['serializingGroupLambda'], 'myalias'),
    'a_different_simple_context_prop' => 42,
    new SerializeContextItem($anotherOne, ['serializingGroup1', 'serializingGroup2']),
]);

The processor'll handle the context and start to work when it'll find your SerializeContextItems and add the serialized objects to the context by using the groups given in 2nd constructor argument. If an alias is given, it will use it to store the property, else it will prefix with the class name., (*11)

AlterDateTimeProcessor

For some reason, you may want to log an event in the past (or future why not ?). The AlterDateTimeProcessor will do it for you, all you need to do is to define the @datetime context property with the wanted \DateTime value., (*12)

$logger->info('a test in the past', ['@datetime' => new \DateTime('10 days ago')]);

By default, this processor, is only available for the app channel, you can add an other or ovveride the service declaration to use on other handler or channel., (*13)

DomainProcessor

In some case, you need to add some extra information to improve your logs: application name, environment... You can add them in extra_fields, (*14)

metrics:
    extra_fields:
        app: 'Acme App'
        env: 'preprod'

Only scalarvalues are allowed. (string, integer, boolean, float, null), (*15)

This processor also add request Uri when she his defined, (*16)

By default, this processor is available for all channels., (*17)

GitProcessor

This processor try to find git revision with git command or in REVISION file at the root of application, (*18)

By default, this processor is available for all channels., (*19)

Log sandbox

Sometime, we just want to send log to test something, this log sandbox to help you to accomplish this small thing., (*20)

Check the metrics routes are registered (in your app/config/routing.yml or routing_dev.yml):, (*21)

MetricsBundle:
    resource: "@MetricsBundle/Controller/"
    type:     annotation
    prefix:   /metrics

and go to /metrics/sandbox/newLog to get your console: Log console sandbox, (*22)

Dashboard and time filter

Once you finished to build your dashboard in kibana, you'll be able to get an iframe to embed it in your website. To handle dashboard in your admin with a time filter, add a row in the database like this:, (*23)

INSERT INTO `metrics_dashboard` (`id`, `name`, `url`, `height`, `width`)
VALUES (1, 'base', '<iframe src="http://your.kibana.url[...]"></iframe>', 768, 1200);

Then, embed the MetricsBundle:Dashboard:show and override (or not) the available blocks:, (*24)

    {% embed 'MetricsBundle:Dashboard:show.html.twig' %}
        {% block body_title %}
            Some thing before the title
            {{ parent() }}
        {% endblock body_title %}
        {# disable the timeFilterForm #}
        {% block body_timeFilterForm %}{% endblock  %}
    {% endembed %}

Time filters

Kibana doesn't integrate its time filter in embed dashboard. The TimeFilter and TimeFilterForm is here to navigate into dashboards., (*25)

Although, TimeFilter is an entity, so you can add some relations between your user and some dashboard., (*26)

Here are the available time filters:, (*27)

  • Today
  • This week
  • This month
  • This year
  • Yesterday
  • Day before yesterday
  • Last 15 minutes
  • Last 30 minutes
  • Last 1 hour
  • Last 4 hours
  • Last 12 hours
  • Last 24 hours
  • Last 7 days
  • Last 30 days
  • Last 60 days
  • Last 90 days
  • Last 6 months
  • Last 1 year
  • Last 2 years
  • Last 5 years

The Versions

04/08 2017

dev-master

9999999-dev http://www.doctrine-project.org

Symfony Bundle for Metrics management

  Sources   Download

MIT

The Requires

 

elasticsearch metrics logstash elk

04/08 2017
04/08 2017
12/09 2016

1.1.0

1.1.0.0 http://www.doctrine-project.org

Symfony Bundle for Metrics management

  Sources   Download

MIT

The Requires

 

elasticsearch metrics logstash elk

26/07 2016

1.0.0

1.0.0.0 http://www.doctrine-project.org

Symfony Bundle for Metrics management

  Sources   Download

MIT

The Requires

 

elasticsearch metrics logstash elk