{"id":13463840,"url":"https://github.com/Jimdo/prometheus_client_php","last_synced_at":"2025-03-25T09:31:10.754Z","repository":{"id":56999086,"uuid":"61367092","full_name":"Jimdo/prometheus_client_php","owner":"Jimdo","description":"Prometheus instrumentation library for PHP applications","archived":true,"fork":false,"pushed_at":"2020-01-06T21:15:22.000Z","size":217,"stargazers_count":281,"open_issues_count":40,"forks_count":212,"subscribers_count":75,"default_branch":"master","last_synced_at":"2024-10-29T16:21:49.122Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://prometheus.io/docs/concepts/metric_types/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jimdo.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":"2016-06-17T10:48:44.000Z","updated_at":"2024-10-25T10:45:29.000Z","dependencies_parsed_at":"2022-08-21T13:50:29.841Z","dependency_job_id":null,"html_url":"https://github.com/Jimdo/prometheus_client_php","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimdo%2Fprometheus_client_php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimdo%2Fprometheus_client_php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimdo%2Fprometheus_client_php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jimdo%2Fprometheus_client_php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jimdo","download_url":"https://codeload.github.com/Jimdo/prometheus_client_php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435102,"owners_count":20614829,"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-07-31T14:00:29.175Z","updated_at":"2025-03-25T09:31:08.265Z","avatar_url":"https://github.com/Jimdo.png","language":"PHP","readme":"# :exclamation: New project maintainers :exclamation:\n\nThis project is no longer maintained here. Please go to https://github.com/endclothing/prometheus_client_php.\n\n# A prometheus client library written in PHP\n\n[![Build Status](https://travis-ci.org/Jimdo/prometheus_client_php.svg?branch=master)](https://travis-ci.org/Jimdo/prometheus_client_php)\n\nThis library uses Redis or APCu to do the client side aggregation.\nIf using Redis, we recommend to run a local Redis instance next to your PHP workers.\n\n## How does it work?\n\nUsually PHP worker processes don't share any state.\nYou can pick from three adapters.\nRedis, APC or an in memory adapter.\nWhile the first needs a separate binary running, the second just needs the [APC](https://pecl.php.net/package/APCU) extension to be installed. If you don't need persistent metrics between requests (e.g. a long running cron job or script) the in memory adapter might be suitable to use.\n\n## Usage\n\nA simple counter:\n```php\n\\Prometheus\\CollectorRegistry::getDefault()\n    -\u003egetOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement')\n    -\u003einc();\n```\n\nWrite some enhanced metrics:\n```php\n$registry = \\Prometheus\\CollectorRegistry::getDefault();\n\n$counter = $registry-\u003egetOrRegisterCounter('test', 'some_counter', 'it increases', ['type']);\n$counter-\u003eincBy(3, ['blue']);\n\n$gauge = $registry-\u003egetOrRegisterGauge('test', 'some_gauge', 'it sets', ['type']);\n$gauge-\u003eset(2.5, ['blue']);\n\n$histogram = $registry-\u003egetOrRegisterHistogram('test', 'some_histogram', 'it observes', ['type'], [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]);\n$histogram-\u003eobserve(3.5, ['blue']);\n```\n\nManually register and retrieve metrics (these steps are combined in the `getOrRegister...` methods):\n```php\n$registry = \\Prometheus\\CollectorRegistry::getDefault();\n\n$counterA = $registry-\u003eregisterCounter('test', 'some_counter', 'it increases', ['type']);\n$counterA-\u003eincBy(3, ['blue']);\n\n// once a metric is registered, it can be retrieved using e.g. getCounter:\n$counterB = $registry-\u003egetCounter('test', 'some_counter')\n$counterB-\u003eincBy(2, ['red']);\n```\n\nExpose the metrics:\n```php\n$registry = \\Prometheus\\CollectorRegistry::getDefault();\n\n$renderer = new RenderTextFormat();\n$result = $renderer-\u003erender($registry-\u003egetMetricFamilySamples());\n\nheader('Content-type: ' . RenderTextFormat::MIME_TYPE);\necho $result;\n```\n\nChange the Redis options (the example shows the defaults):\n```php\n\\Prometheus\\Storage\\Redis::setDefaultOptions(\n    [\n        'host' =\u003e '127.0.0.1',\n        'port' =\u003e 6379,\n        'password' =\u003e null,\n        'timeout' =\u003e 0.1, // in seconds\n        'read_timeout' =\u003e 10, // in seconds\n        'persistent_connections' =\u003e false\n    ]\n);\n```\n\nUsing the InMemory storage:\n```php\n$registry = new CollectorRegistry(new InMemory());\n\n$counter = $registry-\u003eregisterCounter('test', 'some_counter', 'it increases', ['type']);\n$counter-\u003eincBy(3, ['blue']);\n\n$renderer = new RenderTextFormat();\n$result = $renderer-\u003erender($registry-\u003egetMetricFamilySamples());\n```\n\nAlso look at the [examples](examples).\n\n## Development\n\n### Dependencies\n\n* PHP 5.6\n* PHP Redis extension\n* PHP APCu extension\n* [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)\n* Redis\n\nStart a Redis instance:\n```\ndocker-compose up Redis\n```\n\nRun the tests:\n```\ncomposer install\n\n# when Redis is not listening on localhost:\n# export REDIS_HOST=192.168.59.100\n./vendor/bin/phpunit\n```\n\n## Black box testing\n\nJust start the nginx, fpm \u0026 Redis setup with docker-compose:\n```\ndocker-compose up\n```\nPick the adapter you want to test.\n\n```\ndocker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/\ndocker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/\n```\n","funding_links":[],"categories":["Performance","PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJimdo%2Fprometheus_client_php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJimdo%2Fprometheus_client_php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJimdo%2Fprometheus_client_php/lists"}