blob: 749b451b72f44d084278637fc7a8e70fcdfa97a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# Application Metrics
RoadRunner server includes an embedded metrics server based on [Prometheus](https://prometheus.io/).
## Enable Metrics
To enable metrics add `metrics` section to your configuration:
```yaml
metrics:
address: localhost:2112
```
Once complete you can access Prometheus metrics using `http://localhost:2112/metrics` url.
Make sure to install metrics extension:
```bash
composer require spiral/roadrunner-metrics
```
## Application metrics
You can also publish application-specific metrics using an RPC connection to the server. First, you have to register a metric in your
configuration file:
```yaml
metrics:
address: localhost:2112
collect:
app_metric_counter:
type: counter
help: "Application counter."
```
To send metric from the application:
```php
$metrics = new RoadRunner\Metrics\Metrics(
Goridge\RPC\RPC::create(RoadRunner\Environment::fromGlobals()->getRPCAddress())
);
$metrics->add('app_metric_counter', 1);
```
> Supported types: gauge, counter, summary, histogram.
## Tagged metrics
You can use tagged (labels) metrics to group values:
```yaml
metrics:
address: localhost:2112
collect:
app_type_duration:
type: histogram
help: "Application counter."
labels: ["type"]
```
You should specify values for your labels while pushing the metric:
```php
$metrics = new RoadRunner\Metrics\Metrics(
Goridge\RPC\RPC::create(RoadRunner\Environment::fromGlobals()->getRPCAddress())
);
$metrics->add('app_type_duration', 0.5, ['some-type']);
```
## Declare metrics
You can declare metric from PHP application itself:
```php
$metrics->declare(
'test',
RoadRunner\Metrics\Collector::counter()->withHelp('Test counter')
);
```
|