memcrab / metrics
Coroutine-compatible metrics client for InfluxDB V2 (Telegraf listener input)
1.0.1
2025-04-10 07:59 UTC
Requires
- php: >=8.0
- influxdata/influxdb-client-php: 3.1.0
- openswoole/core: ^22.1
Requires (Dev)
- phpunit/phpunit: 9.*.*
README
Memcrab Metrics is a library that provides an additional layer over the InfluxDB client to asynchronously send metrics to InfluxDB. It integrates with OpenSwoole for coroutine-based asynchronous operations and uses the InfluxDB line protocol for metric formatting.
Features
- Asynchronous metric sending with OpenSwoole coroutine support.
- Easy integration with InfluxDB client (version 3.1.0).
- Allows metrics to be sent in the InfluxDB line protocol format.
Installation
composer require memcrab/metrics
Usage
Initialize a client
You must call init() before sending any metrics. If you want to disable metric sending (e.g., in a LOCAL or test environment), pass false as the second argument.
$influxDBListenerUrl = 'http://127.0.0.1:8186/api/v2/write'; Metric::obj()->init($influxDBListenerUrl, ENVIRONMENT !== 'local');
Sending Metrics
Metric::obj()->write('cpu_usage', [ 'host' => 'server01' ], [ 'usage' => 45 ], time() );
License
The gem is available as open source under the terms of the MIT License.