{"id":18031655,"url":"https://github.com/artprima/prometheus-metrics-bundle","last_synced_at":"2026-05-21T23:08:43.671Z","repository":{"id":33165936,"uuid":"153795464","full_name":"artprima/prometheus-metrics-bundle","owner":"artprima","description":"Symfony 5/6 Prometheus Metrics Bundle","archived":false,"fork":false,"pushed_at":"2025-06-17T11:24:25.000Z","size":3588,"stargazers_count":158,"open_issues_count":3,"forks_count":37,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-23T23:26:49.849Z","etag":null,"topics":["metrics","prometheus","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/artprima.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-10-19T14:25:55.000Z","updated_at":"2025-09-23T06:38:26.000Z","dependencies_parsed_at":"2024-03-31T18:29:56.458Z","dependency_job_id":"1165eba4-d885-420c-8670-76221832bcd2","html_url":"https://github.com/artprima/prometheus-metrics-bundle","commit_stats":{"total_commits":79,"total_committers":18,"mean_commits":4.388888888888889,"dds":0.4177215189873418,"last_synced_commit":"a65bc8ea46ee813a7e1437f1d83f1c207d84877f"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/artprima/prometheus-metrics-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artprima%2Fprometheus-metrics-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artprima%2Fprometheus-metrics-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artprima%2Fprometheus-metrics-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artprima%2Fprometheus-metrics-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artprima","download_url":"https://codeload.github.com/artprima/prometheus-metrics-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artprima%2Fprometheus-metrics-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510949,"owners_count":25999012,"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-10-05T02:00:06.059Z","response_time":54,"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":["metrics","prometheus","symfony","symfony-bundle"],"created_at":"2024-10-30T10:10:04.573Z","updated_at":"2025-10-05T20:14:42.945Z","avatar_url":"https://github.com/artprima.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"|                    [Master][Master Link]                     |\n|:------------------------------------------------------------:|\n|           [![Build Status][Master PHP image]][Master]        |\n|           [![Build Status][Master Symfony image]][Master]    |\n|           [![Build Status][Master Coding Style image]][Master] |\n| [![Coverage Status][Master coverage image]][Master coverage] |\n\n\nSymfony 5/6/7 Prometheus Metrics Bundle\n=========================================\n\nA Symfony bundle for the `promphp/prometheus_client_php`.\n\nInstallation\n============\n\nApplications that use Symfony Flex\n----------------------------------\n\nOpen a command console, enter your project directory and execute:\n\n```console\ncomposer require artprima/prometheus-metrics-bundle\n```\n\nApplications that don't use Symfony Flex\n----------------------------------------\n\n### Step 1: Download the Bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```console\ncomposer require artprima/prometheus-metrics-bundle\n```\n\nThis command requires you to have Composer installed globally, as explained\nin the [installation chapter](https://getcomposer.org/doc/00-intro.md)\nof the Composer documentation.\n\n### Step 2: Enable the Bundle\n\nThen, enable the bundle by adding it to the list of registered bundles\nin the `app/AppKernel.php` file of your project:\n\n```php\n\u003c?php\n// app/AppKernel.php\n\n// ...\nclass AppKernel extends Kernel\n{\n    public function registerBundles()\n    {\n        $bundles = [\n            // ...\n            new Artprima\\PrometheusMetricsBundle\\ArtprimaPrometheusMetricsBundle(),\n        ];\n\n        // ...\n    }\n\n    // ...\n}\n```\n\nConfiguration\n=============\n\n`config.yaml`\n\n```yaml\nartprima_prometheus_metrics:\n    # namespace is used to prefix the prometheus metrics\n    namespace: myapp\n\n    # ignoring some routes in metrics\n    ignored_routes: [some_route_name, another_route_name]\n\n    # metrics backend\n    storage:\n        # DSN of the storage. All parsed values will override explicitly set parameters. Ex: redis://127.0.0.1?timeout=0.1\n        url: ~\n        \n        # Known values: in_memory, apcu, apcng, redis\n        type: in_memory\n        \n        # Available parameters used by redis\n        host: 127.0.0.1\n        port: 6379\n        timeout: 0.1\n        read_timeout: 10\n        persistent_connections: false\n        password: ~\n        database: ~ # Int value used by redis adapter\n        prefix: ~   # String value used by redis and apcu\n\n        # A variable parameter to define additionnal options as key / value.\n        options:\n            foo: bar\n\n    # used to disable default application metrics\n    disable_default_metrics: false\n\n    # used to disable default metrics from promphp/prometheus_client_php\n    disable_default_promphp_metrics: false\n\n    # used to enable console metrics\n    enable_console_metrics: false\n```\n\nSupported types are:\n| Adapter name | Prometheus class            |\n|--------------|-----------------------------|\n| in_memory    | Prometheus\\Storage\\InMemory |\n| apcu         | Prometheus\\Storage\\APC      |\n| apcng        | Prometheus\\Storage\\APCng    |\n| redis        | Prometheus\\Storage\\Redis    |\n\n\n`routes.yaml`\n\n```yaml\n# expose /metrics/prometheus in your application\napp_metrics:\n    resource: '@ArtprimaPrometheusMetricsBundle/Resources/config/routing.xml'\n```\n\nYou can alternatively define your own path and rules:\n\n```yaml\napp_metrics:\n    path: /mypath/mymetrics\n    controller: Artprima\\PrometheusMetricsBundle\\Controller\\MetricsController::prometheus\n```\n\nNow your metrics are available to Prometheus using http://\u003cyourapp_url\u003e/metrics/prometheus.\n\nCustom Metrics Collector\n========================\n\nIf you want to collect your own metrics, you should create a class that will implement one or several interfaces that are\nthe children of the `Artprima\\PrometheusMetricsBundle\\Metrics\\MetricsCollectorInterface`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Metrics;\n\nuse Artprima\\PrometheusMetricsBundle\\Metrics\\RequestMetricsCollectorInterface;\nuse Artprima\\PrometheusMetricsBundle\\Metrics\\TerminateMetricsCollectorInterface;\nuse Prometheus\\CollectorRegistry;\nuse Symfony\\Component\\HttpKernel\\Event\\RequestEvent;\nuse Symfony\\Component\\HttpKernel\\Event\\TerminateEvent;\n\n/**\n * Class MyMetricsCollector.\n */\nclass MyMetricsCollector implements RequestMetricsCollectorInterface, TerminateMetricsCollectorInterface\n{\n    /**\n     * @var string\n     */\n    private $namespace;\n\n    /**\n     * @var CollectorRegistry\n     */\n    private $collectionRegistry;\n\n    public function init(string $namespace, CollectorRegistry $collectionRegistry): void\n    {\n        $this-\u003enamespace = $namespace;\n        $this-\u003ecollectionRegistry = $collectionRegistry;\n    }\n\n    private function incRequestsTotal(?string $method = null, ?string $route = null): void\n    {\n        $counter = $this-\u003ecollectionRegistry-\u003egetOrRegisterCounter(\n            $this-\u003enamespace,\n            'http_requests_total',\n            'total request count',\n            ['action']\n        );\n\n        $counter-\u003einc(['all']);\n\n        if (null !== $method \u0026\u0026 null !== $route) {\n            $counter-\u003einc([sprintf('%s-%s', $method, $route)]);\n        }\n    }\n\n    private function incResponsesTotal(?string $method = null, ?string $route = null): void\n    {\n        $counter = $this-\u003ecollectionRegistry-\u003egetOrRegisterCounter(\n            $this-\u003enamespace,\n            'http_responses_total',\n            'total response count',\n            ['action']\n        );\n        $counter-\u003einc(['all']);\n\n        if (null !== $method \u0026\u0026 null !== $route) {\n            $counter-\u003einc([sprintf('%s-%s', $method, $route)]);\n        }\n    }\n\n    // called on the `kernel.request` event\n    public function collectRequest(RequestEvent $event): void\n    {\n        $request = $event-\u003egetRequest();\n        $requestMethod = $request-\u003egetMethod();\n        $requestRoute = $request-\u003eattributes-\u003eget('_route');\n\n        // do not track \"OPTIONS\" requests\n        if ('OPTIONS' === $requestMethod) {\n            return;\n        }\n\n        $this-\u003eincRequestsTotal($requestMethod, $requestRoute);\n    }\n\n    // called on the `kernel.terminate` event\n    public function collectResponse(TerminateEvent $event): void\n    {\n        $response = $event-\u003egetResponse();\n        $request = $event-\u003egetRequest();\n\n        $requestMethod = $request-\u003egetMethod();\n        $requestRoute = $request-\u003eattributes-\u003eget('_route');\n\n        $this-\u003eincResponsesTotal($requestMethod, $requestRoute);\n    }\n}\n```\n\nWhen using autoconfigure = true, by implementing `Artprima\\PrometheusMetricsBundle\\Metrics\\MetricsCollectorInterface`\nSymfony will automatically configure your metrics collector to be used by the collector registry.\n\nBy implementing one of the following interfaces you can collect the metrics on one of the listed Symfony kernel events:\n\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\PreRequestMetricsCollectorInterface`\n  - collect metrics on \"kernel.request\" event with a priority of 1024.\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\RequestMetricsCollectorInterface`\n  - collect metrics on \"kernel.request\" event (default priority).\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\PreExceptionMetricsCollectorInterface`\n  - collect metrics on \"kernel.exception\" event with a priority of 1024.\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\ExceptionMetricsCollectorInterface`\n  - collect metrics on \"kernel.exception\" event with (default priority).\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\TerminateMetricsCollectorInterface`\n  - collect metrics on \"kernel.terminate\" event.\n  \nThe following collectors will only work if you define `enable_console_metrics: true` in the bundle configuration:\n\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\ConsoleCommandMetricsCollectorInterface`\n  - collect metrics on \"console.command\" event.\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\ConsoleTerminateMetricsCollectorInterface`\n  - collect metrics on \"console.terminate\" event.\n- `Artprima\\PrometheusMetricsBundle\\Metrics\\ConsoleErrorMetricsCollectorInterface`\n  - collect metrics on \"console.error\" event.\n\nFor advanced usage you can implement `Artprima\\PrometheusMetricsBundle\\Metrics\\MetricsCollectorInterface` directly.\n\nThere is also `Artprima\\PrometheusMetricsBundle\\Metrics\\MetricsCollectorInitTrait` will add the `init` method to your\ncollector.\n\nIf you don't use autoconfigure = true, then you will have to add this to your `services.yaml`:\n\n```yaml\n    App\\Metrics\\MyMetricsCollector:\n        tags:\n            - { name: prometheus_metrics_bundle.metrics_collector }\n```\n\nCustom Storage Adapter Factory\n========================\n\nA storage adapter is an instance of `Prometheus\\Storage\\Adapter`. \nTo create your own storage adapter you should create a custom factory implementing `Artprima\\PrometheusMetricsBundle\\StorageFactory\\StorageFactoryInterface`.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Metrics;\n\nuse Artprima\\PrometheusMetricsBundle\\StorageFactory\\StorageFactoryInterface;\nuse Prometheus\\Storage\\Adapter;\n\nclass DummyFactory implements StorageFactoryInterface\n{\n    public function getName(): string\n    {\n        return 'dummy';\n    }\n\n    public function create(array $options): Adapter\n    {\n        return new Dummy($options);\n    }\n}\n```\n\nSymfony will automatically configure your storage factory with autoconfigure = true and implementing `Artprima\\PrometheusMetricsBundle\\StorageFactory\\StorageFactoryInterface`.\nIf you don't use autoconfigure = true, then you will have to add this to your `services.yaml`:\n\n```yaml\n    App\\Metrics\\DummyFactory:\n        tags:\n            - { name: prometheus_metrics_bundle.adapter_factory }\n```\n\nDefault Metrics\n===============\n\nThese are default metrics exported by the application:\n\n```\n# TYPE php_info gauge\nphp_info{version=\"7.3.25-1+ubuntu18.04.1+deb.sury.org+1\"} 1\n# HELP symfony_http_2xx_responses_total total 2xx response count\n# TYPE symfony_http_2xx_responses_total counter\nsymfony_http_2xx_responses_total{action=\"GET-app_dummy_homepage\"} 1\nsymfony_http_2xx_responses_total{action=\"all\"} 1\n# HELP symfony_http_requests_total total request count\n# TYPE symfony_http_requests_total counter\nsymfony_http_requests_total{action=\"GET-app_dummy_homepage\"} 1\nsymfony_http_requests_total{action=\"all\"} 1\n# HELP symfony_instance_name app instance name\n# TYPE symfony_instance_name gauge\nsymfony_instance_name{instance=\"dev\"} 1\n```\n\nNote that, php_info comes from the underlying library `promphp/prometheus_client_php`. Other metrics are gathered\nby the built-in class `Artprima\\PrometheusMetricsBundle\\Metrics`. Here, in the example we have a prefix `symfony`\nand the metrics show a single request to the root named `app_dummy_homepage`. Symfony instance is named `dev` here.\nInstance name comes from the server var `HOSTNAME` (`$request-\u003eserver-\u003eget('HOSTNAME')`) and defaults to `dev`.\n\nClear Metrics\n=============\n\nThe bundle provides a console command to clear metrics from the storage. Simply run:\n```bash\n./bin/console artprima:prometheus:metrics:clear\n```\n\nContributors\n============\n\n[\u003cimg alt=\"denisvmedia\" src=\"https://avatars.githubusercontent.com/u/5462781?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/denisvmedia) |[\u003cimg alt=\"Johnmeurt\" src=\"https://avatars.githubusercontent.com/u/12075308?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/Johnmeurt) |[\u003cimg alt=\"rmbl\" src=\"https://avatars.githubusercontent.com/u/60907?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/rmbl) |[\u003cimg alt=\"InboxViktorV\" src=\"https://avatars.githubusercontent.com/u/71443952?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/InboxViktorV) |[\u003cimg alt=\"jb-reynaud\" src=\"https://avatars.githubusercontent.com/u/390431?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/jb-reynaud) |[\u003cimg alt=\"luca-nardelli\" src=\"https://avatars.githubusercontent.com/u/6215162?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/luca-nardelli) |\n:---: |:---: |:---: |:---: |:---: |:---: |\n[denisvmedia](https://github.com/denisvmedia) |[Johnmeurt](https://github.com/Johnmeurt) |[rmbl](https://github.com/rmbl) |[InboxViktorV](https://github.com/InboxViktorV) |[jb-reynaud](https://github.com/jb-reynaud) |[luca-nardelli](https://github.com/luca-nardelli) |\n\n[\u003cimg alt=\"alshenetsky\" src=\"https://avatars.githubusercontent.com/u/8052634?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/alshenetsky) |[\u003cimg alt=\"edditor\" src=\"https://avatars.githubusercontent.com/u/7714920?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/edditor) |[\u003cimg alt=\"marein\" src=\"https://avatars.githubusercontent.com/u/1128786?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/marein) |[\u003cimg alt=\"ctrl-f5\" src=\"https://avatars.githubusercontent.com/u/485346?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/ctrl-f5) |[\u003cimg alt=\"ns3777k\" src=\"https://avatars.githubusercontent.com/u/4613880?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/ns3777k) |[\u003cimg alt=\"scrutinizer-auto-fixer\" src=\"https://avatars.githubusercontent.com/u/6253494?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/scrutinizer-auto-fixer) |\n:---: |:---: |:---: |:---: |:---: |:---: |\n[alshenetsky](https://github.com/alshenetsky) |[edditor](https://github.com/edditor) |[marein](https://github.com/marein) |[ctrl-f5](https://github.com/ctrl-f5) |[ns3777k](https://github.com/ns3777k) |[scrutinizer-auto-fixer](https://github.com/scrutinizer-auto-fixer) |\n\n[\u003cimg alt=\"Yozhef\" src=\"https://avatars.githubusercontent.com/u/8971757?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/Yozhef) |[\u003cimg alt=\"karolmalinowski\" src=\"https://avatars.githubusercontent.com/u/28944325?v=4\u0026s=117\" width=\"117\"\u003e](https://github.com/karolmalinowski) |\n:---: |:---: |\n[Yozhef](https://github.com/Yozhef) |[karolmalinowski](https://github.com/karolmalinowski) |\n\n\nCode license\n============\n\nYou are free to use the code in this repository under the terms of the MIT license. LICENSE contains a copy of this license.\n\n  [Master Link]: https://github.com/artprima/prometheus-metrics-bundle/tree/master\n  [Master PHP image]: https://github.com/artprima/prometheus-metrics-bundle/actions/workflows/php.yml/badge.svg?branch=master\n  [Master Symfony image]: https://github.com/artprima/prometheus-metrics-bundle/actions/workflows/symfony.yml/badge.svg?branch=master\n  [Master Coding Style image]: https://github.com/artprima/prometheus-metrics-bundle/actions/workflows/code-style.yml/badge.svg?branch=master\n  [Master]: https://github.com/artprima/prometheus-metrics-bundle/actions?query=workflow%3APHP+branch%3Amaster\n  [Master coverage image]: https://img.shields.io/codecov/c/github/artprima/prometheus-metrics-bundle/master.svg\n  [Master coverage]: https://codecov.io/gh/artprima/prometheus-metrics-bundle\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartprima%2Fprometheus-metrics-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartprima%2Fprometheus-metrics-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartprima%2Fprometheus-metrics-bundle/lists"}