spiral/roadrunner-metrics
最新稳定版本:3.3.0
Composer 安装命令:
composer require spiral/roadrunner-metrics
包简介
RoadRunner: Prometheus metrics RPC
README 文档
README
RoadRunner Metrics Plugin
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.
统计信息
- 总下载量: 1.88M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04