memcrab/metrics

Coroutine-compatible metrics client for InfluxDB V2 (Telegraf listener input)

1.0.1 2025-04-10 07:59 UTC

This package is auto-updated.

Last update: 2025-04-10 10:10:50 UTC


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.