Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Roadrunner Metrics Laravel Package

spiral/roadrunner-metrics

RoadRunner metrics integration for PHP apps. Exposes and exports runtime and application metrics from the RoadRunner server, enabling observability with common monitoring backends. Lightweight package for collecting counters, gauges, and histograms in production.

View on GitHub
Deep Wiki
Context7

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(),]);
    }
}

License:

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity