2017 © Pedro Peláez
 

library prometheus_client_php

image

jimdo/prometheus_client_php

  • Monday, March 19, 2018
  • by jimdo-dev
  • Repository
  • 33 Watchers
  • 139 Stars
  • 183,696 Installations
  • PHP
  • 10 Dependents
  • 1 Suggesters
  • 69 Forks
  • 20 Open issues
  • 23 Versions
  • 36 % Grown

The README.md

:exclamation: New project maintainers :exclamation:

This project is no longer maintained here. Please go to https://github.com/endclothing/prometheus_client_php., (*1)

A prometheus client library written in PHP

Build Status, (*2)

This library uses Redis or APCu to do the client side aggregation. If using Redis, we recommend to run a local Redis instance next to your PHP workers., (*3)

How does it work?

Usually PHP worker processes don't share any state. You can pick from three adapters. Redis, APC or an in memory adapter. While the first needs a separate binary running, the second just needs the APC 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., (*4)

Usage

A simple counter:, (*5)

\Prometheus\CollectorRegistry::getDefault()
    ->getOrRegisterCounter('', 'some_quick_counter', 'just a quick measurement')
    ->inc();

Write some enhanced metrics:, (*6)

$registry = \Prometheus\CollectorRegistry::getDefault();

$counter = $registry->getOrRegisterCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(3, ['blue']);

$gauge = $registry->getOrRegisterGauge('test', 'some_gauge', 'it sets', ['type']);
$gauge->set(2.5, ['blue']);

$histogram = $registry->getOrRegisterHistogram('test', 'some_histogram', 'it observes', ['type'], [0.1, 1, 2, 3.5, 4, 5, 6, 7, 8, 9]);
$histogram->observe(3.5, ['blue']);

Manually register and retrieve metrics (these steps are combined in the getOrRegister... methods):, (*7)

$registry = \Prometheus\CollectorRegistry::getDefault();

$counterA = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counterA->incBy(3, ['blue']);

// once a metric is registered, it can be retrieved using e.g. getCounter:
$counterB = $registry->getCounter('test', 'some_counter')
$counterB->incBy(2, ['red']);

Expose the metrics:, (*8)

$registry = \Prometheus\CollectorRegistry::getDefault();

$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());

header('Content-type: ' . RenderTextFormat::MIME_TYPE);
echo $result;

Change the Redis options (the example shows the defaults):, (*9)

\Prometheus\Storage\Redis::setDefaultOptions(
    [
        'host' => '127.0.0.1',
        'port' => 6379,
        'password' => null,
        'timeout' => 0.1, // in seconds
        'read_timeout' => 10, // in seconds
        'persistent_connections' => false
    ]
);

Using the InMemory storage:, (*10)

$registry = new CollectorRegistry(new InMemory());

$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(3, ['blue']);

$renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());

Also look at the examples., (*11)

Development

Dependencies

  • PHP 5.6
  • PHP Redis extension
  • PHP APCu extension
  • Composer
  • Redis

Start a Redis instance:, (*12)

docker-compose up Redis

Run the tests:, (*13)

composer install

# when Redis is not listening on localhost:
# export REDIS_HOST=192.168.59.100
./vendor/bin/phpunit

Black box testing

Just start the nginx, fpm & Redis setup with docker-compose:, (*14)

docker-compose up

Pick the adapter you want to test., (*15)

docker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/

The Versions

19/03 2018

dev-master

9999999-dev

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

19/03 2018

dev-php7

dev-php7

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

06/11 2017

v0.9.1

0.9.1.0

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

04/04 2017

v0.9.0

0.9.0.0

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

21/12 2016

v0.8.0

0.8.0.0

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

11/10 2016

v0.7.0

0.7.0.0

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

11/10 2016

dev-pushgateway

dev-pushgateway

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by Joscha
by Jan Brauer

07/09 2016

v0.6.0

0.6.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.3

 

The Development Requires

by Joscha
by Jan Brauer

07/09 2016

dev-apc_storage

dev-apc_storage

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.3

 

The Development Requires

by Joscha
by Jan Brauer

15/07 2016

v0.5.1

0.5.1.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

13/07 2016

v0.5.0

0.5.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

13/07 2016

dev-optimize-metrics-storage

dev-optimize-metrics-storage

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

11/07 2016

v0.4.5

0.4.5.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

11/07 2016

dev-optimizations

dev-optimizations

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

08/07 2016

v0.4.4

0.4.4.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

08/07 2016

v0.4.3

0.4.3.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

08/07 2016

v0.4.2

0.4.2.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

07/07 2016

v0.4.1

0.4.1.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

07/07 2016

v0.4.0

0.4.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

06/07 2016

v0.3.0

0.3.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

01/07 2016

v0.2.1

0.2.1.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

24/06 2016

v0.2.0

0.2.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.3
  • ext-redis *

 

The Development Requires

by Joscha

24/06 2016

v0.1.0

0.1.0.0

  Sources   Download

Apache-2.0

The Requires

  • php >=5.6.0
  • ext-redis *

 

The Development Requires

by Joscha