{"id":19805537,"url":"https://github.com/troopers/metricsbundle","last_synced_at":"2025-08-28T09:09:21.607Z","repository":{"id":57072948,"uuid":"58870846","full_name":"Troopers/MetricsBundle","owner":"Troopers","description":"Symfony Bundle for Metrics management thanks to ELK","archived":false,"fork":false,"pushed_at":"2017-08-04T13:57:43.000Z","size":44,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-01T06:36:45.020Z","etag":null,"topics":["elk","monolog","serializer","symfony","symfony-bundle","troopers"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Troopers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-15T16:03:11.000Z","updated_at":"2022-10-18T19:49:48.000Z","dependencies_parsed_at":"2022-08-24T10:50:56.527Z","dependency_job_id":null,"html_url":"https://github.com/Troopers/MetricsBundle","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/Troopers/MetricsBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Troopers%2FMetricsBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Troopers%2FMetricsBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Troopers%2FMetricsBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Troopers%2FMetricsBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Troopers","download_url":"https://codeload.github.com/Troopers/MetricsBundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Troopers%2FMetricsBundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272475166,"owners_count":24940695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-28T02:00:10.768Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elk","monolog","serializer","symfony","symfony-bundle","troopers"],"created_at":"2024-11-12T09:04:17.864Z","updated_at":"2025-08-28T09:09:21.583Z","avatar_url":"https://github.com/Troopers.png","language":"PHP","readme":"[![Troopers](https://cloud.githubusercontent.com/assets/618536/18787530/83cf424e-81a3-11e6-8f66-cde3ec5fa82a.png)](http://troopers.agency/?utm_source=MetricsBundle\u0026utm_medium=github\u0026utm_campaign=OpenSource)\n\n[![License](https://img.shields.io/packagist/l/troopers/metrics-bundle.svg)](https://packagist.org/packages/troopers/metrics-bundle)\n[![Version](https://img.shields.io/packagist/v/troopers/metrics-bundle.svg)](https://packagist.org/packages/troopers/metrics-bundle)\n[![Packagist DL](https://img.shields.io/packagist/dt/troopers/metrics-bundle.svg)](https://packagist.org/packages/troopers/metrics-bundle)\n[![Build Status](https://travis-ci.org/Troopers/MetricsBundle.svg?branch=master)](https://travis-ci.org/Troopers/MetricsBundle)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/113171b2-e7d1-42ea-86d4-a07be1c468bc/mini.png)](https://insight.sensiolabs.com/projects/113171b2-e7d1-42ea-86d4-a07be1c468bc)\n[![Twitter Follow](https://img.shields.io/twitter/follow/troopersagency.svg?style=social\u0026label=Follow%20Troopers)](https://twitter.com/troopersagency)\n\nMetricsBundle\n=============\n\n## Synopsis\n\nThis bundle works with Monolog and is used to improve monitoring or metric logging process thanks to ELK (Elasticsearch, Logstash, Kibana).\n\n## Install\n\n`composer require troopers/metrics-bundle` and registrer in AppKernel\n\n```php\nclass AppKernel extends Kernel\n{\n    public function registerBundles()\n    {\n        $bundles = array(\n            ...\n            new Troopers\\MetricsBundle\\MetricsBundle(),\n            ...\n        );\n\n        return $bundles\n```\n\nBe sure some serializer is enabled:\n\n- [Symfony serializer](http://symfony.com/doc/current/cookbook/serializer.html#activating-the-serializer).\n- [JMS serializer](http://jmsyst.com/libs/serializer).\n\n## Processors\n\n### UserProcessor\n\nThis processor will automatically add user informations to every log.\nAmong availables informations, we can know if the user is `authenticated` (_authenticated: true/false_), when appropriate his `id` and `username`.\nFurthermore, this processor will check if you defined some serializer groups in the `metrics.serializer_user_groups` config.\n\nThe config below will tell the symfony serializer to serialize the authenticated user by using the profile group:\n```yml\nmetrics:\n    serializer_user_groups:\n      - profile\n```\n\nBy 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.\n\nThe results will be prefixed by `user_` (user_id, user_city...) and you don't need to give any additional context.\n\n### ContextSerializerProcessor\n\nThis processor stands for serializing objects in order to avoid you to pass serializer every where you need to log something.\nTo communicate with this processor and tell it to do its job, you'll need to wrap your objects in a `ContextSerializerProcessor`\nand give them to the contexts like below:\n\n```php\n$logger-\u003einfo('a log with some context object', [\n    new SerializeContextItem($someObject, ['serializingGroupLambda'], 'myalias'),\n    'a_different_simple_context_prop' =\u003e 42,\n    new SerializeContextItem($anotherOne, ['serializingGroup1', 'serializingGroup2']),\n]);\n```\n\nThe 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.\nIf an alias is given, it will use it to store the property, else it will prefix with the class name.\n\n### AlterDateTimeProcessor\n\nFor some reason, you may want to log an event in the past (or future why not ?).\nThe `AlterDateTimeProcessor` will do it for you, all you need to do is to define the `@datetime` context property with the wanted \\DateTime value.\n\n```php\n$logger-\u003einfo('a test in the past', ['@datetime' =\u003e new \\DateTime('10 days ago')]);\n```\n\nBy 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.\n\n### DomainProcessor\n\nIn some case, you need to add some extra information to improve your logs: application name, environment...\nYou can add them in `extra_fields`\n\n```yml\nmetrics:\n    extra_fields:\n        app: 'Acme App'\n        env: 'preprod'\n```\nOnly `scalar`values are allowed. (string, integer, boolean, float, null) \n\nThis processor also add request Uri when she his defined\n \nBy default, this processor is available for all channels.\n\n### GitProcessor\n\nThis processor try to find git revision with git command or in `REVISION` file at the root of application \n\nBy default, this processor is available for all channels.\n\n## Log sandbox\n\nSometime, we just want to send log to test something, this log sandbox to help you to accomplish this small thing.\n\nCheck the metrics routes are registered (in your `app/config/routing.yml` or `routing_dev.yml`):\n```yml\nMetricsBundle:\n    resource: \"@MetricsBundle/Controller/\"\n    type:     annotation\n    prefix:   /metrics\n```\n\nand go to `/metrics/sandbox/newLog` to get your console:\n![Log console sandbox](http://new.tinygrab.com/09b6643d7d41cdfe7be8bac0bc7d5ac2a8c0b4f711.png)\n\n## Dashboard and time filter\n\nOnce you finished to build your dashboard in kibana, you'll be able to get an iframe to embed it in your website.\nTo handle dashboard in your admin with a time filter, add a row in the database like this:\n```sql\nINSERT INTO `metrics_dashboard` (`id`, `name`, `url`, `height`, `width`)\nVALUES (1, 'base', '\u003ciframe src=\"http://your.kibana.url[...]\"\u003e\u003c/iframe\u003e', 768, 1200);\n```\n\nThen, embed the `MetricsBundle:Dashboard:show` and override (or not) the available blocks:\n```twig\n    {% embed 'MetricsBundle:Dashboard:show.html.twig' %}\n        {% block body_title %}\n            Some thing before the title\n            {{ parent() }}\n        {% endblock body_title %}\n        {# disable the timeFilterForm #}\n        {% block body_timeFilterForm %}{% endblock  %}\n    {% endembed %}\n```\n\n### Time filters\n\nKibana doesn't integrate its time filter in embed dashboard. The `TimeFilter` and `TimeFilterForm` is here to navigate into dashboards.\n\nAlthough, TimeFilter is an entity, so you can add some relations between your user and some dashboard.\n\nHere are the available time filters:\n\n- Today\n- This week\n- This month\n- This year\n- Yesterday\n- Day before yesterday\n- Last 15 minutes\n- Last 30 minutes\n- Last 1 hour\n- Last 4 hours\n- Last 12 hours\n- Last 24 hours\n- Last 7 days\n- Last 30 days\n- Last 60 days\n- Last 90 days\n- Last 6 months\n- Last 1 year\n- Last 2 years\n- Last 5 years\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroopers%2Fmetricsbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftroopers%2Fmetricsbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftroopers%2Fmetricsbundle/lists"}