{"id":15023283,"url":"https://github.com/bexiocom/prometheus_php","last_synced_at":"2025-04-09T19:53:05.797Z","repository":{"id":62493708,"uuid":"101174050","full_name":"bexiocom/prometheus_php","owner":"bexiocom","description":"A PHP instrumentation library for Prometheus compatible with PHP 5.5 5.6, 7.0 and 7.1.","archived":false,"fork":false,"pushed_at":"2017-08-31T18:54:44.000Z","size":53,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T21:51:53.122Z","etag":null,"topics":["monitoring","php","php5","php55","php7","php70","php71","prometheus"],"latest_commit_sha":null,"homepage":"https://bexiocom.github.io/prometheus_php/","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/bexiocom.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":"2017-08-23T11:46:46.000Z","updated_at":"2022-02-12T08:00:40.000Z","dependencies_parsed_at":"2022-11-02T11:31:19.463Z","dependency_job_id":null,"html_url":"https://github.com/bexiocom/prometheus_php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bexiocom%2Fprometheus_php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bexiocom%2Fprometheus_php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bexiocom%2Fprometheus_php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bexiocom%2Fprometheus_php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bexiocom","download_url":"https://codeload.github.com/bexiocom/prometheus_php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103915,"owners_count":21048245,"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":["monitoring","php","php5","php55","php7","php70","php71","prometheus"],"created_at":"2024-09-24T19:58:54.525Z","updated_at":"2025-04-09T19:53:05.781Z","avatar_url":"https://github.com/bexiocom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Prometheus client library for PHP\n\n[![Build Status](https://img.shields.io/travis/bexiocom/prometheus_php.svg)](https://travis-ci.org/bexiocom/prometheus_php)\n[![Code Climate](https://img.shields.io/codeclimate/github/bexiocom/prometheus_php.svg)](https://codeclimate.com/github/bexiocom/prometheus_php)\n[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/bexiocom/prometheus_php.svg)](https://codeclimate.com/github/bexiocom/prometheus_php/coverage)\n[![Latest Stable Version](https://img.shields.io/packagist/v/bexiocom/prometheus_php.svg)](https://packagist.org/packages/bexiocom/prometheus_php)\n\nThis library aims to be a lightweight utility for instrumenting a PHP\napplication using [Prometheus](https://prometheus.io). It is heavily inspired\nby the [golang client](https://github.com/prometheus/client_golang).\n\n- The library is supposed to be compatible with the PHP version 5.5, 5.6, 7.0\n  and 7.1.\n- This library tries to do not take any assumptions about the environment it is\n  used in. You should be able to use it without any magic or with what ever\n  tool belt you are using. Be it a lightweight dependency injection, Sympfony\n  or something else.\n  \n## Features\n\n- Counter, Gauge and Histogram metric types.\n- Redis and in memory storage.\n- Rendering to text format.\n\n## Missing features\n\n- Summary metric types.\n- Ability to submit metric samples to a PushGateway.\n- Storage utilising filesystem, Memcached and APC.\n- Rendering to Protocol buffer format\n- Registry class to ease usage when using the library without andy dependency\n  injection tool.\n  \n## Getting Started\n\nAdd this library to your project.\n\n```bash\ncomposer require bexiocom/prometheus_php:dev-master\n```\n\n## Usage\n\nSimple counter with no labels attached:\n\n```php\n\u003c?php\n\nuse Bexio\\PrometheusPHP\\Metric\\Counter;\nuse Bexio\\PrometheusPHP\\Storage\\InMemory;\n\n$storage = new InMemory();\n$counter = Counter::createFromValues('simple_counter', 'Just a simple counting');\n$counter-\u003einc();\n$storage-\u003epersist($counter);\n```\n\nMore enhanced counter with labels:\n\n```php\n\u003c?php\n\nuse Bexio\\PrometheusPHP\\Metric\\CounterCollection;\nuse Bexio\\PrometheusPHP\\Storage\\InMemory;\n\n$storage = new InMemory();\n$collection = CounterCollection::createFromValues('labeled_counter', 'Counting with labels', ['type']);\n$blueCounter = $collection-\u003ewithLabels(['type' =\u003e 'blue']);\n$blueCounter-\u003einc();\n$redCounter = $collection-\u003ewithLabels(['type' =\u003e 'red']);\n$redCounter-\u003eadd(42);\n$storage-\u003epersist($collection);\n```\n\nExpose the metrics:\n\n```php\n\u003c?php\n\nuse Bexio\\PrometheusPHP\\Metric\\Counter;\nuse Bexio\\PrometheusPHP\\Metric\\CounterCollection;\nuse Bexio\\PrometheusPHP\\Output\\TextRenderer;\nuse Bexio\\PrometheusPHP\\Storage\\InMemory;\nuse GuzzleHttp\\Stream\\BufferStream;\n\n$buffer = new BufferStream();\n$renderer = TextRenderer::createFromStream($buffer);\n$storage = new InMemory([\n    'simple_counter' =\u003e [\n        InMemory::DEFAULT_VALUE_INDEX =\u003e 1\n    ],\n    'labeled_counter' =\u003e [\n        '{\"type\":\"blue\"}' =\u003e 1,\n        '{\"type\":\"red\"}' =\u003e 42,\n    ],\n]);\n$counter = Counter::createFromValues('simple_counter', 'Just a simple counting');\n$renderer-\u003erender($counter, $storage-\u003ecollectSamples($counter));\n$collection = CounterCollection::createFromValues('labeled_counter', 'Counting with labels', ['type']);\n$renderer-\u003erender($collection, $storage-\u003ecollectSamples($collection));\n\nheader(sprintf('Content-Type: %s', TextRenderer::MIME_TYPE));\necho $buffer-\u003egetContents();\n```\n\nUse Redis as storage backend:\n\n\u003e NOTE: When using the Redis storage, it is highly suggested to add ```ext-redis``` as requirement to your project. \n\n```php\n\u003c?php\n\nuse Bexio\\PrometheusPHP\\Storage\\Redis;\n\n$redis = new \\Redis();\n$redis-\u003econnect('localhost');\n// Optional: tune your redis connection.\n$redis-\u003esetOption(\\Redis::OPT_READ_TIMEOUT, 10);\n$storage = new Redis($redis, 'PROMETHEUS:');\n```\nUse Redis but open connection lacily:\n\n```php\n\u003c?php\n\nuse Bexio\\PrometheusPHP\\Storage\\Redis;\n\n$redis = new \\Redis();\n$storage = new Redis(new \\Redis(), 'PROMETHEUS:', function(\\Redis $redis) {\n  if (!$redis-\u003econnect('localhost')) {\n      throw new \\Exception('Failed to connect to Redis server');\n  }\n  $redis-\u003esetOption(\\Redis::OPT_READ_TIMEOUT, 10);\n});\n```\n## How to contribute\n\nFirst off, thank you for considering contributing to this PHP Prometheus client\nlibrary. It's people like you that make it useful for more than a handful of\npeople.\n\nPull requests are happily accepted, given they follow the following simple\nrules:\n\n- New feature must be covered with tests\n- All tests must pass\n    ```bash\n    composer check\n    ```\n- Do not mix things up. Only one feature/fix per pull request.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbexiocom%2Fprometheus_php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbexiocom%2Fprometheus_php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbexiocom%2Fprometheus_php/lists"}