https://github.com/phpstreamserver/metrics
[READ ONLY] Metrics Plugin for PHPStreamServer
https://github.com/phpstreamserver/metrics
phpstreamserver
Last synced: 12 months ago
JSON representation
[READ ONLY] Metrics Plugin for PHPStreamServer
- Host: GitHub
- URL: https://github.com/phpstreamserver/metrics
- Owner: phpstreamserver
- Created: 2024-11-22T17:41:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-27T18:07:08.000Z (over 1 year ago)
- Last Synced: 2024-12-27T19:19:04.891Z (over 1 year ago)
- Topics: phpstreamserver
- Language: PHP
- Homepage: https://phpstreamserver.dev
- Size: 19.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Metrics Plugin for PHPStreamServer



The Metrics Plugin for **PHPStreamServer** extends the core functionality by providing integration with Prometheus,
providing an endpoint for exposing application metrics.
It provides default metrics to monitor and allows users to define custom metrics as needed.
### Features:
- Provides counter, gauge, histogram and summary metrics.
- User defined metrics.
## Install
```bash
$ composer require phpstreamserver/core phpstreamserver/metrics
```
### Configure
Here is an example of a simple server configuration with metrics.
After startup, metrics are available at http://127.0.0.1:8081/metrics
```php
// server.php
use PHPStreamServer\Core\Server;
use PHPStreamServer\Core\Worker\WorkerProcess;
use PHPStreamServer\Plugin\Metrics\MetricsPlugin;
use PHPStreamServer\Plugin\Metrics\RegistryInterface;
use Revolt\EventLoop;
$server = new Server();
$server->addPlugin(
new MetricsPlugin(listen: '0.0.0.0:8081'),
);
$server->addWorker(
new WorkerProcess(
name: 'Metrics test',
count: 2,
onStart: function (WorkerProcess $worker): void {
$registry = $worker->container->getService(RegistryInterface::class);
$counter = $registry->registerCounter(namespace: 'test', name: 'ticks', help: 'Demonsration');
EventLoop::repeat(1, function () use ($counter) {
$counter->inc();
});
},
),
);
exit($server->run());
```
### Run
```bash
$ php server.php start
```