An open API service indexing awesome lists of open source software.

https://github.com/roadrunner-php/metrics

:electric_plug: RoadRunner Metrics SDK
https://github.com/roadrunner-php/metrics

grafana metrics php prometheus prometheus-metrics roadrunner

Last synced: 12 months ago
JSON representation

:electric_plug: RoadRunner Metrics SDK

Awesome Lists containing this project

README

          






# RoadRunner Metrics Plugin

[![PHP Version Require](https://poser.pugx.org/spiral/roadrunner-metrics/require/php)](https://packagist.org/packages/spiral/roadrunner-metrics)
[![Latest Stable Version](https://poser.pugx.org/spiral/roadrunner-metrics/version)](https://packagist.org/packages/spiral/roadrunner-metrics)
[![phpunit](https://github.com/spiral/roadrunner-metrics/actions/workflows/phpunit.yml/badge.svg)](https://github.com/spiral/roadrunner-metrics/actions)
[![psalm](https://github.com/spiral/roadrunner-metrics/actions/workflows/psalm.yml/badge.svg)](https://github.com/spiral/roadrunner-metrics/actions)
[![Total Downloads](https://poser.pugx.org/spiral/roadrunner-metrics/downloads)](https://packagist.org/packages/spiral/roadrunner-metrics)

This repository contains the codebase PHP bridge using RoadRunner Metrics plugin.

## Installation:

To install RoadRunner extension:

```bash
composer require spiral/roadrunner-metrics
```

You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:

```bash
composer require spiral/roadrunner-cli --dev
vendor/bin/rr get
```

## Configuration

Enable metrics service in your `.rr.yaml` file:

```yaml
rpc:
listen: tcp://127.0.0.1:6001

server:
command: "php worker.php"

http:
address: "0.0.0.0:8080"

metrics:
address: "0.0.0.0:2112"
```

## Usage

To publish metrics from your application worker:

```php
getRPCAddress())
);

# Declare counter
$metrics->declare(
'http_requests',
RoadRunner\Metrics\Collector::counter()
->withHelp('Collected HTTP requests.')
->withLabels('status', 'method'),
);

while ($req = $worker->waitRequest()) {
try {
$response = new \Nyholm\Psr7\Response();
$response->getBody()->write("hello world");

# Publish metrics for each request with labels (status, method)
$metrics->add('http_requests', 1, [
$response->getStatusCode(),
$req->getMethod(),
]);

$worker->respond($rsp);
} catch (\Throwable $e) {
$worker->getWorker()->error((string)$e);

$metrics->add('http_requests', 1, [503,$req->getMethod(),]);
}
}
```


try Spiral Framework

## License:

The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained
by [Spiral Scout](https://spiralscout.com).