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
- Host: GitHub
- URL: https://github.com/roadrunner-php/metrics
- Owner: roadrunner-php
- License: mit
- Created: 2020-12-02T10:31:33.000Z (over 5 years ago)
- Default Branch: 3.x
- Last Pushed: 2024-09-23T14:03:45.000Z (over 1 year ago)
- Last Synced: 2025-04-09T22:55:54.878Z (12 months ago)
- Topics: grafana, metrics, php, prometheus, prometheus-metrics, roadrunner
- Language: PHP
- Homepage: https://roadrunner.dev
- Size: 42 KB
- Stars: 4
- Watchers: 7
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# RoadRunner Metrics Plugin
[](https://packagist.org/packages/spiral/roadrunner-metrics)
[](https://packagist.org/packages/spiral/roadrunner-metrics)
[](https://github.com/spiral/roadrunner-metrics/actions)
[](https://github.com/spiral/roadrunner-metrics/actions)
[](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(),]);
}
}
```
## License:
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained
by [Spiral Scout](https://spiralscout.com).