{"id":26950992,"url":"https://github.com/ns3777k/prometheus-bundle","last_synced_at":"2026-03-04T17:32:29.292Z","repository":{"id":57028962,"uuid":"238806283","full_name":"ns3777k/prometheus-bundle","owner":"ns3777k","description":"Symfony bundle for collecting and exposing prometheus metrics","archived":false,"fork":false,"pushed_at":"2020-03-11T23:00:06.000Z","size":27,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T23:35:28.083Z","etag":null,"topics":["metrics","php","prometheus","prometheus-bundle","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/ns3777k.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-06T23:32:22.000Z","updated_at":"2024-05-21T14:23:59.000Z","dependencies_parsed_at":"2022-08-23T16:20:44.323Z","dependency_job_id":null,"html_url":"https://github.com/ns3777k/prometheus-bundle","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ns3777k/prometheus-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ns3777k%2Fprometheus-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ns3777k%2Fprometheus-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ns3777k%2Fprometheus-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ns3777k%2Fprometheus-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ns3777k","download_url":"https://codeload.github.com/ns3777k/prometheus-bundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ns3777k%2Fprometheus-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30087362,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T15:40:14.053Z","status":"ssl_error","status_checked_at":"2026-03-04T15:40:13.655Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","php","prometheus","prometheus-bundle","symfony","symfony-bundle"],"created_at":"2025-04-02T23:35:24.845Z","updated_at":"2026-03-04T17:32:29.240Z","avatar_url":"https://github.com/ns3777k.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prometheus bundle\n\n[![Build Status](https://travis-ci.org/ns3777k/prometheus-bundle.svg?branch=master)](https://travis-ci.org/ns3777k/prometheus-bundle)\n[![codecov](https://codecov.io/gh/ns3777k/prometheus-bundle/branch/master/graph/badge.svg)](https://codecov.io/gh/ns3777k/prometheus-bundle)\n\n## Requirements\n\n- PHP 7.3+\n- Symfony 4+\n\n## Installing\n\nThere are 2 ways to install the bundle: automatically with flex or manually.\n\n### Using symfony flex\n\n```shell script\n$ composer require ns3777k/prometheus-bundle\n```\n\n### Manually\n\n1. Require the package:\n\n```shell script\n$ composer require ns3777k/prometheus-bundle\n```\n\n2. Register the bundle in `config/bundles.php`:\n\n```php\n\u003c?php\n\nreturn [\n    // ...\n    Ns3777k\\PrometheusBundle\\Ns3777kPrometheusBundle::class =\u003e ['all' =\u003e true],\n];\n```\n\n3. Configure (see below)\n\n## Usage\n\n### Configuration\n\n`config/packages/ns3777k_prometheus.yaml`:\n\n```yaml\nns3777k_prometheus:\n  namespace: app\n  adapter: in_memory # or apcu or redis\n\n  # listener (read below)\n  listener:\n    enabled: true\n    ignored_routes: []\n\n  # redis adapter settings\n  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:\n```\n\nTo register the metrics route, add to `config/routes.yaml`:\n\n```yaml\nmetrics:\n  path: /metrics\n  controller: 'Ns3777k\\PrometheusBundle\\Controller\\MetricsController::prometheus'\n```\n\nor:\n\n```yaml\nmetrics:\n  resource: '@Ns3777kPrometheusBundle/Resources/config/routing.xml'\n```\n\n### Builtin listener\n\nBy default the listener is turned on and collects only one histogram with\nrequest duration in seconds (`request_duration_seconds`) with 3 labels: `code`,\n`method` and `route`.\n\nHistogram creates `total` and `count` metrics automatically.\n\nUsually you don't wanna collect the metrics for routes like `_wdt` and `metrics`\n(that's the route for `/metrics`) and that's where `listener.ignored_routes`\ncomes in.\n\nCommon PromQL queries for the listener:\n\n- HTTP Request Rate\n\n```\nrate(request_duration_seconds_sum[5m]) / rate(request_duration_seconds_count[5m])\n```\n\n- HTTP Successful Responses\n\n```\nrequest_duration_seconds_count{code=~\"(2|3).*\"}\n```\n\n- HTTP Failed Responses\n\n```\nrequest_duration_seconds_count{code=~\"(4|5).*\"}\n```\n\n- HTTP Success Response Time 5m 95p\n\n```\nhistogram_quantile(0.95, rate(request_duration_seconds_bucket{code=~\"(2|3).*\"}[5m]))\n```\n\n### Collect own metrics\n\nBuiltin listener covers only basic information about the request and response.\nYou can use it to get top 10 requests, slow responses, calculate request rate\nand etc.\n\nBut most of the time you wanna collect your own metrics. It's easy to do using\n`CollectorRegistryInterface` (implemented by `NamespacedCollectorRegistry`).\n\nHistogram example:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Weather;\n\nuse Ns3777k\\PrometheusBundle\\Metrics\\CollectorRegistryInterface;\n\nclass WeatherClient\n{\n    private $registry;\n\n    public function __construct(CollectorRegistryInterface $registry)\n    {\n        $this-\u003eregistry = $registry;\n    }\n\n    public function getWeatherForRegion(string $region)\n    {\n        $histogram = $this-\u003eregistry-\u003egetOrRegisterHistogram(\n            'weather_request_duration_seconds',\n            'Weather request duration with response information',\n            ['region']\n        );\n\n        $start = microtime(true);\n        // do request\n        $duration = microtime(true) - $start;\n\n        $histogram-\u003eobserve($duration, [$region]);\n    }\n\n}\n```\n\nNo worries about the namespace. It will be prepended automatically from the\nbundle's configuration.\n\n## Security\n\nRemember that when you add `/metrics` route it becomes publicly available from\nthe internet.\n\n**It's you job to restrict access to it (using nginx for example).**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fns3777k%2Fprometheus-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fns3777k%2Fprometheus-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fns3777k%2Fprometheus-bundle/lists"}