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.
complete()  : void
Complete an instrument and pass its metrics to the processor.
createCounter()  : Counter
Create or get a Counter instrument.
createGauge()  : Gauge
Create or get a Gauge instrument.
createHistogram()  : Histogram
Create or get a Histogram instrument.
createThroughput()  : Throughput
Create or get a Throughput instrument.
createUpDownCounter()  : UpDownCounter
Create or get an UpDownCounter instrument.
flush()  : bool
Collect all metrics and flush to processor.
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>

complete()

Complete an instrument and pass its metrics to the processor.

public complete(Instrument $instrument) : void

Collects all aggregated metrics from the instrument, passes them to the processor, and removes the instrument from this meter. Use this for bounded operations where the instrument lifecycle is tied to a specific task (e.g., DataFrame processing).

Parameters
$instrument : Instrument

The instrument to complete

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

createThroughput()

Create or get a Throughput instrument.

public createThroughput(string $name[, null|string $unit = null ][, null|string $description = null ][, null|int $ratePrecision = 2 ][, TimeUnit $timeUnit = TimeUnit::SECONDS ]) : Throughput

Throughput tracks accumulated count and calculates rate (count/time unit). The timer starts from the first add() call for each attribute combination. Use for: rows processed per second, bytes transferred per second.

Parameters
$name : string

Metric name (e.g., 'dataframe_throughput', 'transfer_rate')

$unit : null|string = null

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

$description : null|string = null

Human-readable description

$ratePrecision : null|int = 2

Number of decimal places for rate calculation (default: 2, null for no rounding)

$timeUnit : TimeUnit = TimeUnit::SECONDS

Time unit for rate calculation (default: SECONDS)

Return values
Throughput

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

flush()

Collect all metrics and flush to processor.

public flush() : bool
Return values
bool

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