{"id":13530256,"url":"https://github.com/beberlei/metrics","last_synced_at":"2025-04-08T09:05:51.634Z","repository":{"id":3376088,"uuid":"4423633","full_name":"beberlei/metrics","owner":"beberlei","description":"Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.","archived":false,"fork":false,"pushed_at":"2024-03-11T07:50:51.000Z","size":315,"stargazers_count":315,"open_issues_count":12,"forks_count":38,"subscribers_count":15,"default_branch":"3.x","last_synced_at":"2024-05-02T00:23:45.986Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/beberlei.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-05-23T18:20:36.000Z","updated_at":"2024-05-05T07:37:04.286Z","dependencies_parsed_at":"2024-03-11T08:57:40.607Z","dependency_job_id":null,"html_url":"https://github.com/beberlei/metrics","commit_stats":{"total_commits":80,"total_committers":23,"mean_commits":"3.4782608695652173","dds":0.7,"last_synced_commit":"5e76c85a1241cdc111892639301c675d5646c980"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beberlei%2Fmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beberlei%2Fmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beberlei%2Fmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beberlei%2Fmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beberlei","download_url":"https://codeload.github.com/beberlei/metrics/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809963,"owners_count":20999816,"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","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":[],"created_at":"2024-08-01T07:00:46.784Z","updated_at":"2025-04-08T09:05:51.618Z","avatar_url":"https://github.com/beberlei.png","language":"PHP","funding_links":[],"categories":["Table of Contents","Collecting data into InfluxDB","杂项","Miscellaneous","杂项 Miscellaneous","目录","PHP","Configuration"],"sub_categories":["Debugging and Profiling","Libraries","调试和性能分析 Debugging and Profiling","Miscellaneous","Globalization"],"readme":"# Metrics\n\n[![Build Status](https://travis-ci.org/beberlei/metrics.svg?branch=master)](https://travis-ci.org/beberlei/metrics)\n\nSimple library that abstracts different metrics collectors. I find this\nnecessary to have a consistent and simple metrics API that doesn't cause vendor\nlock-in.\n\nIt also ships with a Symfony Bundle. **This is not a library for displaying metrics.**\n\nCurrently supported backends:\n\n* Doctrine DBAL\n* Graphite\n* InfluxDB\n* Telegraf\n* Librato\n* Logger (Psr\\Log\\LoggerInterface)\n* Null (Dummy that does nothing)\n* Prometheus\n* StatsD\n* Zabbix\n* DogStatsD\n\n## Installation\n\nUsing Composer:\n\n```bash\ncomposer require beberlei/metrics\n```\n\n## API\n\nYou can instantiate clients:\n\n```php\n\u003c?php\n\n$collector = \\Beberlei\\Metrics\\Factory::create('statsd');\n```\n\nYou can measure stats:\n\n```php\n\u003c?php\n\n$collector-\u003eincrement('foo.bar');\n$collector-\u003edecrement('foo.bar');\n\n$start = microtime(true);\n$diff  = microtime(true) - $start;\n$collector-\u003etiming('foo.bar', $diff);\n\n$value = 1234;\n$collector-\u003emeasure('foo.bar', $value);\n```\n\nSome backends defer sending and aggregate all information, make sure to call\nflush:\n\n```php\n\u003c?php\n\n$collector-\u003eflush();\n```\n\n## Configuration\n\n```php\n\u003c?php\n$statsd = \\Beberlei\\Metrics\\Factory::create('statsd');\n\n$zabbix = \\Beberlei\\Metrics\\Factory::create('zabbix', array(\n    'hostname' =\u003e 'foo.beberlei.de',\n    'server'   =\u003e 'localhost',\n    'port'     =\u003e 10051,\n));\n\n$zabbixConfig = \\Beberlei\\Metrics\\Factory::create('zabbix_file', array(\n    'hostname' =\u003e 'foo.beberlei.de',\n    'file'     =\u003e '/etc/zabbix/zabbix_agentd.conf'\n));\n\n$librato = \\Beberlei\\Metrics\\Factory::create('librato', array(\n    'hostname' =\u003e 'foo.beberlei.de',\n    'username' =\u003e 'foo',\n    'password' =\u003e 'bar',\n));\n\n$null = \\Beberlei\\Metrics\\Factory::create('null');\n```\n\n## Symfony Bundle Integration\n\nRegister Bundle into Kernel:\n\n```php\n\u003c?php\n\nclass AppKernel extends Kernel\n{\n    public function registerBundles()\n    {\n        //..\n        $bundles[] = new \\Beberlei\\Bundle\\MetricsBundle\\BeberleiMetricsBundle();\n        //..\n    }\n}\n```\n\nDo Configuration:\n\n```yaml\n# app/config/config.yml\nbeberlei_metrics:\n    default: foo\n    collectors:\n        foo:\n            type: statsd\n        bar:\n            type: zabbix\n            prefix: foo.beberlei.de\n            host: localhost\n            port: 10051\n        baz:\n            type: zabbix_file\n            prefix: foo.beberlei.de\n            file: /etc/zabbix/zabbix_agentd.conf\n        librato:\n            type: librato\n            username: foo\n            password: bar\n            source: hermes10\n        dbal:\n            type: doctrine_dbal\n            connection: metrics # using the connection named \"metrics\"\n        monolog:\n            type: monolog\n        influxdb:\n            type: influxdb\n            influxdb_client: influxdb_client_service # using the InfluxDB client service named \"influxdb_client_service\"\n            tags:\n                dc: \"west\"\n                node_instance: \"hermes10\"\n        prometheus:\n            type: prometheus\n            prometheus_collector_registry: prometheus_collector_registry_service # using the Prometheus collector registry service named \"prometheus_collector_registry_service\"\n            namespace: app_name # optional\n            tags:\n                dc: \"west\"\n                node_instance: \"hermes10\"\n```\n\nThis adds collectors to the Metrics registry. The functions are automatically\nincluded in the Bundle class so that in your code you can just start using the\nconvenient functions. Metrics are also added as services:\n\n```php\n\u003c?php\n\n$metrics = $container-\u003eget('beberlei_metrics.collector.foo');\n```\n\nand the default collector can be fetched:\n\n```php\n\u003c?php\n\n$metrics = $container-\u003eget('beberlei_metrics.collector');\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeberlei%2Fmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeberlei%2Fmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeberlei%2Fmetrics/lists"}