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.
- 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.
composer require memcrab/metrics
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');
Metric::obj()->write('cpu_usage', [
'host' => 'server01'
],
[
'usage' => 45
],
time()
);
The gem is available as open source under the terms of the MIT License.