spiral/roadrunner-metrics

RoadRunner: Prometheus metrics RPC

Maintainers

👁 wolfy-j

Package info

github.com/roadrunner-php/metrics

Homepage

Issues

Chat

Forum

Documentation

pkg:composer/spiral/roadrunner-metrics

Fund package maintenance!

roadrunner-server

Statistics

Installs: 2 758 808

Dependents: 3

Suggesters: 0

Stars: 8

3.3.0 2025-05-13 11:43 UTC

Requires

Requires (Dev)

Suggests

Provides

None

Conflicts

None

Replaces

None

MIT 701c5c0beda29d42c7fdd5afda5d89aac6358938

  • Anton Titov (wolfy-j) <wolfy-j.woop@spiralscout.com>
  • Pavel Buchnev (butschster) <pavel.buchnev.woop@spiralscout.com>
  • Aleksei Gagarin (roxblnfk) <alexey.gagarin.woop@spiralscout.com>
  • Maksim Smakouz (msmakouz) <maksim.smakouz.woop@spiralscout.com>
  • Kirill Nesmeyanov (SerafimArts) <kirill.nesmeyanov.woop@spiralscout.com>
  • RoadRunner Community

This package is auto-updated.

Last update: 2026-05-29 01:00:48 UTC


README

👁 Image

RoadRunner Metrics Plugin

👁 PHP Version Require
👁 Latest Stable Version
👁 phpunit
👁 psalm
👁 Total Downloads

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

Installation:

To install RoadRunner extension:

composer require spiral/roadrunner-metrics

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

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

Configuration

Enable metrics service in your .rr.yaml file:

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

declare(strict_types=1);

use Nyholm\Psr7\Factory;use Spiral\Goridge;use Spiral\RoadRunner;

include "vendor/autoload.php";

$worker = new RoadRunner\Http\PSR7Worker(
 RoadRunner\Worker::create(),
 new Factory\Psr17Factory(),
 new Factory\Psr17Factory(),
 new Factory\Psr17Factory()
);

# Create metrics client
$metrics = new RoadRunner\Metrics\Metrics(
 Goridge\RPC\RPC::create(RoadRunner\Environment::fromGlobals()->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 for more information. Maintained by Spiral Scout.