\Drupal\strata\Anomaly MetricSampler

Records what the store looks like now, and keeps a bounded window of earlier readings.

A detector needs a series and the store only offers a snapshot: the frame index knows how many frames exist right now, not how many existed an hour ago. So the readings are taken on cron and kept in state, which is the cheapest durable place for a fixed-size ring of numbers and does not need a table of its own.

The window is capped by count, not by age. A site whose cron stops running for a week should come back and be judged against its last hundred readings rather than against nothing, and a site running cron every minute should not accumulate a million rows.

The op rate is a difference between readings rather than a running total, so it is the one value that means nothing on the first sample. It is recorded as zero there and the detector skips it until the series is established.

Summary

Methods
Properties
Constants
__construct
sample
window
series
clear
No public properties found
STATE_KEY
WINDOW
METRICS
No protected methods found
No protected properties found
No protected constants found
operationRate
capturedRawBytes
deepestChain
state
frames
commits
database
time
No private constants found

Constant

STATE_KEY

STATE_KEY = 'strata.metrics'

The state key the window lives under.

WINDOW

WINDOW = 128

Readings kept.

METRICS

METRICS = ['op_rate' => ['label' => 'Operation rate', 'unit' => 'per hour'], 'stored_bytes' => ['label' => 'Stored bytes', 'unit' => 'bytes'], 'dedup_ratio' => ['label' => 'Deduplication ratio', 'unit' => 'x'], 'compression_ratio' => ['label' => 'Compression ratio', 'unit' => 'x'], 'chain_depth' => ['label' => 'Deepest delta chain', 'unit' => 'links']] : array<string, array{label: string, unit: string}>

Every metric this samples, keyed to its label and unit.

Properties

$state

$state : \Drupal\Core\State\StateInterface

Type

StateInterface

$commits

$commits : \Drupal\strata\Tree\CommitIndex

Type

CommitIndex

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

$time

$time : \Drupal\Component\Datetime\TimeInterface

Type

TimeInterface

Methods

__construct()

__construct(\Drupal\Core\State\StateInterface  $state, \Drupal\strata\Cas\FrameIndexInterface  $frames, \Drupal\strata\Tree\CommitIndex  $commits, \Drupal\Core\Database\Connection  $database, \Drupal\Component\Datetime\TimeInterface  $time) : mixed

Constructs a sampler.

Parameters

\Drupal\Core\State\StateInterface $state

Where the window is kept.

\Drupal\strata\Cas\FrameIndexInterface $frames

Supplies the store totals.

\Drupal\strata\Tree\CommitIndex $commits

Supplies the operation counts.

\Drupal\Core\Database\Connection $database

Reads the captured raw byte total the dedup ratio is measured against.

\Drupal\Component\Datetime\TimeInterface $time

Stamps each reading.

Returns

mixed —

sample()

sample() : array<string,float>

Takes a reading and appends it to the window.

Returns

array

The reading, keyed as METRICS is, with an at entry holding the unix second.

window()

window() : list<array<string,float>>

Every reading kept, oldest first.

Returns

list> —

The window.

series()

series(string  $metric) : \Drupal\strata\Anomaly\Series

One metric's readings as a series, oldest first.

Parameters

string $metric

A key of METRICS.

Returns

\Drupal\strata\Anomaly\Series —

The series.

clear()

clear() : void

Forgets every reading.

Returns

void —

operationRate()

operationRate(array|null  $previous, int  $now) : float

Operations an hour since the previous reading.

Parameters

array|null $previous

The previous reading, or NULL when this is the first.

int $now

The current unix second.

Returns

float —

Operations an hour, or 0.0 when there is nothing to difference against.

capturedRawBytes()

capturedRawBytes() : float

Raw bytes the commits say were captured.

Compared against the frame index's own raw total to give a deduplication ratio: the same value written twice is captured twice and framed once.

Returns

float —

Bytes.

deepestChain()

deepestChain() : int

The deepest delta chain in the store.

Returns

int —

Links, or 0 when nothing is delta coded.