├── docs ├── 0.1.0 │ ├── opensearch.xml │ ├── PROJECT_VERSION │ ├── SAMI_VERSION │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ ├── renderer.index │ ├── interfaces.html │ ├── traits.html │ ├── index.html │ ├── namespaces.html │ ├── PHPProm │ │ ├── Integration.html │ │ ├── Storage.html │ │ ├── PrometheusExport.html │ │ ├── Integration │ │ │ └── SilexSetup.html │ │ ├── StopWatch.html │ │ └── Storage │ │ │ ├── AbstractStorage.html │ │ │ ├── Memcached.html │ │ │ └── DBAL.html │ ├── PHPProm.html │ ├── search.html │ ├── classes.html │ ├── css │ │ └── sami.css │ └── doc-index.html └── grafana.png ├── .gitignore ├── samiConf.php ├── CHANGELOG.md ├── tests ├── bootstrap.php └── PHPPromTests │ ├── Storage │ ├── MemcachedTest.php │ ├── RedisTest.php │ ├── DBALSQLiteTest.php │ ├── AbstractDBALTest.php │ ├── DBALMySQLTest.php │ ├── DBALPostgreSQLTest.php │ ├── MongoDBTest.php │ └── AbstractStorageTest.php │ ├── StopWatchTest.php │ ├── PrometheusExportTest.php │ └── Integration │ └── SilexSetupTest.php ├── .travis.yml ├── LICENSE ├── composer.json ├── phpunit.xml.dist ├── src └── PHPProm │ ├── StopWatch.php │ ├── Storage │ ├── Redis.php │ ├── Memcached.php │ ├── AbstractStorage.php │ ├── MongoDB.php │ └── DBAL.php │ ├── PrometheusExport.php │ └── Integration │ ├── Slim3Setup.php │ └── SilexSetup.php └── README.md /docs/0.1.0/opensearch.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/0.1.0/PROJECT_VERSION: -------------------------------------------------------------------------------- 1 | master -------------------------------------------------------------------------------- /docs/0.1.0/SAMI_VERSION: -------------------------------------------------------------------------------- 1 | 3.3.0-DEV -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | cache 3 | build 4 | vendor 5 | coverageReport 6 | -------------------------------------------------------------------------------- /docs/grafana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiplb/PHPProm/HEAD/docs/grafana.png -------------------------------------------------------------------------------- /docs/0.1.0/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiplb/PHPProm/HEAD/docs/0.1.0/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /docs/0.1.0/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiplb/PHPProm/HEAD/docs/0.1.0/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /docs/0.1.0/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philiplb/PHPProm/HEAD/docs/0.1.0/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /samiConf.php: -------------------------------------------------------------------------------- 1 | 'PHPProm API' 7 | ]); 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | PHPProm Changelog 2 | ================= 3 | 4 | ## 0.2.0 5 | Released: Upcoming 6 | 7 | - The Silex integration now supports match() routes, too. 8 | 9 | ## 0.1.0 10 | Released: 2016-11-20 11 | 12 | First release. 13 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | $loader = require __DIR__.'/../vendor/autoload.php'; 13 | $loader->add('PHPPromTests', __DIR__); -------------------------------------------------------------------------------- /docs/0.1.0/renderer.index: -------------------------------------------------------------------------------- 1 | C:19:"Sami\Renderer\Index":768:{a:3:{i:0;a:8:{s:30:"PHPProm\Integration\SilexSetup";s:40:"e10cdaf39d94607be19ab391ea132a126c9e89bd";s:24:"PHPProm\PrometheusExport";s:40:"bbb54df083a75353b70cf48781532f9bcc88a511";s:17:"PHPProm\StopWatch";s:40:"d5f107b7b03335f55808fc91606a5e708d8d6b5b";s:31:"PHPProm\Storage\AbstractStorage";s:40:"cb441ae8369661b6915aaaf470f95367532d83b4";s:20:"PHPProm\Storage\DBAL";s:40:"4d95f575fa671c68534e79e06bfea66791a6d182";s:25:"PHPProm\Storage\Memcached";s:40:"c8e9380ac01a3c61726fcd5c278af85ccb0c7a59";s:23:"PHPProm\Storage\MongoDB";s:40:"8eed9edadaf31e0772279af1d649b143eca6a2af";s:21:"PHPProm\Storage\Redis";s:40:"96d443ee8e477225fb6011fb76a45fd9667b1378";}i:1;a:1:{i:0;s:6:"master";}i:2;a:3:{i:0;s:7:"PHPProm";i:1;s:19:"PHPProm\Integration";i:2;s:15:"PHPProm\Storage";}}} -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of the PHPProm package. 3 | # 4 | # (c) Philip Lehmann-Böhm 5 | # 6 | # For the full copyright and license information, please view the LICENSE 7 | # file that was distributed with this source code. 8 | # 9 | 10 | language: php 11 | services: 12 | - memcached 13 | - redis-server 14 | - mysql 15 | - postgresql 16 | - mongodb 17 | before_script: 18 | - echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 19 | - echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 20 | - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini 21 | - mysql -e 'CREATE DATABASE phppromtest;' 22 | - composer install 23 | script: vendor/bin/phpunit 24 | php: 25 | - 5.5.37 26 | - 5.6.25 27 | - 7 28 | after_script: 29 | - php vendor/bin/coveralls -v 30 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/MemcachedTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\Memcached; 15 | 16 | class MemcachedTest extends AbstractStorageTest { 17 | 18 | protected $memcached; 19 | 20 | protected function setUp() { 21 | $this->storage = new Memcached('localhost'); 22 | $this->memcached = new \Memcached(); 23 | $this->memcached->addServer('localhost', 11211); 24 | $this->memcached->delete('PHPProm:metric:key'); 25 | $this->memcached->delete('PHPProm:metric:incrementKey'); 26 | } 27 | 28 | protected function getRawKey($key) { 29 | return $this->memcached->get('PHPProm:'.$key); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/RedisTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\Redis; 15 | 16 | class RedisTest extends AbstractStorageTest { 17 | 18 | protected $redis; 19 | 20 | protected function setUp() { 21 | $this->storage = new Redis('localhost', '', 6379, 'PHPProm:', 0); 22 | $this->redis = new \Redis(); 23 | $this->redis->connect('localhost'); 24 | $this->redis->setOption(\Redis::OPT_PREFIX, 'PHPProm:'); 25 | $this->redis->delete('metric:key'); 26 | $this->redis->delete('metric:incrementKey'); 27 | } 28 | 29 | protected function getRawKey($key) { 30 | return (int)$this->redis->get($key); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/DBALSQLiteTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\DBAL; 15 | 16 | class DBALSQLiteTest extends AbstractDBALTest { 17 | 18 | protected function setUp() { 19 | $connectionParams = array( 20 | 'url' => 'sqlite:///:memory:', 21 | ); 22 | $this->connectToDatabase($connectionParams); 23 | 24 | $sql = 'DROP TABLE IF EXISTS `phpprom`'; 25 | $this->database->executeUpdate($sql); 26 | $sql = 'CREATE TABLE `phpprom` ( 27 | `key` TEXT NOT NULL UNIQUE, 28 | `value` REAL NOT NULL, 29 | PRIMARY KEY(`key`) 30 | );'; 31 | $this->database->executeUpdate($sql); 32 | $this->storage = new DBAL($this->database); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2016 Philip Lehmann-Böhm philip@philiplb.de 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/AbstractDBALTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | abstract class AbstractDBALTest extends AbstractStorageTest { 15 | 16 | protected $database; 17 | 18 | protected $esc; 19 | 20 | protected function connectToDatabase($connectionParams) { 21 | $config = new \Doctrine\DBAL\Configuration(); 22 | $this->database = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); 23 | $this->esc = '`'; 24 | } 25 | 26 | protected function getRawKey($key) { 27 | $sql = 'SELECT '.$this->esc.'value'.$this->esc.' FROM '.$this->esc.'phpprom'.$this->esc.' WHERE '.$this->esc.'key'.$this->esc.' = ?'; 28 | $result = $this->database->fetchAssoc($sql, [$key]); 29 | return (int)$result['value']; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "philiplb/phpprom", 3 | "type": "library", 4 | "description": "PHPProm is a library to measure some performance relevant metrics and expose them for Prometheus", 5 | "keywords": ["silex", "performance measurement", "prometheus"], 6 | "homepage": "https://github.com/philiplb/PHPProm", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Philip Lehmann-Boehm", 11 | "email": "philip@philiplb.de" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { "PHPProm\\": "src/PHPProm" } 16 | }, 17 | "extra": { 18 | "branch-alias": { 19 | "dev-master": "0.2.x-dev" 20 | } 21 | }, 22 | "require": { 23 | "php": ">=5.5" 24 | }, 25 | "require-dev": { 26 | "sami/sami": "^3.3", 27 | "phpunit/phpunit": "^4.8", 28 | "eloquent/phony": "^0.14.1", 29 | "satooshi/php-coveralls": "1.0.1", 30 | "doctrine/dbal": "^2.5", 31 | "silex/silex": "^2.0", 32 | "symfony/browser-kit": "^3.1", 33 | "symfony/css-selector": "^3.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/DBALMySQLTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\DBAL; 15 | 16 | class DBALMySQLTest extends AbstractDBALTest { 17 | 18 | protected function setUp() { 19 | $connectionParams = array( 20 | 'url' => 'mysql://root:@localhost/phppromtest', 21 | ); 22 | $this->connectToDatabase($connectionParams); 23 | 24 | $sql = 'DROP TABLE IF EXISTS `phpprom`'; 25 | $this->database->executeUpdate($sql); 26 | $sql = 'CREATE TABLE `phpprom` ( 27 | `key` varchar(255) NOT NULL, 28 | `value` double NOT NULL, 29 | PRIMARY KEY (`key`) 30 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8'; 31 | $this->database->executeUpdate($sql); 32 | 33 | $this->storage = new DBAL($this->database); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /tests/PHPPromTests/StopWatchTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests; 13 | 14 | use Eloquent\Phony\Phpunit\Phony; 15 | use PHPProm\StopWatch; 16 | 17 | class StopWatchTest extends \PHPUnit_Framework_TestCase { 18 | 19 | public function testStartStop() { 20 | $storageHandle = Phony::mock('\\PHPProm\\Storage\\AbstractStorage'); 21 | $storageMock = $storageHandle->get(); 22 | 23 | $stopWatch = new StopWatch($storageMock); 24 | $stopWatch->start(); 25 | sleep(1); 26 | $stopWatch->stop('prefix', 'key'); 27 | 28 | $storageHandle->storeMeasurement->once()->called(); 29 | $call = $storageHandle->storeMeasurement->firstCall(); 30 | $arguments = $call->arguments(); 31 | $this->assertSame('prefix', $arguments->get(0)); 32 | $this->assertSame('key', $arguments->get(1)); 33 | $this->assertTrue(abs($arguments->get(2) - 1.0) < 0.01); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/DBALPostgreSQLTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\DBAL; 15 | 16 | class DBALPostgreSQLTest extends AbstractDBALTest { 17 | 18 | protected function setUp() { 19 | $connectionParams = array( 20 | 'url' => 'postgresql://localhost:5432/postgres', 21 | ); 22 | $this->connectToDatabase($connectionParams); 23 | $this->esc = '"'; 24 | 25 | 26 | $sql = 'DROP TABLE IF EXISTS phpprom'; 27 | $this->database->executeUpdate($sql); 28 | $sql = 'CREATE TABLE public.phpprom ( 29 | key VARCHAR(255) PRIMARY KEY NOT NULL, 30 | value DOUBLE PRECISION NOT NULL 31 | )'; 32 | $this->database->executeUpdate($sql); 33 | $sql = 'CREATE UNIQUE INDEX phpprom_key_uindex ON public.phpprom (key);'; 34 | $this->database->executeUpdate($sql); 35 | 36 | $this->storage = new DBAL($this->database); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 22 | ./tests/PHPPromTests/ 23 | 24 | 25 | 26 | 27 | ./src 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/MongoDBTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | use PHPProm\Storage\MongoDB; 15 | 16 | class MongoDBTest extends AbstractStorageTest { 17 | 18 | protected $mongoDBManager; 19 | 20 | protected function setUp() { 21 | $this->storage = new MongoDB('mongodb://localhost:27017'); 22 | $this->mongoDBManager = new \MongoDB\Driver\Manager('mongodb://localhost:27017'); 23 | 24 | $bulkDelete = new \MongoDB\Driver\BulkWrite; 25 | $bulkDelete->delete(['key' => 'metric:key']); 26 | $bulkDelete->delete(['key' => 'metric:incrementKey']); 27 | $this->mongoDBManager->executeBulkWrite('phppromdb.measurements', $bulkDelete); 28 | } 29 | 30 | protected function getRawKey($key) { 31 | $filter = ['key' => $key]; 32 | $options = ['limit' => 1]; 33 | $query = new \MongoDB\Driver\Query($filter, $options); 34 | $results = $this->mongoDBManager->executeQuery('phppromdb.measurements', $query); 35 | foreach ($results as $result) { 36 | return $result->value; 37 | } 38 | return null; 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /tests/PHPPromTests/PrometheusExportTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests; 13 | 14 | use Eloquent\Phony\Phpunit\Phony; 15 | use PHPProm\PrometheusExport; 16 | 17 | class PrometheusExportTest extends \PHPUnit_Framework_TestCase { 18 | 19 | public function testGetExport() { 20 | $storageHandle = Phony::mock('\\PHPProm\\Storage\\AbstractStorage'); 21 | $storageHandle->getMeasurements->returns(['val1' => 1, 'val2' => 2]); 22 | $storageHandle->getAvailableMetrics->returns([ 23 | [ 24 | 'name' => 'name', 25 | 'metric' => 'metric', 26 | 'label' => 'label', 27 | 'help' => 'help', 28 | 'type' => 'type', 29 | 'defaultValue' => 'defaultValue' 30 | ] 31 | ]); 32 | $storageMock = $storageHandle->get(); 33 | $prometheusExport = new PrometheusExport(); 34 | $read = $prometheusExport->getExport($storageMock, ['val1', 'val2', 'val3']); 35 | $expected = "# HELP metric help\n# TYPE metric type\nmetric{label=\"val1\"} 1\nmetric{label=\"val2\"} 2\n"; 36 | $this->assertSame($expected, $read); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/PHPProm/StopWatch.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm; 13 | 14 | use PHPProm\Storage\AbstractStorage; 15 | 16 | /** 17 | * Class StopWatch 18 | * Small utility class to measure the time of something. 19 | * @package PHPProm 20 | */ 21 | class StopWatch { 22 | 23 | /** 24 | * @var AbstractStorage 25 | * the storage to store the result at 26 | */ 27 | protected $storage; 28 | 29 | /** 30 | * @var float 31 | * the moment the measurement started 32 | */ 33 | protected $start; 34 | 35 | /** 36 | * StopWatch constructor. 37 | * @param AbstractStorage $storage 38 | * the storage to store the result at 39 | */ 40 | public function __construct(AbstractStorage $storage) { 41 | $this->storage = $storage; 42 | } 43 | 44 | /** 45 | * To start the measurement. 46 | */ 47 | public function start() { 48 | $this->start = microtime(true); 49 | } 50 | 51 | /**+ 52 | * To stop and store the measurement as float seconds. 53 | * 54 | * @param string $metric 55 | * the name of the metric 56 | * @param string $key 57 | * the key 58 | */ 59 | public function stop($metric, $key) { 60 | $time = microtime(true) - $this->start; 61 | $this->storage->storeMeasurement($metric, $key, $time); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/PHPProm/Storage/Redis.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Storage; 13 | 14 | /** 15 | * Class Redis 16 | * Storage implementation using Redis. 17 | * @package PHPProm\Storage 18 | */ 19 | class Redis extends AbstractStorage { 20 | 21 | /** 22 | * @var \Redis 23 | * The Redis connection. 24 | */ 25 | protected $redis; 26 | 27 | /** 28 | * Redis constructor. 29 | * 30 | * @param string $host 31 | * the connection host 32 | * @param null|string $password 33 | * the password for authentication, null to ignore 34 | * @param int $port 35 | * the connection port, default 6379 36 | * @param string $prefix 37 | * the global key prefix to use, default 'PHPProm:' 38 | * @param null|string $dbIndex 39 | * the Redis DB index to use, null to ignore 40 | */ 41 | public function __construct($host, $password = null, $port = 6379, $prefix = 'PHPProm:', $dbIndex = null) { 42 | parent::__construct(); 43 | $this->redis = new \Redis(); 44 | $this->redis->connect($host, $port); 45 | if ($password !== null) { 46 | $this->redis->auth($password); 47 | } 48 | if ($dbIndex !== null) { 49 | $this->redis->select($dbIndex); 50 | } 51 | $this->redis->setOption(\Redis::OPT_PREFIX, $prefix); 52 | } 53 | 54 | /** 55 | * {@inheritdoc} 56 | */ 57 | public function storeMeasurement($metric, $key, $value) { 58 | $this->redis->set($metric.':'.$key, $value); 59 | } 60 | 61 | /** 62 | * {@inheritdoc} 63 | */ 64 | public function incrementMeasurement($metric, $key) { 65 | $this->redis->incr($metric.':'.$key); 66 | } 67 | 68 | /** 69 | * {@inheritdoc} 70 | */ 71 | public function getMeasurements($metric, array $keys, $defaultValue = 'Nan') { 72 | $measurements = []; 73 | $prefixedKeys = array_map(function($key) use ($metric) { 74 | return $metric.':'.$key; 75 | }, $keys); 76 | foreach ($this->redis->mget($prefixedKeys) as $i => $value) { 77 | $measurements[$keys[$i]] = $value !== false ? (float)$value : $defaultValue; 78 | } 79 | return $measurements; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/PHPProm/Storage/Memcached.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Storage; 13 | 14 | /** 15 | * Class Memcached 16 | * Storage implementation using memcached. 17 | * @package PHPProm\Storage 18 | */ 19 | class Memcached extends AbstractStorage { 20 | 21 | /** 22 | * @var \Memcached 23 | * The memcached connection. 24 | */ 25 | protected $memcached; 26 | 27 | /** 28 | * @var string 29 | * The global key prefix. 30 | */ 31 | protected $prefix; 32 | 33 | /** 34 | * Memcached constructor. 35 | * 36 | * @param string $host 37 | * the connection host 38 | * @param int $port 39 | * the connection port, default 11211 40 | * @param string $prefix 41 | * the global key prefix to use, default 'PHPProm:' 42 | */ 43 | public function __construct($host, $port = 11211, $prefix = 'PHPProm:') { 44 | parent::__construct(); 45 | $this->memcached = new \Memcached(); 46 | $this->memcached->addServer($host, $port); 47 | $this->prefix = $prefix; 48 | } 49 | 50 | /** 51 | * {@inheritdoc} 52 | */ 53 | public function storeMeasurement($metric, $key, $value) { 54 | $this->memcached->set($this->prefix.$metric.':'.$key, $value); 55 | } 56 | 57 | /** 58 | * {@inheritdoc} 59 | */ 60 | public function incrementMeasurement($metric, $key) { 61 | // Increment doesn't work on older versions, see 62 | // https://github.com/php-memcached-dev/php-memcached/issues/133 63 | $value = $this->memcached->get($this->prefix.$metric.':'.$key); 64 | if ($value === false) { 65 | $value = 0; 66 | } 67 | $value++; 68 | $this->storeMeasurement($metric, $key, $value); 69 | } 70 | 71 | /** 72 | * {@inheritdoc} 73 | */ 74 | public function getMeasurements($metric, array $keys, $defaultValue = 'Nan') { 75 | $measurements = []; 76 | foreach ($keys as $key) { 77 | $measurements[$key] = $defaultValue; 78 | } 79 | $prefixedKeys = array_map(function($key) use ($metric) { 80 | return $this->prefix.$metric.':'.$key; 81 | }, $keys); 82 | foreach ($this->memcached->getMulti($prefixedKeys) as $key => $value) { 83 | $unprefixedKey = substr($key, strlen($this->prefix) + strlen($metric) + 1); 84 | $measurements[$unprefixedKey] = $value !== false ? (float)$value : $defaultValue; 85 | } 86 | return $measurements; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Storage/AbstractStorageTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Storage; 13 | 14 | abstract class AbstractStorageTest extends \PHPUnit_Framework_TestCase { 15 | 16 | protected $storage; 17 | 18 | abstract protected function getRawKey($key); 19 | 20 | public function testStoreMeasurement() { 21 | $this->storage->storeMeasurement('metric', 'key', 42); 22 | $read = $this->getRawKey('metric:key'); 23 | $expected = 42; 24 | $this->assertSame($expected, $read); 25 | } 26 | 27 | public function testIncrementMeasurement() { 28 | $this->storage->incrementMeasurement('metric', 'incrementKey'); 29 | $read = $this->getRawKey('metric:incrementKey'); 30 | $expected = 1; 31 | $this->assertSame($expected, $read); 32 | $this->storage->incrementMeasurement('metric', 'incrementKey'); 33 | $read = $this->getRawKey('metric:incrementKey'); 34 | $expected = 2; 35 | $this->assertSame($expected, $read); 36 | } 37 | 38 | public function testGetMeasurements() { 39 | $this->storage->storeMeasurement('metric', 'key', 42); 40 | $read = $this->storage->getMeasurements('metric', ['key', 'anotherKey'], 'Foo'); 41 | $expected = [ 42 | 'key' => 42.0, 43 | 'anotherKey' => 'Foo' 44 | ]; 45 | $this->assertSame($expected, $read); 46 | } 47 | 48 | public function testAddAvailableMetricGetAvailableMetrics() { 49 | $read = $this->storage->getAvailableMetrics(); 50 | $expected = []; 51 | $this->assertSame($expected, $read); 52 | $this->storage->addAvailableMetric('metric', 'label', 'help', 'type', 'defaultValue'); 53 | $read = $this->storage->getAvailableMetrics(); 54 | $expected = [ 55 | [ 56 | 'metric' => 'metric', 57 | 'label' => 'label', 58 | 'help' => 'help', 59 | 'type' => 'type', 60 | 'defaultValue' => 'defaultValue' 61 | ] 62 | ]; 63 | $this->assertSame($expected, $read); 64 | $this->storage->addAvailableMetric('metric2', 'label2', 'help2', 'type2', 'defaultValue2'); 65 | $read = $this->storage->getAvailableMetrics(); 66 | $expected[] = [ 67 | 'metric' => 'metric2', 68 | 'label' => 'label2', 69 | 'help' => 'help2', 70 | 'type' => 'type2', 71 | 'defaultValue' => 'defaultValue2' 72 | ]; 73 | $this->assertSame($expected, $read); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/PHPProm/PrometheusExport.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm; 13 | 14 | use PHPProm\Storage\AbstractStorage; 15 | 16 | /** 17 | * Class PrometheusExport 18 | * To export the measurements into the Prometheus format. 19 | * @package PHPProm 20 | */ 21 | class PrometheusExport { 22 | 23 | /** 24 | * Gets the header of a metric like its type or help. 25 | * 26 | * @param $type 27 | * the header type, "HELP" or "TYPE" 28 | * @param $metric 29 | * the metric 30 | * @param $label 31 | * the label of the header like the actual help text or Prometheus type 32 | * 33 | * @return string 34 | * the complete header 35 | */ 36 | protected function getHeader($type, $metric, $label) { 37 | $header = ''; 38 | if ($label !== null) { 39 | $header .= '# '.$type.' '.$metric.' '.$label."\n"; 40 | } 41 | return $header; 42 | } 43 | 44 | /** 45 | * Gets a metric with header and values. 46 | * 47 | * @param string $metric 48 | * the metric 49 | * @param string $label 50 | * the categorizing label 51 | * @param array $labelsToValues 52 | * each label value mapping to the metric value 53 | * @param string $help 54 | * a helping text about the metric 55 | * @param string $type 56 | * the Prometheus type of the metric 57 | * 58 | * @return string 59 | * the Prometheus export string of this metric 60 | */ 61 | protected function getMetric($metric, $label, array $labelsToValues, $help, $type) { 62 | $result = $this->getHeader('HELP', $metric, $help); 63 | $result .= $this->getHeader('TYPE', $metric, $type); 64 | $result .= implode("\n", array_map(function($value, $labelValue) use ($metric, $label) { 65 | return $metric.'{'.$label.'="'.$labelValue.'"} '.$value; 66 | }, $labelsToValues, array_keys($labelsToValues))); 67 | return $result."\n"; 68 | } 69 | 70 | /** 71 | * Gets a Prometheus export of the given storage. 72 | * 73 | * @param AbstractStorage $storage 74 | * the storage to export 75 | * @param $keys 76 | * the measurement keys to export 77 | * 78 | * @return string 79 | * the Prometheus export string of all available metrics 80 | */ 81 | public function getExport(AbstractStorage $storage, $keys) { 82 | $export = ''; 83 | foreach ($storage->getAvailableMetrics() as $availableMetric) { 84 | $measurements = $storage->getMeasurements($availableMetric['metric'], $keys, $availableMetric['defaultValue']); 85 | $export .= $this->getMetric($availableMetric['metric'], $availableMetric['label'], $measurements, $availableMetric['help'], $availableMetric['type']); 86 | } 87 | return $export; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/PHPProm/Storage/AbstractStorage.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Storage; 13 | 14 | /** 15 | * Class AbstractStorage 16 | * The parent class of all storage implementations. 17 | * @package PHPProm\Storage 18 | */ 19 | abstract class AbstractStorage { 20 | 21 | /** 22 | * @var array 23 | * Holds the available metrics. 24 | */ 25 | protected $availableMetrics; 26 | 27 | /** 28 | * AbstractStorage constructor. 29 | */ 30 | public function __construct() { 31 | $this->availableMetrics = []; 32 | } 33 | 34 | /** 35 | * Adds a metric to the available ones. 36 | * 37 | * @param string $metric 38 | * the metric itself as delivered by Prometheus 39 | * @param string $label 40 | * the name of the one Prometheus label to categorize the values 41 | * @param string $help 42 | * a helping text for the metric 43 | * @param string $type 44 | * the Prometheus type of the metric 45 | * @param string $defaultValue 46 | * the default value which the metric gets if there is no value stored 47 | */ 48 | public function addAvailableMetric($metric, $label, $help, $type, $defaultValue) { 49 | $this->availableMetrics[] = [ 50 | 'metric' => $metric, 51 | 'label' => $label, 52 | 'help' => $help, 53 | 'type' => $type, 54 | 'defaultValue' => $defaultValue 55 | ]; 56 | } 57 | 58 | /** 59 | * Gets all available metrics in an array. 60 | * 61 | * @return array 62 | * the available metrics 63 | */ 64 | public function getAvailableMetrics() { 65 | return $this->availableMetrics; 66 | } 67 | 68 | /** 69 | * Stores a measurement. 70 | * 71 | * @param string $metric 72 | * the name of the metric 73 | * @param string $key 74 | * the key 75 | * @param float $value 76 | * the value 77 | * @return void 78 | */ 79 | abstract public function storeMeasurement($metric, $key, $value); 80 | 81 | /** 82 | * Increments a measurement, starting with 1 if it doesn't exist yet. 83 | * @param string $metric 84 | * the name of the metric 85 | * @param string $key 86 | * the key 87 | * @return void 88 | */ 89 | abstract public function incrementMeasurement($metric, $key); 90 | 91 | /** 92 | * Gets all measurements. 93 | * 94 | * @param string $metric 95 | * the name of the metric 96 | * @param array $keys 97 | * the keys to retrieve 98 | * @param string $defaultValue 99 | * the default value a key gets if there is no value for it in the storage 100 | * @return array 101 | * the map with the keys and values 102 | */ 103 | abstract public function getMeasurements($metric, array $keys, $defaultValue = 'Nan'); 104 | 105 | } 106 | -------------------------------------------------------------------------------- /docs/0.1.0/interfaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Interfaces | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 67 | 68 | 69 |
70 |
71 |
72 | 75 | 76 |
77 |
78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /docs/0.1.0/traits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Traits | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 67 | 68 |
69 |
70 |
71 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/PHPProm/Storage/MongoDB.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Storage; 13 | 14 | /** 15 | * Class MongoDB 16 | * Storage implementation using MongoDB. 17 | * @package PHPProm\Storage 18 | */ 19 | class MongoDB extends AbstractStorage { 20 | 21 | /** 22 | * @var \MongoDB\Driver\Manager 23 | * The MongoDB Driver Manager. 24 | */ 25 | protected $mongoDBManager; 26 | 27 | /** 28 | * @var string 29 | * The database name for the data. 30 | */ 31 | protected $database; 32 | 33 | /** 34 | * @var string 35 | * The collection name for the data. 36 | */ 37 | protected $collection; 38 | 39 | /** 40 | * MongoDB constructor. 41 | * 42 | * @param string $host 43 | * a mongodb:// connection URI 44 | * @param string $database 45 | * the database to use, defaults to "phppromdb" 46 | * @param string $collection 47 | * the collection to use, defaults to "measurements" 48 | * @param array $options 49 | * connection string options, defaults to [] 50 | * @param array $driverOptions 51 | * any driver-specific options not included in MongoDB connection spec, defaults to [] 52 | */ 53 | public function __construct($host, $database = 'phppromdb', $collection = 'measurements', array $options = [], array $driverOptions = []) { 54 | parent::__construct(); 55 | $this->mongoDBManager = new \MongoDB\Driver\Manager($host, $options, $driverOptions); 56 | $this->database = $database; 57 | $this->collection = $collection; 58 | } 59 | 60 | /** 61 | * {@inheritdoc} 62 | */ 63 | public function storeMeasurement($metric, $key, $value) { 64 | $bulkWrite = new \MongoDB\Driver\BulkWrite; 65 | $document = ['key' => $metric.':'.$key, 'value' => $value]; 66 | $filter = ['key' => $metric.':'.$key]; 67 | $bulkWrite->update($filter, $document, ['upsert' => true]); 68 | $this->mongoDBManager->executeBulkWrite($this->database.'.'.$this->collection, $bulkWrite); 69 | } 70 | 71 | /** 72 | * {@inheritdoc} 73 | */ 74 | public function incrementMeasurement($metric, $key) { 75 | $filter = ['key' => $metric.':'.$key]; 76 | $options = ['limit' => 1]; 77 | $query = new \MongoDB\Driver\Query($filter, $options); 78 | $results = $this->mongoDBManager->executeQuery($this->database.'.'.$this->collection, $query); 79 | $value = 1; 80 | foreach ($results as $result) { 81 | $value += $result->value; 82 | break; 83 | } 84 | $this->storeMeasurement($metric, $key, $value); 85 | } 86 | 87 | /** 88 | * {@inheritdoc} 89 | */ 90 | public function getMeasurements($metric, array $keys, $defaultValue = 'Nan') { 91 | $prefixedKeys = array_map(function($key) use ($metric) { 92 | return $metric.':'.$key; 93 | }, $keys); 94 | 95 | $measurements = []; 96 | foreach ($keys as $key) { 97 | $measurements[$key] = $defaultValue; 98 | } 99 | $filter = ['key' => ['$in' => $prefixedKeys]]; 100 | $query = new \MongoDB\Driver\Query($filter); 101 | $results = $this->mongoDBManager->executeQuery($this->database.'.'.$this->collection, $query); 102 | foreach ($results as $result) { 103 | $unprefixedKey = substr($result->key, strlen($metric) + 1); 104 | $measurements[$unprefixedKey] = (float)$result->value; 105 | } 106 | return $measurements; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /docs/0.1.0/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Namespaces | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 67 | 68 |
69 |
70 |

PHPProm

71 | 76 |
77 |
78 | 79 |
80 | 83 | 84 |
85 |
86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /docs/0.1.0/namespaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Namespaces | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 67 | 68 |
69 |
70 |

PHPProm

71 | 76 |
77 |
78 | 79 |
80 | 83 | 84 |
85 |
86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /src/PHPProm/Integration/Slim3Setup.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Integration; 13 | 14 | use \Psr\Http\Message\ServerRequestInterface as Request; 15 | use \Psr\Http\Message\ResponseInterface as Response; 16 | use \Slim\App; 17 | use PHPProm\PrometheusExport; 18 | use PHPProm\Storage\AbstractStorage; 19 | use PHPProm\StopWatch; 20 | use Slim\Route; 21 | 22 | /** 23 | * Class Slim3Setup 24 | * Setups Slim applications to measure: 25 | * - the time of each route 26 | * - the used memory of each route 27 | * - the amount of requests of each route 28 | * It also offers an function to be used for a Prometheus scrapable endpoint. 29 | * @package PHPProm\Integration 30 | */ 31 | class Slim3Setup { 32 | 33 | 34 | /** 35 | * Sets up the Slim middleware where the actual measurements happen. 36 | * 37 | * @param App $app 38 | * the Silex application 39 | * @param AbstractStorage $storage 40 | * the storage for the measurements 41 | */ 42 | protected function setupMiddleware(App $app, AbstractStorage $storage) { 43 | $storage->addAvailableMetric('route_time', 'name', 'request times per route in seconds', 'gauge', 'Nan'); 44 | $storage->addAvailableMetric('route_memory', 'name', 'request memory per route in bytes', 'gauge', 'Nan'); 45 | $storage->addAvailableMetric('route_requests_total', 'name', 'total requests per route', 'counter', 0); 46 | 47 | $app->add(function(Request $request, Response $response, App $next) use ($storage) { 48 | $method = $request->getMethod(); 49 | $pattern = str_replace('/', '_', $request->getAttribute('route')->getPattern()); 50 | $route = $method.$pattern; 51 | $routeTime = new StopWatch($storage); 52 | $routeTime->start(); 53 | $response = $next($request, $response); 54 | $routeTime->stop('route_time', $route); 55 | $storage->storeMeasurement('route_memory', $route, memory_get_peak_usage(true)); 56 | $storage->incrementMeasurement('route_requests_total', $route); 57 | return $response; 58 | }); 59 | } 60 | 61 | /** 62 | * Gets the path with all methods from a route. 63 | * 64 | * @param Route $route 65 | * the route to get the path and methods from 66 | * @return array 67 | * the pathes with methods 68 | */ 69 | protected function getPathWithMethods(Route $route) { 70 | $routes = []; 71 | $pattern = str_replace('/', '_', $route->getPattern()); 72 | $methods = $route->getMethods(); 73 | foreach ($methods as $method) { 74 | $routes[] = $method.$pattern; 75 | } 76 | return $routes; 77 | } 78 | 79 | /** 80 | * Sets up the Slim middlewares where the actual measurements happen 81 | * and returns a function to be used for a Prometheus scrapable endpoint. 82 | * 83 | * @param App $app 84 | * the Slim application 85 | * @param AbstractStorage $storage 86 | * the storage for the measurements 87 | * 88 | * @return \Closure 89 | * the function to be used for a Prometheus scrapable endpoint 90 | */ 91 | public function setupAndGetMetricsRoute(App $app, AbstractStorage $storage) { 92 | $this->setupMiddleware($app, $storage); 93 | $self = $this; 94 | return function(Request $request, Response $response) use ($app, $storage, $self) { 95 | $routes = []; 96 | $availableRoutes = $app->getContainer()->get('router')->getRoutes(); 97 | foreach ($availableRoutes as $route) { 98 | $routes = array_merge($routes, $self->getPathWithMethods($route)); 99 | } 100 | $export = new PrometheusExport(); 101 | $responseBody = $export->getExport($storage, $routes); 102 | 103 | $response = $response->withHeader('Content-type', 'text/plain; version=0.0.4'); 104 | $response->getBody()->write($responseBody); 105 | 106 | }; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/PHPProm/Integration/SilexSetup.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Integration; 13 | 14 | use PHPProm\PrometheusExport; 15 | use PHPProm\StopWatch; 16 | use PHPProm\Storage\AbstractStorage; 17 | use Silex\Application; 18 | use Silex\Route; 19 | use Symfony\Component\HttpFoundation\Request; 20 | use Symfony\Component\HttpFoundation\Response; 21 | 22 | /** 23 | * Class SilexSetup 24 | * Setups Silex applications to measure: 25 | * - the time of each route 26 | * - the used memory of each route 27 | * - the amount of requests of each route 28 | * It also offers an function to be used for a Prometheus scrapable endpoint. 29 | * @package PHPProm\Integration 30 | */ 31 | class SilexSetup { 32 | 33 | /** 34 | * Sets up the Silex middlewares where the actual measurements happen. 35 | * 36 | * @param Application $app 37 | * the Silex application 38 | * @param AbstractStorage $storage 39 | * the storage for the measurements 40 | */ 41 | protected function setupMiddleware(Application $app, AbstractStorage $storage) { 42 | 43 | $storage->addAvailableMetric('route_time', 'name', 'request times per route in seconds', 'gauge', 'Nan'); 44 | $storage->addAvailableMetric('route_memory', 'name', 'request memory per route in bytes', 'gauge', 'Nan'); 45 | $storage->addAvailableMetric('route_requests_total', 'name', 'total requests per route', 'counter', 0); 46 | 47 | $routeTime = new StopWatch($storage); 48 | 49 | $app->before(function() use ($routeTime) { 50 | $routeTime->start(); 51 | }, Application::EARLY_EVENT); 52 | 53 | $app->finish(function(Request $request) use ($routeTime, $storage) { 54 | $route = $request->get('_route'); 55 | $routeTime->stop('route_time', $route); 56 | $storage->storeMeasurement('route_memory', $route, memory_get_peak_usage(true)); 57 | $storage->incrementMeasurement('route_requests_total', $route); 58 | }); 59 | 60 | } 61 | 62 | /** 63 | * Gets the path with all methods from a route. 64 | * 65 | * @param Route $route 66 | * the route to get the path and methods from 67 | * @return array 68 | * the pathes with methods 69 | */ 70 | protected function getPathWithMethods(Route $route) { 71 | $supportedMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']; 72 | $path = str_replace('/', '_', $route->getPath()); 73 | $foundMethod = false; 74 | $routes = []; 75 | foreach ($route->getMethods() as $method) { 76 | $routes[] = $method.$path; 77 | $foundMethod = true; 78 | } 79 | if (!$foundMethod) { 80 | foreach ($supportedMethods as $supportedMethod) { 81 | $routes[] = $supportedMethod.$path; 82 | } 83 | } 84 | return $routes; 85 | } 86 | 87 | /** 88 | * Sets up the Silex middlewares where the actual measurements happen 89 | * and returns a function to be used for a Prometheus scrapable endpoint. 90 | * 91 | * @param Application $app 92 | * the Silex application 93 | * @param AbstractStorage $storage 94 | * the storage for the measurements 95 | * 96 | * @return \Closure 97 | * the function to be used for a Prometheus scrapable endpoint 98 | */ 99 | public function setupAndGetMetricsRoute(Application $app, AbstractStorage $storage) { 100 | 101 | $this->setupMiddleware($app, $storage); 102 | 103 | return function() use ($app, $storage) { 104 | $routes = []; 105 | foreach ($app['routes']->all() as $route) { 106 | $routes = array_merge($routes, $this->getPathWithMethods($route)); 107 | } 108 | $export = new PrometheusExport(); 109 | $response = $export->getExport($storage, $routes); 110 | return new Response($response, 200, ['Content-Type' => 'text/plain; version=0.0.4']); 111 | }; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Integration.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Integration | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 70 |
71 |
72 | 73 | 76 | 77 | 78 |

Classes

79 | 80 |
81 |
82 |
83 | SilexSetup 84 | 85 |
86 |
87 | Class SilexSetup 88 | Setups Silex applications to measure: 89 | - the time of each route 90 | - the used memory of each route 91 | - the amount of requests of each route 92 | It also offers an function to be used for a Prometheus scrapable endpoint. 93 |
94 |
95 |
96 | 97 | 98 | 99 |
100 | 103 | 104 |
105 |
106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 69 |
70 |
71 | 72 | 75 | 76 |

Namespaces

77 | 79 | 80 |

Classes

81 | 82 |
83 |
84 |
85 | PrometheusExport 86 | 87 |
88 |
89 | Class PrometheusExport 90 | To export the measurements into the Prometheus format. 91 |
92 |
93 |
94 |
95 | StopWatch 96 | 97 |
98 |
99 | Class StopWatch 100 | Small utility class to measure the time of something. 101 |
102 |
103 |
104 | 105 | 106 | 107 |
108 | 111 | 112 |
113 |
114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /tests/PHPPromTests/Integration/SilexSetupTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPPromTests\Integration; 13 | 14 | use PHPProm\Storage\Memcached; 15 | use Silex\WebTestCase; 16 | 17 | class SilexSetupTest extends WebTestCase { 18 | 19 | protected function setUp() { 20 | parent::setUp(); 21 | $keys = [ 22 | 'PHPProm:route_time:GET_metrics', 23 | 'PHPProm:route_memory:GET_metrics', 24 | 'PHPProm:route_requests_total:GET_metrics', 25 | 'PHPProm:route_time:GET_test1', 26 | 'PHPProm:route_memory:GET_test1', 27 | 'PHPProm:route_requests_total:GET_test1', 28 | 'PHPProm:route_time:GET_test2', 29 | 'PHPProm:route_memory:GET_test2', 30 | 'PHPProm:route_requests_total:GET_test2' 31 | ]; 32 | $memcached = new \Memcached(); 33 | $memcached->addServer('localhost', 11211); 34 | foreach ($keys as $key) { 35 | $memcached->delete($key); 36 | } 37 | } 38 | 39 | public function createApplication() { 40 | $app = new \Silex\Application(); 41 | 42 | $app['debug'] = true; 43 | unset($app['exception_handler']); 44 | 45 | $storage = new Memcached('localhost'); 46 | $silexSetup = new \PHPProm\Integration\SilexSetup(); 47 | $app->get('/metrics', $silexSetup->setupAndGetMetricsRoute($app, $storage)); 48 | 49 | $app->get('/test1', function() { 50 | sleep(1); 51 | return 'ok'; 52 | }); 53 | $app->get('/test2', function() { 54 | return 'ok'; 55 | }); 56 | $app->match('/test3', function() { 57 | return 'ok'; 58 | }); 59 | 60 | return $app; 61 | } 62 | 63 | public function testMeasurements() { 64 | 65 | $client = $this->createClient(); 66 | $client->request('GET', '/test1'); 67 | $client->request('GET', '/test2'); 68 | $client->request('GET', '/test2'); 69 | 70 | $client->request('GET', '/metrics'); 71 | $response = $client->getResponse(); 72 | $this->assertTrue($response->isOk()); 73 | $content = $response->getContent(); 74 | 75 | $this->assertRegExp('/# HELP route\\_time request times per route in seconds/', $content); 76 | $this->assertRegExp('/# TYPE route\\_time gauge/', $content); 77 | $this->assertRegExp('/route_time{name="GET_metrics"} Nan/', $content); 78 | $this->assertRegExp('/route_time{name="GET_test1"} [0-9]+/', $content); 79 | $this->assertRegExp('/route_time{name="GET_test2"} [0-9]+/', $content); 80 | $this->assertRegExp('/route_time{name="GET_test3"} Nan+/', $content); 81 | $this->assertRegExp('/route_time{name="POST_test3"} Nan+/', $content); 82 | $this->assertRegExp('/route_time{name="PUT_test3"} Nan+/', $content); 83 | $this->assertRegExp('/route_time{name="DELETE_test3"} Nan+/', $content); 84 | $this->assertRegExp('/route_time{name="PATCH_test3"} Nan+/', $content); 85 | $this->assertRegExp('/route_time{name="OPTIONS_test3"} Nan+/', $content); 86 | 87 | $this->assertRegExp('/# HELP route\\_memory request memory per route in bytes/', $content); 88 | $this->assertRegExp('/# TYPE route\\_memory gauge/', $content); 89 | $this->assertRegExp('/route_memory{name="GET_metrics"} Nan/', $content); 90 | $this->assertRegExp('/route_memory{name="GET_test1"} [0-9]+/', $content); 91 | $this->assertRegExp('/route_memory{name="GET_test2"} [0-9]+/', $content); 92 | $this->assertRegExp('/route_memory{name="GET_test3"} Nan+/', $content); 93 | $this->assertRegExp('/route_memory{name="POST_test3"} Nan+/', $content); 94 | $this->assertRegExp('/route_memory{name="PUT_test3"} Nan+/', $content); 95 | $this->assertRegExp('/route_memory{name="DELETE_test3"} Nan+/', $content); 96 | $this->assertRegExp('/route_memory{name="PATCH_test3"} Nan+/', $content); 97 | $this->assertRegExp('/route_memory{name="OPTIONS_test3"} Nan+/', $content); 98 | 99 | $this->assertRegExp('/# HELP route\\_requests_total total requests per route/', $content); 100 | $this->assertRegExp('/# TYPE route\\_requests_total counter/', $content); 101 | $this->assertRegExp('/route_requests_total{name="GET_metrics"} 0/', $content); 102 | $this->assertRegExp('/route_requests_total{name="GET_test1"} 1/', $content); 103 | $this->assertRegExp('/route_requests_total{name="GET_test2"} 2/', $content); 104 | $this->assertRegExp('/route_requests_total{name="GET_test3"} 0/', $content); 105 | $this->assertRegExp('/route_requests_total{name="POST_test3"} 0/', $content); 106 | $this->assertRegExp('/route_requests_total{name="PUT_test3"} 0/', $content); 107 | $this->assertRegExp('/route_requests_total{name="DELETE_test3"} 0/', $content); 108 | $this->assertRegExp('/route_requests_total{name="PATCH_test3"} 0/', $content); 109 | $this->assertRegExp('/route_requests_total{name="OPTIONS_test3"} 0/', $content); 110 | 111 | } 112 | } -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Storage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Storage | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 70 |
71 |
72 | 73 | 76 | 77 | 78 |

Classes

79 | 80 |
81 |
82 |
83 | AbstractStorage 84 | 85 |
86 |
87 | Class AbstractStorage 88 | The parent class of all storage implementations. 89 |
90 |
91 |
92 |
93 | DBAL 94 | 95 |
96 |
97 | Class DBAL 98 | Storage implementation using Doctrine DBAL. 99 |
100 |
101 |
102 |
103 | Memcached 104 | 105 |
106 |
107 | Class Memcached 108 | Storage implementation using memcached. 109 |
110 |
111 |
112 |
113 | Redis 114 | 115 |
116 |
117 | Class Redis 118 | Storage implementation using Redis. 119 |
120 |
121 |
122 | 123 | 124 | 125 |
126 | 129 | 130 |
131 |
132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/0.1.0/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Search | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 | 28 | 32 |
33 |
34 | 35 |
36 | 37 |
38 |
39 | 62 | 63 |
64 | 65 | 68 | 69 |

This page allows you to search through the API documentation for 70 | specific terms. Enter your search words into the box below and click 71 | "submit". The search will be performed on namespaces, clases, interfaces, 72 | traits, functions, and methods.

73 | 74 |
75 |
76 | 77 | 78 |
79 | 80 |
81 | 82 |

Search Results

83 | 84 |
85 |
    86 |
    87 | 88 | 144 | 145 | 146 |
    147 | 150 | 151 |
    152 |
    153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/PrometheusExport.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\PrometheusExport | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 70 |
    71 |
    72 | 73 | 79 | 80 |

    class 81 | PrometheusExport 82 |

    83 | 84 | 85 | 86 | 87 |
    88 |

    Class PrometheusExport 89 | To export the measurements into the Prometheus format.

    90 | 91 | 92 | 93 | 94 |

    Methods

    95 | 96 |
    97 |
    98 |
    99 | string 100 |
    101 |
    102 | getExport(AbstractStorage $storage, $keys) 103 | 104 |

    Gets a Prometheus export of the given storage.

    105 |
    106 |
    107 |
    108 | 109 | 110 |

    Details

    111 | 112 |
    113 |
    114 |

    115 |
    at line line 81
    116 | string 117 | getExport(AbstractStorage $storage, $keys) 118 | 119 |

    120 |
    121 | 122 | 123 | 124 |
    125 |

    Gets a Prometheus export of the given storage.

    126 |
    127 |

    Parameters

    128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 |
    AbstractStorage$storagethe storage to export
    $keysthe measurement keys to export
    141 | 142 | 143 |

    Return Value

    144 | 145 | 146 | 147 | 148 | 149 | 150 |
    stringthe Prometheus export string of all available metrics
    151 | 152 | 153 | 154 |
    155 |
    156 | 157 |
    158 |
    159 | 160 | 161 |
    162 | 165 | 166 |
    167 |
    168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /src/PHPProm/Storage/DBAL.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace PHPProm\Storage; 13 | 14 | use \Doctrine\DBAL\Connection; 15 | 16 | /** 17 | * Class DBAL 18 | * Storage implementation using Doctrine DBAL. 19 | * This way, MySQL and other databases are supported. 20 | * The used SQL is kept very simple so the queries should work 21 | * with most of the DBAL supported databases. 22 | * 23 | * A MySQL example of the expected table: 24 | * CREATE TABLE `phpprom` ( 25 | * `key` varchar(255) NOT NULL, 26 | * `value` double NOT NULL, 27 | * PRIMARY KEY (`key`) 28 | * ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 29 | * @package PHPProm\Storage 30 | * 31 | * A SQLite example of the expected table: 32 | * CREATE TABLE `phpprom` ( 33 | * `key` TEXT NOT NULL UNIQUE, 34 | * `value` REAL NOT NULL, 35 | * PRIMARY KEY(`key`) 36 | * ); 37 | * 38 | * A PostgreSQL example of the expected table: 39 | * CREATE TABLE public.phpprom ( 40 | * key VARCHAR(255) PRIMARY KEY NOT NULL, 41 | * value DOUBLE PRECISION NOT NULL 42 | * ); 43 | * CREATE UNIQUE INDEX phpprom_key_uindex ON public.phpprom (key); 44 | */ 45 | class DBAL extends AbstractStorage { 46 | 47 | /** 48 | * @var Connection 49 | * The DBAL connection. 50 | */ 51 | protected $connection; 52 | 53 | /** 54 | * @var string 55 | * The table to use. 56 | */ 57 | protected $table; 58 | 59 | /** 60 | * @var \Doctrine\DBAL\Driver\Statement 61 | * The prepared statement to check whether there is already a value for a given key. 62 | */ 63 | protected $statementKeyExists; 64 | 65 | /** 66 | * @var \Doctrine\DBAL\Driver\Statement 67 | * The prepared statement to insert a new key value pair. 68 | */ 69 | protected $statementKeyInsert; 70 | 71 | /** 72 | * @var \Doctrine\DBAL\Driver\Statement 73 | * The prepared statement to update the value of an existing key. 74 | */ 75 | protected $statementKeyUpdate; 76 | 77 | /** 78 | * @var \Doctrine\DBAL\Driver\Statement 79 | * The prepared statement to increment the value of the given key. 80 | */ 81 | protected $statementKeyIncr; 82 | 83 | /** 84 | * @var string 85 | * the sign to use to quote identifiers in queries 86 | */ 87 | protected $quote; 88 | 89 | /** 90 | * Builds the prepared statements. 91 | */ 92 | protected function buildStatements() { 93 | $quote = $this->quote; 94 | $queryBuilder = $this->connection->createQueryBuilder() 95 | ->select('COUNT('.$quote.'key'.$quote.') AS amount')->from($quote.$this->table.$quote)->where(''.$quote.'key'.$quote.' = ?'); 96 | $this->statementKeyExists = $this->connection->prepare($queryBuilder->getSQL()); 97 | 98 | $queryBuilder = $this->connection->createQueryBuilder() 99 | ->insert($quote.$this->table.$quote)->setValue($quote.'value'.$quote, '?')->setValue(''.$quote.'key'.$quote.'', '?'); 100 | $this->statementKeyInsert = $this->connection->prepare($queryBuilder->getSQL()); 101 | 102 | $queryBuilder = $this->connection->createQueryBuilder() 103 | ->update($quote.$this->table.$quote)->set($quote.'value'.$quote, '?')->where($quote.'key'.$quote.' = ?'); 104 | $this->statementKeyUpdate = $this->connection->prepare($queryBuilder->getSQL()); 105 | 106 | $queryBuilder = $this->connection->createQueryBuilder() 107 | ->update($quote.$this->table.$quote)->set($quote.'value'.$quote, $quote.'value'.$quote.' + 1')->where($quote.'key'.$quote.' = ?'); 108 | $this->statementKeyIncr = $this->connection->prepare($queryBuilder->getSQL()); 109 | } 110 | 111 | /** 112 | * DBAL constructor. 113 | * 114 | * @param Connection $connection 115 | * the DBAL connection 116 | * @param string $table 117 | * the table to use 118 | */ 119 | public function __construct(Connection $connection, $table = 'phpprom') { 120 | parent::__construct(); 121 | $this->connection = $connection; 122 | $this->table = $table; 123 | $this->quote = $connection->getDatabasePlatform()->getIdentifierQuoteCharacter(); 124 | $this->buildStatements(); 125 | } 126 | 127 | /** 128 | * {@inheritdoc} 129 | */ 130 | public function storeMeasurement($metric, $key, $value) { 131 | $prefixedKey = $metric.':'.$key; 132 | $this->statementKeyExists->bindValue(1, $prefixedKey); 133 | $this->statementKeyExists->execute(); 134 | $exists = $this->statementKeyExists->fetch(\PDO::FETCH_ASSOC); 135 | $statementStore = $exists['amount'] > 0 ? $this->statementKeyUpdate : $this->statementKeyInsert; 136 | $statementStore->bindValue(1, $value); 137 | $statementStore->bindValue(2, $prefixedKey); 138 | $statementStore->execute(); 139 | } 140 | 141 | /** 142 | * {@inheritdoc} 143 | */ 144 | public function incrementMeasurement($metric, $key) { 145 | $prefixedKey = $metric.':'.$key; 146 | $this->statementKeyExists->bindValue(1, $prefixedKey); 147 | $this->statementKeyExists->execute(); 148 | $exists = $this->statementKeyExists->fetch(\PDO::FETCH_ASSOC); 149 | $statementIncrement = $exists['amount'] > 0 ? $this->statementKeyIncr : $this->statementKeyInsert; 150 | if ($exists['amount'] > 0) { 151 | $statementIncrement->bindValue(1, $prefixedKey); 152 | } else { 153 | $statementIncrement->bindValue(1, 1); 154 | $statementIncrement->bindValue(2, $prefixedKey); 155 | } 156 | $statementIncrement->execute(); 157 | } 158 | 159 | /** 160 | * {@inheritdoc} 161 | */ 162 | public function getMeasurements($metric, array $keys, $defaultValue = 'Nan') { 163 | $prefixedKeys = array_map(function($key) use ($metric) { 164 | return $metric.':'.$key; 165 | }, $keys); 166 | $quote = $this->quote; 167 | $queryBuilder = $this->connection->createQueryBuilder(); 168 | $queryBuilder 169 | ->select($quote.'key'.$quote, $quote.'value'.$quote) 170 | ->from($quote.$this->table.$quote) 171 | ->where($quote.'key'.$quote.' IN (?)') 172 | ->setParameter(1, $prefixedKeys, Connection::PARAM_STR_ARRAY) 173 | ; 174 | $measurements = []; 175 | foreach ($keys as $key) { 176 | $measurements[$key] = $defaultValue; 177 | } 178 | $rows = $queryBuilder->execute()->fetchAll(\PDO::FETCH_ASSOC); 179 | foreach ($rows as $row) { 180 | $unprefixedKey = substr($row['key'], strlen($metric) + 1); 181 | $measurements[$unprefixedKey] = (float)$row['value']; 182 | } 183 | return $measurements; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /docs/0.1.0/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 67 | 68 | 69 |
    70 |
    71 |
    72 | SilexSetup 73 | 74 |
    75 |
    76 | Class SilexSetup 77 | Setups Silex applications to measure: 78 | - the time of each route 79 | - the used memory of each route 80 | - the amount of requests of each route 81 | It also offers an function to be used for a Prometheus scrapable endpoint. 82 |
    83 |
    84 |
    85 |
    86 | PrometheusExport 87 | 88 |
    89 |
    90 | Class PrometheusExport 91 | To export the measurements into the Prometheus format. 92 |
    93 |
    94 |
    95 |
    96 | StopWatch 97 | 98 |
    99 |
    100 | Class StopWatch 101 | Small utility class to measure the time of something. 102 |
    103 |
    104 |
    105 |
    106 | AbstractStorage 107 | 108 |
    109 |
    110 | Class AbstractStorage 111 | The parent class of all storage implementations. 112 |
    113 |
    114 |
    115 |
    116 | DBAL 117 | 118 |
    119 |
    120 | Class DBAL 121 | Storage implementation using Doctrine DBAL. 122 |
    123 |
    124 |
    125 |
    126 | Memcached 127 | 128 |
    129 |
    130 | Class Memcached 131 | Storage implementation using memcached. 132 |
    133 |
    134 |
    135 |
    136 | MongoDB 137 | 138 |
    139 |
    140 | Class MongoDB 141 | Storage implementation using MongoDB. 142 |
    143 |
    144 |
    145 |
    146 | Redis 147 | 148 |
    149 |
    150 | Class Redis 151 | Storage implementation using Redis. 152 |
    153 |
    154 |
    155 |
    156 | 159 | 160 |
    161 |
    162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Integration/SilexSetup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Integration\SilexSetup | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 71 |
    72 |
    73 | 74 | 80 | 81 |

    class 82 | SilexSetup 83 |

    84 | 85 | 86 | 87 | 88 |
    89 |

    Class SilexSetup 90 | Setups Silex applications to measure: 91 | - the time of each route 92 | - the used memory of each route 93 | - the amount of requests of each route 94 | It also offers an function to be used for a Prometheus scrapable endpoint.

    95 | 96 | 97 | 98 | 99 |

    Methods

    100 | 101 |
    102 |
    103 |
    104 | Closure 105 |
    106 |
    107 | setupAndGetMetricsRoute(Application $app, AbstractStorage $storage) 108 | 109 |

    Sets up the Silex middlewares where the actual measurements happen 110 | and returns a function to be used for a Prometheus scrapable endpoint.

    111 |
    112 |
    113 |
    114 | 115 | 116 |

    Details

    117 | 118 |
    119 |
    120 |

    121 |
    at line line 73
    122 | Closure 123 | setupAndGetMetricsRoute(Application $app, AbstractStorage $storage) 124 | 125 |

    126 |
    127 | 128 | 129 | 130 |
    131 |

    Sets up the Silex middlewares where the actual measurements happen 132 | and returns a function to be used for a Prometheus scrapable endpoint.

    133 |
    134 |

    Parameters

    135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
    Application$appthe Silex application
    AbstractStorage$storagethe storage for the measurements
    148 | 149 | 150 |

    Return Value

    151 | 152 | 153 | 154 | 155 | 156 | 157 |
    Closurethe function to be used for a Prometheus scrapable endpoint
    158 | 159 | 160 | 161 |
    162 |
    163 | 164 |
    165 |
    166 | 167 | 168 |
    169 | 172 | 173 |
    174 |
    175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /docs/0.1.0/css/sami.css: -------------------------------------------------------------------------------- 1 | html, body, #content { 2 | height: 100%; 3 | } 4 | 5 | /* Site menu */ 6 | 7 | #site-nav.navbar-default { 8 | margin: 0; 9 | border-radius: 0; 10 | border-bottom: 1px solid #ccc; 11 | background-color: #EDF3FE; 12 | background-image: none; 13 | } 14 | 15 | #site-nav.navbar-default .navbar-brand, 16 | #site-nav.navbar-default .navbar-nav > li > a { 17 | color: #000; 18 | } 19 | 20 | #site-nav.navbar-default .navbar-nav > li > a:hover { 21 | text-decoration: underline; 22 | } 23 | 24 | #navbar-elements { 25 | float: right; 26 | } 27 | 28 | @media (max-width: 768px) { 29 | #navbar-elements { 30 | float: none !important; 31 | } 32 | } 33 | 34 | /* Namespace breadcrumbs */ 35 | 36 | .namespace-breadcrumbs .breadcrumb { 37 | margin: 0 0 12px; 38 | border-radius: 0 0 4px 4px; 39 | padding-left: 35px; 40 | } 41 | 42 | .namespace-breadcrumbs .breadcrumb > li + li:before { 43 | content: "\\" 44 | } 45 | 46 | /* Site columns */ 47 | 48 | #right-column { 49 | margin-left: 20%; 50 | } 51 | 52 | #page-content { 53 | padding: 0 30px; 54 | } 55 | 56 | #left-column { 57 | width: 20%; 58 | position: fixed; 59 | height: 100%; 60 | border-right: 1px solid #ccc; 61 | line-height: 18px; 62 | font-size: 13px; 63 | display: flex; 64 | flex-flow: column; 65 | } 66 | 67 | @media (max-width: 991px) { 68 | #left-column { 69 | display: none; 70 | } 71 | #right-column { 72 | width: 100%; 73 | margin-left: 0; 74 | } 75 | } 76 | 77 | /* API Tree */ 78 | 79 | #api-tree { 80 | background: linear-gradient( 81 | to bottom, 82 | #FFF, 83 | #FFF 50%, 84 | #EDF3FE 50%, 85 | #EDF3FE 86 | ); 87 | background-size: 100% 56px; 88 | overflow: auto; 89 | height: 100%; 90 | background-attachment: local; 91 | } 92 | 93 | #api-tree ul { 94 | list-style-type: none; 95 | margin: 0; 96 | padding: 0; 97 | } 98 | 99 | #api-tree ul li { 100 | padding: 0; 101 | margin: 0; 102 | } 103 | 104 | /* Prevents the menu from jittering on lad */ 105 | #api-tree .glyphicon-play { 106 | width: 26px; 107 | } 108 | 109 | #api-tree ul li .hd { 110 | padding: 5px; 111 | } 112 | 113 | #api-tree li .hd:nth-child(even) { 114 | background-color: #EDF3FE; 115 | } 116 | 117 | #api-tree ul li.opened > .hd span { 118 | -webkit-transform: rotate(90deg); 119 | -moz-transform: rotate(90deg); 120 | -o-transform: rotate(90deg); 121 | -ms-transform: rotate(90deg); 122 | transform: rotate(90deg); 123 | } 124 | 125 | #api-tree .bd { 126 | display: none; 127 | } 128 | 129 | #api-tree li.opened > .bd { 130 | display: block; 131 | } 132 | 133 | #api-tree li .hd:hover { 134 | background-color: #eee; 135 | } 136 | 137 | #api-tree li.active > .hd { 138 | background-color: #3875D7; 139 | } 140 | 141 | #api-tree li.active > .hd a { 142 | color: #eee; 143 | font-weight: bold; 144 | } 145 | 146 | #api-tree a { 147 | color: #222; 148 | } 149 | 150 | #api-tree div.leaf a { 151 | margin-left: 20px; 152 | } 153 | 154 | #api-tree .hd span { 155 | padding: 2px 8px; 156 | font-size: 10px; 157 | line-height: 85%; 158 | } 159 | 160 | /* Control panel, search form, version drop-down */ 161 | 162 | #control-panel { 163 | background: #e8e8e8; 164 | border-bottom: 1px solid #666; 165 | padding: 4px; 166 | } 167 | 168 | #control-panel form { 169 | margin: 4px 4px 5px 4px; 170 | } 171 | 172 | #search-form { 173 | position: relative; 174 | } 175 | 176 | #search-form input { 177 | width: 100%; 178 | padding-left: 28px; 179 | } 180 | 181 | #search-form span.glyphicon-search { 182 | position: absolute; 183 | left: 9px; 184 | top: 9px; 185 | font-size: 14px; 186 | z-index: 2; 187 | } 188 | 189 | /* Typeahead */ 190 | 191 | .twitter-typeahead { 192 | width: 100%; 193 | z-index: 1; 194 | } 195 | 196 | .tt-dropdown-menu { 197 | overflow: auto; 198 | max-height: 260px; 199 | margin-top: 9px; 200 | background-color: #fff; 201 | border: 1px solid #ccc; 202 | border-radius: 8px; 203 | box-shadow: 0 5px 10px rgba(0,0,0,.2); 204 | padding: 8px; 205 | } 206 | 207 | .tt-dropdown-menu p { 208 | margin: 0; 209 | padding: 0; 210 | } 211 | 212 | .tt-suggestion { 213 | padding: 8px; 214 | border-bottom: 1px solid #ccc; 215 | font-size: 1.1em; 216 | } 217 | 218 | .tt-cursor { 219 | background-color: #3875D7; 220 | color: #fff; 221 | } 222 | 223 | /** General typography **/ 224 | 225 | .navbar { 226 | border-bottom: 0; 227 | } 228 | 229 | .page-header { 230 | margin: 0 0 20px; 231 | } 232 | 233 | abbr[title], abbr[data-original-title], abbr { 234 | border-bottom: none; 235 | cursor: pointer; 236 | } 237 | 238 | a abbr { 239 | cursor: pointer; 240 | } 241 | 242 | /** General Sami styling **/ 243 | 244 | .underlined > .row { 245 | padding: 8px 0; 246 | border-bottom: 1px solid #ddd; 247 | } 248 | 249 | #footer { 250 | text-align: right; 251 | margin: 30px; 252 | font-size: 11px; 253 | } 254 | 255 | .description { 256 | margin: 10px 0; 257 | padding: 10px; 258 | background-color: #efefef; 259 | } 260 | 261 | .description p { 262 | padding: 0; 263 | margin: 8px 0; 264 | } 265 | 266 | .method-description { 267 | margin: 0 0 24px 0; 268 | } 269 | 270 | .details { 271 | padding-left: 30px; 272 | } 273 | 274 | #method-details .method-item { 275 | margin-bottom: 30px; 276 | } 277 | 278 | .method-item h3, 279 | .method-item h3 code { 280 | background-color: #eee; 281 | } 282 | 283 | .method-item h3 { 284 | padding: 4px; 285 | margin-bottom: 20px; 286 | font-size: 20px; 287 | } 288 | 289 | .location { 290 | font-size: 11px; 291 | float: right; 292 | font-style: italic; 293 | } 294 | 295 | .namespace-list a { 296 | padding: 3px 8px; 297 | margin: 0 5px 5px 0; 298 | border: 1px solid #ddd; 299 | background-color: #f9f9f9; 300 | display: inline-block; 301 | border-radius: 4px; 302 | } 303 | 304 | .no-description { 305 | color: #ccc; 306 | font-size: 90%; 307 | } 308 | 309 | /* Namespaces page */ 310 | 311 | .namespaces { 312 | clear: both; 313 | } 314 | 315 | .namespaces .namespace-container { 316 | float: left; 317 | margin: 0 14px 14px 0; 318 | min-width: 30%; 319 | } 320 | 321 | .namespaces h2 { 322 | margin: 0 0 20px 0; 323 | } 324 | 325 | @media (max-width: 991px) { 326 | .namespaces .namespace-container { 327 | margin-right: 0; 328 | width: 100%; 329 | } 330 | } 331 | 332 | /** Code and pre tags **/ 333 | 334 | tt, code, pre { 335 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; 336 | } 337 | 338 | code { 339 | padding: 0; 340 | padding-top: 0.2em; 341 | padding-bottom: 0.2em; 342 | margin: 0; 343 | font-size: 85%; 344 | background-color: rgba(0,0,0,0.04); 345 | border-radius: 3px; 346 | color: #333; 347 | } 348 | 349 | pre { 350 | padding: 16px; 351 | overflow: auto; 352 | font-size: 85%; 353 | line-height: 1.45; 354 | background-color: #f7f7f7; 355 | border-radius: 3px; 356 | } 357 | 358 | h2 { 359 | background-color: #EDF3FE; 360 | padding: 4px 4px 4px 8px; 361 | font-size: 25px; 362 | margin: 20px 0; 363 | } 364 | 365 | /** Doc index **/ 366 | 367 | dt { 368 | font-weight: normal; 369 | } 370 | 371 | dd { 372 | margin-left: 30px; 373 | line-height: 1.5em; 374 | } 375 | 376 | #doc-index h2 { 377 | font-weight: bold; 378 | margin: 30px 0; 379 | } 380 | 381 | #doc-index .pagination { 382 | margin: 0; 383 | } 384 | 385 | /* Search page */ 386 | 387 | .search-results { 388 | list-style-type: none; 389 | padding: 0; 390 | margin: 0; 391 | } 392 | 393 | .search-results li { 394 | list-style-type: none; 395 | margin: 0; 396 | padding: 14px 0; 397 | border-bottom: 1px solid #ccc; 398 | } 399 | 400 | .search-results h2 { 401 | background: none; 402 | margin: 0; 403 | padding: 0; 404 | font-size: 18px; 405 | } 406 | 407 | .search-results h2 a { 408 | float: left; 409 | display: block; 410 | margin: 0 0 4px 0; 411 | } 412 | 413 | .search-results .search-type { 414 | float: right; 415 | margin: 0 0 4px 0; 416 | } 417 | 418 | .search-results .search-from { 419 | margin: 0 0 12px 0; 420 | font-size: 12px; 421 | color: #999; 422 | } 423 | 424 | .search-results .search-from a { 425 | font-style: italic; 426 | } 427 | 428 | .search-results .search-description { 429 | margin: 8px 0 0 30px; 430 | } 431 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/StopWatch.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\StopWatch | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 70 |
    71 |
    72 | 73 | 79 | 80 |

    class 81 | StopWatch 82 |

    83 | 84 | 85 | 86 | 87 |
    88 |

    Class StopWatch 89 | Small utility class to measure the time of something.

    90 | 91 | 92 | 93 | 94 |

    Methods

    95 | 96 |
    97 |
    98 |
    99 | 100 |
    101 |
    102 | __construct(AbstractStorage $storage) 103 | 104 |

    StopWatch constructor.

    105 |
    106 |
    107 |
    108 |
    109 | 110 |
    111 |
    112 | start() 113 | 114 |

    To start the measurement.

    115 |
    116 |
    117 |
    118 |
    119 | 120 |
    121 |
    122 | stop($metric, $key) 123 | 124 |

    No description

    125 |
    126 |
    127 |
    128 |
    129 | 130 | 131 |

    Details

    132 | 133 |
    134 |
    135 |

    136 |
    at line line 40
    137 | 138 | __construct(AbstractStorage $storage) 139 | 140 |

    141 |
    142 | 143 | 144 | 145 |
    146 |

    StopWatch constructor.

    147 |
    148 |

    Parameters

    149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |
    AbstractStorage$storagethe storage to store the result at
    157 | 158 | 159 | 160 | 161 |
    162 |
    163 | 164 |
    165 |
    166 |

    167 |
    at line line 47
    168 | 169 | start() 170 | 171 |

    172 |
    173 | 174 | 175 | 176 |
    177 |

    To start the measurement.

    178 |
    179 | 180 | 181 | 182 |
    183 |
    184 | 185 |
    186 |
    187 |

    188 |
    at line line 59
    189 | 190 | stop($metric, $key) 191 | 192 |

    193 |
    194 | 195 | 196 | 197 |
    198 |

    Parameters

    199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 |
    $metric
    $key
    212 | 213 | 214 | 215 | 216 |
    217 |
    218 | 219 |
    220 |
    221 | 222 | 223 |
    224 | 227 | 228 |
    229 |
    230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PHPProm 2 | ------- 3 | 4 | PHPProm is a library to measure some performance relevant metrics and expose them for Prometheus. 5 | 6 | Its goal is to offer a simple, drop in solution to start measuring but 7 | without limiting customization. 8 | 9 | As the measurements are regulary collected by Prometheus visiting a 10 | specific endpoint, they need to be stored. PHPProm offeres support 11 | for various backends like Redis or Memcached. 12 | 13 | ![Grafana Sample](docs/grafana.png) 14 | 15 | ## Documentation 16 | 17 | - [API Documentation 0.1.0](http://philiplb.github.io/PHPProm/docs/0.1.0/) 18 | 19 | 20 | ## Package 21 | 22 | PHPProm uses [SemVer](http://semver.org/) for versioning. Currently, 23 | the API changes quickly due to be < 1.0.0, so take care about notes 24 | in the changelog when upgrading. 25 | 26 | ### Stable 27 | 28 | ```json 29 | "require": { 30 | "philiplb/phpprom": "0.1.0" 31 | } 32 | ``` 33 | 34 | ### Bleeding Edge 35 | 36 | ```json 37 | "require": { 38 | "philiplb/phpprom": "0.2.x-dev" 39 | } 40 | ``` 41 | 42 | ## Getting Started 43 | 44 | Here is an example about how to quickly get started measuring a Silex 45 | application using Redis as Storage: 46 | 47 | ### Prerequisites 48 | 49 | You need to have the 50 | [PHP redis extension](https://pecl.php.net/package/redis) installed. 51 | 52 | And you need to have a Redis server up and running. Here we just 53 | assume "localhost" as host and "supersecret" as authentication password. 54 | 55 | ### Require PHPProm 56 | 57 | The PHPProm package is integrated via composer: 58 | 59 | ```bash 60 | composer require "philiplb/phpprom" 61 | ``` 62 | 63 | ### Setup the Silex Application 64 | 65 | The first step is to create a storage object: 66 | 67 | ```PHP 68 | $storage = new PHPProm\Storage\Redis('localhost', 'supersecret'); 69 | ``` 70 | 71 | With this, the Silex setup can be called. It returns a function 72 | to be used as metrics route which can be scraped by Prometheus: 73 | 74 | ```PHP 75 | $silexPrometheusSetup = new PHPProm\Integration\SilexSetup(); 76 | $metricsAction = $silexPrometheusSetup->setupAndGetMetricsRoute($app, $storage); 77 | $app->get('/metrics', $metricsAction); 78 | ``` 79 | 80 | ## Integrations 81 | 82 | Integrating some Prometheus scrapable metrics should be as easy as 83 | possible. So some setup steps of frameworks are abstracted away into integrations in order to make PHPProm a drop in solution. 84 | 85 | More integrations are to come. If you have a specific request, just 86 | drop me a line. Or make a pull request. :) 87 | 88 | ### Silex 89 | 90 | The [Silex](http://silex.sensiolabs.org/) integration measures the 91 | following metrics: 92 | 93 | - Time spent per route as gauge 94 | - Consumed memory per route as gauge 95 | - How often each route has been called as counter 96 | 97 | Each metric has the route as label "name". Wheras the slashes 98 | are replaced by underscores and the route method is prefixed. So a 99 | route like this 100 | 101 | ```PHP 102 | $app->get('my/great/{route}', function($route) { 103 | // ... 104 | }); 105 | ``` 106 | gets the label "GET\_my\_great_{route}". 107 | 108 | This integration requires the package 109 | ["silex/silex"](https://packagist.org/packages/silex/silex). 110 | 111 | It is represented by the class 112 | _PHPProm\Integration\SilexSetup_ with it's usage explained in the 113 | "Getting Started" section. 114 | 115 | Adding more metrics is easy via the function _addAvailableMetric_ of 116 | the storage instance. See the subchapter for custom integrations for 117 | a detailed explanation of the parameters. 118 | 119 | The actual measurements are added via the according storage instance 120 | functions (see again the custom integrations subchapter). All data 121 | automatically appears within the metrics endpoint. 122 | 123 | ### Custom Integration 124 | 125 | Writing a custom integration consists of three parts. First, the metrics have to be setup, second measurements needs to happen and third, a Prometheus scrapable metrics endpoint has to be offered. 126 | 127 | First, the metrics to measure have to be added to the storage 128 | instance via the method _addAvailableMetric_: 129 | 130 | ```PHP 131 | $storage->addAvailableMetric( 132 | $metric, // the Prometheus metric name itself 133 | $label, // the name of the one Prometheus label to categorize the values 134 | $help, // a small, meaningful help text for the metric 135 | $type, // the Prometheus type of the metric like "gauge" or "counter" 136 | $defaultValue // the default value to be taken if no measurement happened yet for the metric/label combination, "Nan" for example or "0" 137 | ); 138 | ``` 139 | 140 | Now, the measurements have to happen. The storage object offers two 141 | methods for this: 142 | 143 | - _storeMeasurement($metric, $key, $value):_ to store a raw value for a 144 | metric under the given key 145 | - _incrementMeasurement($metric, $key):_ increments a counter for the 146 | metric under the given key, starts with 1 if it didn't exist before 147 | 148 | There is a little helper class to measure time, the _PHPProm\StopWatch_. To start the measurement, call its function 149 | _start()_ and to stop and store the measurement, call the function 150 | _stop($metric, $key)_. The parameters have the same meaning as the 151 | storage function parameters. 152 | 153 | The third part is to offer an endpoint delivering the metrics. To get 154 | the content, the class _PHPProm\PrometheusExport_ exists. It has a 155 | single public function _getExport(AbstractStorage $storage, $keys)_ 156 | where the storage instance is handed in along with all expected keys. 157 | The function returns a string with all the Prometheus data to be used 158 | as response in the endpoint. It should be delivered with the 159 | "Content-Type: text/plain; version=0.0.4". 160 | 161 | ## Storage Implementations 162 | 163 | There are several storage implementations available for the 164 | measurements so the metrics endpoint can deliver them. It is also easy 165 | to write an own one if the existing ones don't cover the use case. 166 | They are all in the namespace _PHPProm\Storage_. 167 | 168 | ### Redis 169 | 170 | The Redis storage needs to have the [PHP redis extension](https://pecl.php.net/package/redis) installed. Its constructor takes the 171 | following parameters: 172 | 173 | - _string $host:_ the connection host 174 | - _null|string $password:_ the password for authentication, null to ignore 175 | - _int $port:_ the connection port, default 6379 176 | - _string $prefix:_ the global key prefix to use, default 'PHPProm:' 177 | - _null|string $dbIndex:_ the Redis DB index to use, null to ignore 178 | 179 | It is very fast and offers persistence, so this one is the recommended 180 | storage implementation. 181 | 182 | ### Memcached 183 | 184 | The Memcached storage implementation needs to have the [PHP memcached extension](http://php.net/manual/en/book.memcached.php) installed. Its 185 | constructor takes the following parameters: 186 | 187 | - _string $host:_ the connection host 188 | - _int $port:_ the connection port, default 11211 189 | - _string $prefix:_ the global key prefix to use, default 'PHPProm:' 190 | 191 | This storage implementation is even faster then Redis, but offers no 192 | persistence and so is not recommended if there are counters measured 193 | over time for example which should not be lost. 194 | 195 | ### DBAL 196 | 197 | The DBAL storage implementation needs to have the package 198 | "doctrine/dbal" and the prerequisites of the used driver must be 199 | fullfilled. Currently, the MySQL, PostgreSQL and SQLite drivers have 200 | been tested. But the SQL statements have been kept simple in order to 201 | be compatible with many of the DBAL supported databases. Give me a 202 | shout if you find something not working. 203 | 204 | Its constructor takes the following parameters: 205 | 206 | - _\Doctrine\DBAL\Connection $connection:_ the DBAL connection 207 | - _string $table:_ the table to use 208 | 209 | The MySQL scheme of the table is: 210 | 211 | ```SQL 212 | CREATE TABLE `phpprom` ( 213 | `key` varchar(255) NOT NULL, 214 | `value` double NOT NULL, 215 | PRIMARY KEY (`key`) 216 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 217 | ``` 218 | 219 | The SQLite scheme of the table is: 220 | 221 | ```SQL 222 | CREATE TABLE `phpprom` ( 223 | `key` TEXT NOT NULL UNIQUE, 224 | `value` REAL NOT NULL, 225 | PRIMARY KEY(`key`) 226 | ); 227 | ``` 228 | 229 | The PostgreSQL scheme of the table is: 230 | 231 | ```SQL 232 | CREATE TABLE public.phpprom ( 233 | key VARCHAR(255) PRIMARY KEY NOT NULL, 234 | value DOUBLE PRECISION NOT NULL 235 | ); 236 | CREATE UNIQUE INDEX phpprom_key_uindex ON public.phpprom (key); 237 | ``` 238 | 239 | This one is possibly the slowest one, but offers a secure data storage 240 | and is mostly available in existing stacks. 241 | 242 | 243 | ### MongoDB 244 | 245 | The MongoDB storage needs to have the [PHP MongoDB driver](http://php.net/manual/en/set.mongodb.php) installed. Its 246 | constructor takes the following parameters: 247 | 248 | - _string $host_: a mongodb:// connection URI 249 | - _string $database_: the database to use, defaults to "phppromdb" 250 | - _string $collection_: the collection to use, defaults to "measurements" 251 | - _array $options_: connection string options, defaults to [] 252 | - _array $driverOptions_: any driver-specific options not included in MongoDB connection spec, defaults to [] 253 | 254 | This storage should be reasonable fast, offers persistence but should maybe only taken if Redis, MySQL or PostgreSQL is 255 | not available. 256 | 257 | ### Custom 258 | 259 | In case you want to store the measurements in a different backend, 260 | you can inherit your implementation from _PHPProm\Storage\AbstractStorage_ and implement the abstract methods: 261 | 262 | - _abstract public function storeMeasurement($metric, $key, $value):_ 263 | Stores a measurement. 264 | - _abstract public function incrementMeasurement($metric, $key):_ 265 | Increments a measurement, starting with 1 if it doesn't exist yet. 266 | - _abstract public function getMeasurements($metric, array $keys, $defaultValue = 'Nan'):_ 267 | Gets all measurements. 268 | 269 | New storage implementations would make a good pull request again. :) 270 | 271 | ## Status 272 | 273 | [![Build Status](https://travis-ci.org/philiplb/PHPProm.svg?branch=master)](https://travis-ci.org/philiplb/PHPProm) 274 | [![Coverage Status](https://coveralls.io/repos/philiplb/PHPProm/badge.png?branch=master)](https://coveralls.io/r/philiplb/PHPProm?branch=master) 275 | 276 | [![SensioLabsInsight](https://insight.sensiolabs.com/projects/e0026986-7a55-4a9f-9086-53abe1918556/mini.png)](https://insight.sensiolabs.com/projects/e0026986-7a55-4a9f-9086-53abe1918556) 277 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/philiplb/PHPProm/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/philiplb/PHPProm/?branch=master) 278 | 279 | [![Total Downloads](https://poser.pugx.org/philiplb/phpprom/downloads.svg)](https://packagist.org/packages/philiplb/phpprom) 280 | [![Latest Stable Version](https://poser.pugx.org/philiplb/phpprom/v/stable.svg)](https://packagist.org/packages/phpprom/crudlex) 281 | [![Latest Unstable Version](https://poser.pugx.org/philiplb/phpprom/v/unstable.svg)](https://packagist.org/packages/phpprom/crudlex) [![License](https://poser.pugx.org/philiplb/phpprom/license.svg)](https://packagist.org/packages/philiplb/phpprom) 282 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Storage/AbstractStorage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Storage\AbstractStorage | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 71 |
    72 |
    73 | 74 | 80 | 81 |

    class 82 | AbstractStorage 83 |

    84 | 85 | 86 | 87 | 88 |
    89 |

    Class AbstractStorage 90 | The parent class of all storage implementations.

    91 | 92 | 93 | 94 | 95 |

    Methods

    96 | 97 |
    98 |
    99 |
    100 | 101 |
    102 |
    103 | __construct() 104 | 105 |

    AbstractStorage constructor.

    106 |
    107 |
    108 |
    109 |
    110 | 111 |
    112 |
    113 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 114 | 115 |

    Adds a metric to the available ones.

    116 |
    117 |
    118 |
    119 |
    120 | array 121 |
    122 |
    123 | getAvailableMetrics() 124 | 125 |

    Gets all available metrics in an array.

    126 |
    127 |
    128 |
    129 |
    130 | void 131 |
    132 |
    133 | storeMeasurement(string $metric, string $key, float $value) 134 | 135 |

    Stores a measurement.

    136 |
    137 |
    138 |
    139 |
    140 | void 141 |
    142 |
    143 | incrementMeasurement(string $metric, string $key) 144 | 145 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    146 |
    147 |
    148 |
    149 |
    150 | array 151 |
    152 |
    153 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 154 | 155 |

    Gets all measurements.

    156 |
    157 |
    158 |
    159 | 160 | 161 |

    Details

    162 | 163 |
    164 |
    165 |

    166 |
    at line line 30
    167 | 168 | __construct() 169 | 170 |

    171 |
    172 | 173 | 174 | 175 |
    176 |

    AbstractStorage constructor.

    177 |
    178 | 179 | 180 | 181 |
    182 |
    183 | 184 |
    185 |
    186 |

    187 |
    at line line 48
    188 | 189 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 190 | 191 |

    192 |
    193 | 194 | 195 | 196 |
    197 |

    Adds a metric to the available ones.

    198 |
    199 |

    Parameters

    200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 |
    string$metricthe metric itself as delivered by Prometheus
    string$labelthe name of the one Prometheus label to categorize the values
    string$helpa helping text for the metric
    string$typethe Prometheus type of the metric
    string$defaultValuethe default value which the metric gets if there is no value stored
    228 | 229 | 230 | 231 | 232 |
    233 |
    234 | 235 |
    236 |
    237 |

    238 |
    at line line 64
    239 | array 240 | getAvailableMetrics() 241 | 242 |

    243 |
    244 | 245 | 246 | 247 |
    248 |

    Gets all available metrics in an array.

    249 |
    250 | 251 |

    Return Value

    252 | 253 | 254 | 255 | 256 | 257 | 258 |
    arraythe available metrics
    259 | 260 | 261 | 262 |
    263 |
    264 | 265 |
    266 |
    267 |

    268 |
    at line line 79
    269 | abstract void 270 | storeMeasurement(string $metric, string $key, float $value) 271 | 272 |

    273 |
    274 | 275 | 276 | 277 |
    278 |

    Stores a measurement.

    279 |
    280 |

    Parameters

    281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 |
    string$metricthe name of the metric
    string$keythe key
    float$valuethe value
    299 | 300 | 301 |

    Return Value

    302 | 303 | 304 | 305 | 306 | 307 | 308 |
    void
    309 | 310 | 311 | 312 |
    313 |
    314 | 315 |
    316 |
    317 |

    318 |
    at line line 89
    319 | abstract void 320 | incrementMeasurement(string $metric, string $key) 321 | 322 |

    323 |
    324 | 325 | 326 | 327 |
    328 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    329 |
    330 |

    Parameters

    331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 |
    string$metricthe name of the metric
    string$keythe key
    344 | 345 | 346 |

    Return Value

    347 | 348 | 349 | 350 | 351 | 352 | 353 |
    void
    354 | 355 | 356 | 357 |
    358 |
    359 | 360 |
    361 |
    362 |

    363 |
    at line line 103
    364 | abstract array 365 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 366 | 367 |

    368 |
    369 | 370 | 371 | 372 |
    373 |

    Gets all measurements.

    374 |
    375 |

    Parameters

    376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 |
    string$metricthe name of the metric
    array$keysthe keys to retrieve
    string$defaultValuethe default value a key gets if there is no value for it in the storage
    394 | 395 | 396 |

    Return Value

    397 | 398 | 399 | 400 | 401 | 402 | 403 |
    arraythe map with the keys and values
    404 | 405 | 406 | 407 |
    408 |
    409 | 410 |
    411 |
    412 | 413 | 414 |
    415 | 418 | 419 |
    420 |
    421 | 422 | 423 | 424 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Storage/Memcached.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Storage\Memcached | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 71 |
    72 |
    73 | 74 | 80 | 81 |

    class 82 | Memcached extends AbstractStorage 83 |

    84 | 85 | 86 | 87 | 88 |
    89 |

    Class Memcached 90 | Storage implementation using memcached.

    91 | 92 | 93 | 94 | 95 |

    Methods

    96 | 97 |
    98 |
    99 |
    100 | 101 |
    102 |
    103 | __construct(string $host, int $port = 11211, string $prefix = 'PHPProm:') 104 | 105 |

    Memcached constructor.

    106 |
    107 |
    108 |
    109 |
    110 | 111 |
    112 |
    113 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 114 | 115 |

    Adds a metric to the available ones.

    116 | 117 |
    118 |
    119 |
    120 | array 121 |
    122 |
    123 | getAvailableMetrics() 124 | 125 |

    Gets all available metrics in an array.

    126 | 127 |
    128 |
    129 |
    130 | void 131 |
    132 |
    133 | storeMeasurement(string $metric, string $key, float $value) 134 | 135 |

    Stores a measurement.

    136 |
    137 |
    138 |
    139 |
    140 | void 141 |
    142 |
    143 | incrementMeasurement(string $metric, string $key) 144 | 145 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    146 |
    147 |
    148 |
    149 |
    150 | array 151 |
    152 |
    153 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 154 | 155 |

    Gets all measurements.

    156 |
    157 |
    158 |
    159 | 160 | 161 |

    Details

    162 | 163 |
    164 |
    165 |

    166 |
    at line line 43
    167 | 168 | __construct(string $host, int $port = 11211, string $prefix = 'PHPProm:') 169 | 170 |

    171 |
    172 | 173 | 174 | 175 |
    176 |

    Memcached constructor.

    177 |
    178 |

    Parameters

    179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 |
    string$hostthe connection host
    int$portthe connection port, default 11211
    string$prefixthe global key prefix to use, default 'PHPProm:'
    197 | 198 | 199 | 200 | 201 |
    202 |
    203 | 204 |
    205 |
    206 |

    207 |
    in AbstractStorage at line line 48
    208 | 209 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 210 | 211 |

    212 |
    213 | 214 | 215 | 216 |
    217 |

    Adds a metric to the available ones.

    218 |
    219 |

    Parameters

    220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 |
    string$metricthe metric itself as delivered by Prometheus
    string$labelthe name of the one Prometheus label to categorize the values
    string$helpa helping text for the metric
    string$typethe Prometheus type of the metric
    string$defaultValuethe default value which the metric gets if there is no value stored
    248 | 249 | 250 | 251 | 252 |
    253 |
    254 | 255 |
    256 |
    257 |

    258 |
    in AbstractStorage at line line 64
    259 | array 260 | getAvailableMetrics() 261 | 262 |

    263 |
    264 | 265 | 266 | 267 |
    268 |

    Gets all available metrics in an array.

    269 |
    270 | 271 |

    Return Value

    272 | 273 | 274 | 275 | 276 | 277 | 278 |
    arraythe available metrics
    279 | 280 | 281 | 282 |
    283 |
    284 | 285 |
    286 |
    287 |

    288 |
    at line line 53
    289 | void 290 | storeMeasurement(string $metric, string $key, float $value) 291 | 292 |

    293 |
    294 | 295 | 296 | 297 |
    298 |

    Stores a measurement.

    299 |
    300 |

    Parameters

    301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 |
    string$metricthe name of the metric
    string$keythe key
    float$valuethe value
    319 | 320 | 321 |

    Return Value

    322 | 323 | 324 | 325 | 326 | 327 | 328 |
    void
    329 | 330 | 331 | 332 |
    333 |
    334 | 335 |
    336 |
    337 |

    338 |
    at line line 60
    339 | void 340 | incrementMeasurement(string $metric, string $key) 341 | 342 |

    343 |
    344 | 345 | 346 | 347 |
    348 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    349 |
    350 |

    Parameters

    351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 |
    string$metricthe name of the metric
    string$keythe key
    364 | 365 | 366 |

    Return Value

    367 | 368 | 369 | 370 | 371 | 372 | 373 |
    void
    374 | 375 | 376 | 377 |
    378 |
    379 | 380 |
    381 |
    382 |

    383 |
    at line line 74
    384 | array 385 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 386 | 387 |

    388 |
    389 | 390 | 391 | 392 |
    393 |

    Gets all measurements.

    394 |
    395 |

    Parameters

    396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 |
    string$metricthe name of the metric
    array$keysthe keys to retrieve
    string$defaultValuethe default value a key gets if there is no value for it in the storage
    414 | 415 | 416 |

    Return Value

    417 | 418 | 419 | 420 | 421 | 422 | 423 |
    arraythe map with the keys and values
    424 | 425 | 426 | 427 |
    428 |
    429 | 430 |
    431 |
    432 | 433 | 434 |
    435 | 438 | 439 |
    440 |
    441 | 442 | 443 | 444 | -------------------------------------------------------------------------------- /docs/0.1.0/PHPProm/Storage/DBAL.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | PHPProm\Storage\DBAL | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 71 |
    72 |
    73 | 74 | 80 | 81 |

    class 82 | DBAL extends AbstractStorage 83 |

    84 | 85 | 86 | 87 | 88 |
    89 |

    Class DBAL 90 | Storage implementation using Doctrine DBAL.

    This way, MySQL and other databases are supported. 91 | The used SQL is kept very simple so the queries should work 92 | with most of the DBAL supported databases.

    93 | 94 |

    A MySQL example of the expected table: 95 | CREATE TABLE phpprom ( 96 | key varchar(255) NOT NULL, 97 | value double NOT NULL, 98 | PRIMARY KEY (key) 99 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    100 | 101 | 102 | 103 | 104 |

    Methods

    105 | 106 |
    107 |
    108 |
    109 | 110 |
    111 |
    112 | __construct(Connection $connection, string $table = 'phpprom') 113 | 114 |

    DBAL constructor.

    115 |
    116 |
    117 |
    118 |
    119 | 120 |
    121 |
    122 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 123 | 124 |

    Adds a metric to the available ones.

    125 | 126 |
    127 |
    128 |
    129 | array 130 |
    131 |
    132 | getAvailableMetrics() 133 | 134 |

    Gets all available metrics in an array.

    135 | 136 |
    137 |
    138 |
    139 | void 140 |
    141 |
    142 | storeMeasurement(string $metric, string $key, float $value) 143 | 144 |

    Stores a measurement.

    145 |
    146 |
    147 |
    148 |
    149 | void 150 |
    151 |
    152 | incrementMeasurement(string $metric, string $key) 153 | 154 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    155 |
    156 |
    157 |
    158 |
    159 | array 160 |
    161 |
    162 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 163 | 164 |

    Gets all measurements.

    165 |
    166 |
    167 |
    168 | 169 | 170 |

    Details

    171 | 172 |
    173 |
    174 |

    175 |
    at line line 119
    176 | 177 | __construct(Connection $connection, string $table = 'phpprom') 178 | 179 |

    180 |
    181 | 182 | 183 | 184 |
    185 |

    DBAL constructor.

    186 |
    187 |

    Parameters

    188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 |
    Connection$connectionthe DBAL connection
    string$tablethe table to use
    201 | 202 | 203 | 204 | 205 |
    206 |
    207 | 208 |
    209 |
    210 |

    211 |
    in AbstractStorage at line line 48
    212 | 213 | addAvailableMetric(string $metric, string $label, string $help, string $type, string $defaultValue) 214 | 215 |

    216 |
    217 | 218 | 219 | 220 |
    221 |

    Adds a metric to the available ones.

    222 |
    223 |

    Parameters

    224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 |
    string$metricthe metric itself as delivered by Prometheus
    string$labelthe name of the one Prometheus label to categorize the values
    string$helpa helping text for the metric
    string$typethe Prometheus type of the metric
    string$defaultValuethe default value which the metric gets if there is no value stored
    252 | 253 | 254 | 255 | 256 |
    257 |
    258 | 259 |
    260 |
    261 |

    262 |
    in AbstractStorage at line line 64
    263 | array 264 | getAvailableMetrics() 265 | 266 |

    267 |
    268 | 269 | 270 | 271 |
    272 |

    Gets all available metrics in an array.

    273 |
    274 | 275 |

    Return Value

    276 | 277 | 278 | 279 | 280 | 281 | 282 |
    arraythe available metrics
    283 | 284 | 285 | 286 |
    287 |
    288 | 289 |
    290 |
    291 |

    292 |
    at line line 130
    293 | void 294 | storeMeasurement(string $metric, string $key, float $value) 295 | 296 |

    297 |
    298 | 299 | 300 | 301 |
    302 |

    Stores a measurement.

    303 |
    304 |

    Parameters

    305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 |
    string$metricthe name of the metric
    string$keythe key
    float$valuethe value
    323 | 324 | 325 |

    Return Value

    326 | 327 | 328 | 329 | 330 | 331 | 332 |
    void
    333 | 334 | 335 | 336 |
    337 |
    338 | 339 |
    340 |
    341 |

    342 |
    at line line 144
    343 | void 344 | incrementMeasurement(string $metric, string $key) 345 | 346 |

    347 |
    348 | 349 | 350 | 351 |
    352 |

    Increments a measurement, starting with 1 if it doesn't exist yet.

    353 |
    354 |

    Parameters

    355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 |
    string$metricthe name of the metric
    string$keythe key
    368 | 369 | 370 |

    Return Value

    371 | 372 | 373 | 374 | 375 | 376 | 377 |
    void
    378 | 379 | 380 | 381 |
    382 |
    383 | 384 |
    385 |
    386 |

    387 |
    at line line 162
    388 | array 389 | getMeasurements(string $metric, array $keys, string $defaultValue = 'Nan') 390 | 391 |

    392 |
    393 | 394 | 395 | 396 |
    397 |

    Gets all measurements.

    398 |
    399 |

    Parameters

    400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
    string$metricthe name of the metric
    array$keysthe keys to retrieve
    string$defaultValuethe default value a key gets if there is no value for it in the storage
    418 | 419 | 420 |

    Return Value

    421 | 422 | 423 | 424 | 425 | 426 | 427 |
    arraythe map with the keys and values
    428 | 429 | 430 | 431 |
    432 |
    433 | 434 |
    435 |
    436 | 437 | 438 |
    439 | 442 | 443 |
    444 |
    445 | 446 | 447 | 448 | -------------------------------------------------------------------------------- /docs/0.1.0/doc-index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Index | PHPProm API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 |
    27 | 28 | 32 |
    33 |
    34 | 35 |
    36 | 37 |
    38 |
    39 | 62 | 63 |
    64 | 65 | 68 | 69 |
      70 |
    • A
    • 71 |
    • B
    • 72 |
    • C
    • 73 |
    • D
    • 74 |
    • E
    • 75 |
    • F
    • 76 |
    • G
    • 77 |
    • H
    • 78 |
    • I
    • 79 |
    • J
    • 80 |
    • K
    • 81 |
    • L
    • 82 |
    • M
    • 83 |
    • N
    • 84 |
    • O
    • 85 |
    • P
    • 86 |
    • Q
    • 87 |
    • R
    • 88 |
    • S
    • 89 |
    • T
    • 90 |
    • U
    • 91 |
    • V
    • 92 |
    • W
    • 93 |
    • X
    • 94 |
    • Y
    • 95 |
    • Z
    • 96 |
    97 | 98 |

    A

    99 |
    AbstractStorageClass in namespace PHPProm\Storage
    100 |
    Class AbstractStorage 101 | The parent class of all storage implementations.
    AbstractStorage::addAvailableMetric() — Method in class AbstractStorage
    102 |
    Adds a metric to the available ones.

    D

    103 |
    DBALClass in namespace PHPProm\Storage
    104 |
    Class DBAL 105 | Storage implementation using Doctrine DBAL.

    G

    106 |
    PrometheusExport::getExport() — Method in class PrometheusExport
    107 |
    Gets a Prometheus export of the given storage.
    AbstractStorage::getAvailableMetrics() — Method in class AbstractStorage
    108 |
    Gets all available metrics in an array.
    AbstractStorage::getMeasurements() — Method in class AbstractStorage
    109 |
    Gets all measurements.
    DBAL::getMeasurements() — Method in class DBAL
    110 |
    Gets all measurements.
    Memcached::getMeasurements() — Method in class Memcached
    111 |
    Gets all measurements.
    MongoDB::getMeasurements() — Method in class MongoDB
    112 |
    Gets all measurements.
    Redis::getMeasurements() — Method in class Redis
    113 |
    Gets all measurements.

    I

    114 |
    AbstractStorage::incrementMeasurement() — Method in class AbstractStorage
    115 |
    Increments a measurement, starting with 1 if it doesn't exist yet.
    DBAL::incrementMeasurement() — Method in class DBAL
    116 |
    Increments a measurement, starting with 1 if it doesn't exist yet.
    Memcached::incrementMeasurement() — Method in class Memcached
    117 |
    Increments a measurement, starting with 1 if it doesn't exist yet.
    MongoDB::incrementMeasurement() — Method in class MongoDB
    118 |
    Increments a measurement, starting with 1 if it doesn't exist yet.
    Redis::incrementMeasurement() — Method in class Redis
    119 |
    Increments a measurement, starting with 1 if it doesn't exist yet.

    M

    120 |
    MemcachedClass in namespace PHPProm\Storage
    121 |
    Class Memcached 122 | Storage implementation using memcached.
    MongoDBClass in namespace PHPProm\Storage
    123 |
    Class MongoDB 124 | Storage implementation using MongoDB.

    P

    125 |
    PrometheusExportClass in namespace PHPProm
    126 |
    Class PrometheusExport 127 | To export the measurements into the Prometheus format.

    R

    128 |
    RedisClass in namespace PHPProm\Storage
    129 |
    Class Redis 130 | Storage implementation using Redis.

    S

    131 |
    SilexSetupClass in namespace PHPProm\Integration
    132 |
    Class SilexSetup 133 | Setups Silex applications to measure: 134 | - the time of each route 135 | - the used memory of each route 136 | - the amount of requests of each route 137 | It also offers an function to be used for a Prometheus scrapable endpoint.
    SilexSetup::setupAndGetMetricsRoute() — Method in class SilexSetup
    138 |
    Sets up the Silex middlewares where the actual measurements happen 139 | and returns a function to be used for a Prometheus scrapable endpoint.
    StopWatchClass in namespace PHPProm
    140 |
    Class StopWatch 141 | Small utility class to measure the time of something.
    StopWatch::start() — Method in class StopWatch
    142 |
    To start the measurement.
    StopWatch::stop() — Method in class StopWatch
    143 |
    AbstractStorage::storeMeasurement() — Method in class AbstractStorage
    144 |
    Stores a measurement.
    DBAL::storeMeasurement() — Method in class DBAL
    145 |
    Stores a measurement.
    Memcached::storeMeasurement() — Method in class Memcached
    146 |
    Stores a measurement.
    MongoDB::storeMeasurement() — Method in class MongoDB
    147 |
    Stores a measurement.
    Redis::storeMeasurement() — Method in class Redis
    148 |
    Stores a measurement.

    _

    149 |
    StopWatch::__construct() — Method in class StopWatch
    150 |
    StopWatch constructor.
    AbstractStorage::__construct() — Method in class AbstractStorage
    151 |
    AbstractStorage constructor.
    DBAL::__construct() — Method in class DBAL
    152 |
    DBAL constructor.
    Memcached::__construct() — Method in class Memcached
    153 |
    Memcached constructor.
    MongoDB::__construct() — Method in class MongoDB
    154 |
    MongoDB constructor.
    Redis::__construct() — Method in class Redis
    155 |
    Redis constructor.
    156 | 159 | 160 |
    161 |
    162 | 163 | 164 | 165 | --------------------------------------------------------------------------------