clivern / metric
Observability SDK for PHP Applications.
Fund package maintenance!
clivern
Requires
- php: >=7.0
- ext-memcached: *
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.0.0
- phpunit/phpunit: 9.5.6
- squizlabs/php_codesniffer: 3.6.0
This package is auto-updated.
Last update: 2024-11-16 13:13:41 UTC
README
Observability SDK
Observability SDK for PHP Applications
Documentation
Installation:
To install the package via composer
, use the following:
$ composer require clivern/observability-php-sdk
This command requires you to have composer
installed globally.
Graphite Reporter:
use Clivern\Observability\Aggregation\MemcachedAggregate; use Clivern\Observability\Aggregation\Client\MemcachedClient; use Clivern\Observability\Reporter\GraphiteClient; $metricsReporter = new MemcachedAggregate( new GraphiteClient('localhost', 2003), new MemcachedClient('127.0.0.1', 11211), [] ); $metricsReporter->report([ [ 'key' => 'orders_service.metrics.total_http_calls', 'value' => 1, 'time' => time(), 'aggregateFunc' => MemcachedAggregate::SUM_AGGREGATE_FUNCTION ] ]);
For PHP
runtime statistics, You can use this class Clivern\Observability\Stats\Runtime
.
To measure the execution time:
use Clivern\Observability\Stats\Execution; $execution = new Execution(); $execution->start(); // Code that takes time! sleep(2); $execution->end(); var_dump($execution->getTimeInSeconds()); // float var_dump($execution->getTimeInMinutes()); // float
To measure latency of an HTTP call or application latency.
use Clivern\Observability\Aggregation\MemcachedAggregate; use Clivern\Observability\Aggregation\Client\MemcachedClient; use Clivern\Observability\Reporter\GraphiteClient; $metricsReporter = new MemcachedAggregate( new GraphiteClient('localhost', 2003), new MemcachedClient('127.0.0.1', 11211), [] ); $execution = new Execution(); $execution->start(); // Code that takes time! sleep(2); $execution->end(); $metricsReporter->report([ [ 'key' => 'orders_service.metrics.http_request_latency', 'value' => $execution->getTimeInSeconds(), 'time' => time(), 'aggregateFunc' => MemcachedAggregate::AVG_AGGREGATE_FUNCTION ] ]);
Elasticsearch Reporter:
#
Versioning
For transparency into our release cycle and in striving to maintain backward compatibility, observability-php-sdk is maintained under the Semantic Versioning guidelines and release process is predictable and business-friendly.
See the Releases section of our GitHub project for changelogs for each release version of observability-php-sdk. It contains summaries of the most noteworthy changes made in each release.
Bug tracker
If you have any suggestions, bug reports, or annoyances please report them to our issue tracker at https://github.com/clivern/observability-php-sdk/issues
Security Issues
If you discover a security vulnerability within observability-php-sdk, please send an email to hello@clivern.com
Contributing
We are an open source, community-driven project so please feel free to join us. see the contributing guidelines for more details.
License
© 2020, clivern. Released under MIT License.
observability-php-sdk is authored and maintained by @clivern.