Flow PHP

Meter

FinalYes

Meter for creating metric instruments.

A Meter creates instruments for a specific instrumentation scope. Instruments are cached and returned by name - calling createCounter() twice with the same name returns the same Counter instance.

Example usage:

$meter = $meterProvider->meter('my-service', '1.0.0');

$counter = $meter->createCounter('requests.total', 'requests', 'Total requests');
$counter->add(1, ['http.method' => 'GET']);

$histogram = $meter->createHistogram('request.duration', 'ms', 'Request duration');
$histogram->record(42.5, ['http.status' => 200]);
Tags
see
https://opentelemetry.io/docs/specs/otel/metrics/api/#meter

Methods

__construct()  : mixed
collect()  : array<string|int, Metric>
Collect all aggregated metrics from all instruments.
createCounter()  : Counter
Create or get a Counter instrument.
createGauge()  : Gauge
Create or get a Gauge instrument.
createHistogram()  : Histogram
Create or get a Histogram instrument.
createUpDownCounter()  : UpDownCounter
Create or get an UpDownCounter instrument.
instrumentationScope()  : InstrumentationScope
Get the instrumentation scope.
name()  : string
Get the meter name.
processor()  : MetricProcessor
Get the processor used by this meter.
version()  : string
Get the meter version.
withInstrumentationScope()  : self
Change the instrumentation scope for this meter.

Methods

__construct()

public __construct(resource $resource, InstrumentationScope $scope, MetricProcessor $processor, ClockInterface $clock[, AggregationTemporality $temporality = AggregationTemporality::CUMULATIVE ][, ExemplarFilter $exemplarFilter = new TraceBasedExemplarFilter() ]) : mixed
Parameters
$resource : resource

The resource context for all metrics from this meter

$scope : InstrumentationScope

The instrumentation scope

$processor : MetricProcessor

The metric processor

$clock : ClockInterface

Clock for timestamps

$temporality : AggregationTemporality = AggregationTemporality::CUMULATIVE

Aggregation temporality for metrics

$exemplarFilter : ExemplarFilter = new TraceBasedExemplarFilter()

Filter for exemplar sampling

collect()

Collect all aggregated metrics from all instruments.

public collect() : array<string|int, Metric>
Return values
array<string|int, Metric>

createCounter()

Create or get a Counter instrument.

public createCounter(string $name[, null|string $unit = null ][, null|string $description = null ]) : Counter

Counters are monotonically increasing - they only go up. Use for counting occurrences: requests, errors, items processed.

Parameters
$name : string

Metric name (e.g., 'http.requests', 'flow.rows.processed')

$unit : null|string = null

Unit of measurement (e.g., 'rows', 'bytes')

$description : null|string = null

Human-readable description

Return values
Counter

createGauge()

Create or get a Gauge instrument.

public createGauge(string $name[, null|string $unit = null ][, null|string $description = null ]) : Gauge

Gauges record the current value at a point in time. Use for: temperature, memory usage, CPU utilization.

Parameters
$name : string

Metric name (e.g., 'system.memory.usage', 'cpu.utilization')

$unit : null|string = null

Unit of measurement (e.g., 'bytes', '%')

$description : null|string = null

Human-readable description

Return values
Gauge

createHistogram()

Create or get a Histogram instrument.

public createHistogram(string $name[, null|string $unit = null ][, null|string $description = null ][, null|array<string|int, float> $boundaries = null ]) : Histogram

Histograms track the statistical distribution of values. Use for: request latency, response sizes, batch sizes.

Parameters
$name : string

Metric name (e.g., 'http.request.duration', 'flow.batch.size')

$unit : null|string = null

Unit of measurement (e.g., 'ms', 'bytes', 'rows')

$description : null|string = null

Human-readable description

$boundaries : null|array<string|int, float> = null

Explicit bucket boundaries (null uses default)

Return values
Histogram

createUpDownCounter()

Create or get an UpDownCounter instrument.

public createUpDownCounter(string $name[, null|string $unit = null ][, null|string $description = null ]) : UpDownCounter

UpDownCounters track values that can go both up and down. Use for: active connections, queue size, items in cache.

Parameters
$name : string

Metric name (e.g., 'queue.size', 'active.connections')

$unit : null|string = null

Unit of measurement

$description : null|string = null

Human-readable description

Return values
UpDownCounter

name()

Get the meter name.

public name() : string
Return values
string

version()

Get the meter version.

public version() : string
Return values
string

withInstrumentationScope()

Change the instrumentation scope for this meter.

public withInstrumentationScope(InstrumentationScope $scope) : self

This mutates the meter instance and returns it for method chaining.

Parameters
$scope : InstrumentationScope
Return values
self

        
On this page

Search results