-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcounters.php
More file actions
47 lines (39 loc) · 1.33 KB
/
counters.php
File metadata and controls
47 lines (39 loc) · 1.33 KB
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
<?php declare(strict_types=1);
namespace YourVendor\YourProject;
use OpenMetricsPhp\Exposition\Text\Collections\CounterCollection;
use OpenMetricsPhp\Exposition\Text\Collections\LabelCollection;
use OpenMetricsPhp\Exposition\Text\Metrics\Counter;
use OpenMetricsPhp\Exposition\Text\Types\Label;
use OpenMetricsPhp\Exposition\Text\Types\MetricName;
require __DIR__ . '/../vendor/autoload.php';
$counters = CounterCollection::fromCounters(
MetricName::fromString( 'your_metric_name' ),
Counter::fromValue( 1 ),
Counter::fromValueAndTimestamp( 2, time() ),
Counter::fromValue( 3 )->withLabels(
Label::fromNameAndValue( 'label1', 'label_value' )
),
Counter::fromValueAndTimestamp( 4, time() )->withLabels(
Label::fromNameAndValue( 'label2', 'label_value' )
)
)->withHelp( 'A helpful description of your measurement.' );
# Add counters after creating the collection
$counters->add(
Counter::fromValue( 5 ),
Counter::fromValueAndTimestamp( 6, time() ),
Counter::fromValue( 7 )->withLabels(
# Create labels from label string
Label::fromLabelString( 'label3="label_value"' )
)
);
# Prepare labels upfront
$labels = LabelCollection::fromAssocArray(
[
'label4' => 'label_value',
'label5' => 'label_value',
]
);
$counters->add(
Counter::fromValueAndTimestamp( 8, time() )->withLabelCollection( $labels )
);
echo $counters->getMetricsString();