spiral/roadrunner-metrics

RoadRunner: Prometheus metrics RPC

v2.0.1 2021-02-18 17:53 UTC

This package is auto-updated.

Last update: 2021-07-18 18:47:15 UTC


README

RoadRunner

68747470733a2f2f706f7365722e707567782e6f72672f73706972616c2f726f616472756e6e65722f76657273696f6e 68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f73706972616c2f726f616472756e6e65723f7374617475732e737667 68747470733a2f2f676f7265706f7274636172642e636f6d2f62616467652f6769746875622e636f6d2f73706972616c2f726f616472756e6e6572 68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73706972616c2f726f616472756e6e65722f6261646765732f7175616c6974792d73636f72652e706e67 68747470733a2f2f636f6465636f762e696f2f67682f73706972616c2f726f616472756e6e65722f6272616e63682f6d61737465722f67726170682f62616467652e737667 Total alerts 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973636f72642d636861742d6d6167656e74612e737667 68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f73706972616c2f726f616472756e6e65723f7374796c653d666c61742d737175617265

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a service with the ability to extend its functionality on a per-project basis.

RoadRunner includes PSR-7/PSR-17 compatible HTTP and HTTP/2 server and can be used to replace classic Nginx+FPM setup with much greater performance and flexibility.

Official Website | Documentation

Repository:

This repository contains the codebase used to publish Prometheus metrics from PHP application. Check spiral/roadrunner to get application server.

Installation:

To install RoadRunner extension:

$ composer require spiral/roadrunner-http spiral/roadrunner-metrics nyholm/psr7
$ vendor/bin/rr get-binary

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:8081"

Example:

To publish metrics from your application worker:

<?php

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

ini_set('display_errors', 'stderr');
include "vendor/autoload.php";

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

$metrics = new RoadRunner\Metrics\Metrics(
    Goridge\RPC\RPC::create(RoadRunner\Environment::fromGlobals()->getRPCAddress())
);

$metrics->declare(
    'test',
    RoadRunner\Metrics\Collector::counter()->withHelp('Test counter')
);

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

        $metrics->add('test', 1);

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

Testing:

This codebase is automatically tested via host repository - spiral/roadrunner.

License:

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