\Drupal\strata\Telemetry MetricSet

Named numbers with their units, ready to be exported.

OTLP distinguishes a gauge from a counter and a collector treats them differently - a counter is expected to only ever rise, and one that falls is read as a process restart rather than as a real decrease. So the kind is recorded here rather than guessed at export time: stored bytes is a gauge, requests performed is a counter, and getting that backwards produces a graph that is wrong in a way nobody notices.

Summary

Methods
Properties
Constants
gauge
counter
all
get
count
isEmpty
jsonSerialize
No public properties found
GAUGE
COUNTER
No protected methods found
No protected properties found
No protected constants found
set
key
metrics
No private constants found

Constant

GAUGE

GAUGE = 'gauge'

A value that can move in either direction.

COUNTER

COUNTER = 'counter'

A value that only rises for the life of the process.

Properties

$metrics

$metrics : array}>

The metrics, keyed by name and dimensions.

Type

array<string, array{name: string, value: float, kind: string, unit: string, attributes: array}> —

Methods

gauge()

gauge(string  $name, float  $value, string  $unit = '', array  $attributes = []) : self

Records a gauge.

Parameters

string $name

The metric name, such as "strata.stored_bytes".

float $value

The reading.

string $unit

The UCUM unit, such as "By" for bytes or "s" for seconds.

array $attributes

Dimensions, such as the realm or the provider.

Returns

self —

This set, for chaining.

counter()

counter(string  $name, float  $value, string  $unit = '', array  $attributes = []) : self

Records a counter.

Parameters

string $name

The metric name.

float $value

The total so far.

string $unit

The UCUM unit.

array $attributes

Dimensions.

Returns

self —

This set, for chaining.

all()

all() : array<string,array{name: string, value: float, kind: string, unit: string, attributes: array<string,string>}>

Every reading recorded.

Returns

array}> —

A key of the name and its dimensions, each holding the reading and the plain metric name.

get()

get(string  $name, array  $attributes = []) : float|null

One reading's value.

Parameters

string $name

The metric name.

array $attributes

The dimensions that reading was recorded with.

Returns

float|null —

The value, or NULL when it was not recorded.

count()

count() : int

How many metrics are recorded.

Returns

int —

The count.

isEmpty()

isEmpty() : bool

Whether nothing has been recorded.

Returns

bool —

TRUE when the set is empty.

jsonSerialize()

jsonSerialize() : array

{@inheritdoc}

Returns

array —

set()

set(string  $name, float  $value, string  $kind, string  $unit, array  $attributes) : self

Records one metric.

The key is the name AND its attributes. One name carries several series when it is dimensioned - open findings per severity, request counts per class - and keying on the name alone would have each dimension overwrite the last, leaving one arbitrary series exported and the rest silently gone. The stored name stays the plain metric name, so the wire shape is unaffected.

The same name with the same attributes recorded twice keeps the later value, because the second reading is the more recent one and a set is a snapshot rather than a log.

Parameters

string $name

The metric name.

float $value

The reading.

string $kind

Either GAUGE or COUNTER.

string $unit

The UCUM unit.

array $attributes

Dimensions.

Returns

self —

This set, for chaining.

key()

key(string  $name, array  $attributes) : string

The key one dimensioned reading is stored under.

Attributes are sorted so the same dimensions in a different order resolve to one series rather than two.

Parameters

string $name

The metric name.

array $attributes

Dimensions.

Returns

string —

The key.