\Drupal\strata\Anomaly AnomalyDetector

Scores the newest reading of each measurement against the site's own earlier readings.

A threshold that is right for one site is wrong for another, so nothing here is compared against an absolute number. A site doing four operations an hour and a site doing four hundred thousand both have a normal, and the only useful question is whether today looks like their own yesterday. Every judgement is therefore relative to the series in MetricSampler's window.

Findings go through the same ledger as every tripwire, so an anomaly appears on the health dashboard beside a missing frame and inherits the repair ladder, the circuit breaker and the notification channel rather than getting a parallel set of its own. The rung stays at observe: an unusual number is a reason to look, never a reason to repair.

Two measurements are directional and the rest are not. A compression ratio and a deduplication ratio going UP is the pipeline working better, so only a fall is reported. An operation rate, a stored-byte total and a chain depth are reported in both directions - a site that suddenly stops capturing is as interesting as one that suddenly captures far more, and it is the failure mode a one-sided detector would miss entirely.

Summary

Methods
Properties
Constants
__construct
run
current
score
series
No public properties found
WARN_SIGMA
ERROR_SIGMA
FALL_ONLY
No protected methods found
No protected properties found
No protected constants found
report
sampler
ledger
logger
notifier
warnAt
No private constants found

Constant

WARN_SIGMA

WARN_SIGMA = 4.0

Deviations from the median before a departure is worth a warning.

ERROR_SIGMA

ERROR_SIGMA = 8.0

Deviations from the median before a departure is worth an error.

FALL_ONLY

FALL_ONLY = ['dedup_ratio', 'compression_ratio'] : array<int, string>

Measurements where only a fall is a symptom.

Properties

$sampler

$sampler : \Drupal\strata\Anomaly\MetricSampler

Type

MetricSampler

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

$notifier

$notifier : ?\Drupal\strata\Event\Notifier

Type

Notifier|null

$warnAt

$warnAt : float

Type

float

Methods

__construct()

__construct(\Drupal\strata\Anomaly\MetricSampler  $sampler, \Drupal\strata\Health\HealthLedgerInterface  $ledger, \Psr\Log\LoggerInterface  $logger, \Drupal\strata\Event\Notifier|null  $notifier = null, float  $warnAt = \self::WARN_SIGMA) : mixed

Constructs a detector.

Parameters

\Drupal\strata\Anomaly\MetricSampler $sampler

Takes the reading and holds the window.

\Drupal\strata\Health\HealthLedgerInterface $ledger

Where an anomaly is recorded.

\Psr\Log\LoggerInterface $logger

Records what was found.

\Drupal\strata\Event\Notifier|null $notifier

Announces each anomaly, or NULL to stay silent.

float $warnAt

Deviations before a warning, so a site can widen or tighten the band.

Returns

mixed —

run()

run(bool  $record = true) : list<\Drupal\strata\Anomaly\Anomaly>

Takes a reading and reports what departed from the window before it.

Parameters

bool $record

FALSE to score without writing findings, which is what the dashboard's preview does.

Returns

list<\Drupal\strata\Anomaly\Anomaly> —

What departed, worst first.

current()

current() : list<\Drupal\strata\Anomaly\Anomaly>

Scores the window as it stands, without taking a reading or writing anything.

What a dashboard calls. run() samples first, so rendering a page through it would append a reading on every page load and move the baseline every time somebody looked at it.

Returns

list<\Drupal\strata\Anomaly\Anomaly> —

What departed, worst first.

score()

score(string  $metric) : \Drupal\strata\Anomaly\Anomaly|null

Scores one measurement's newest reading.

Parameters

string $metric

A key of MetricSampler::METRICS.

Returns

\Drupal\strata\Anomaly\Anomaly|null —

The anomaly, or NULL when the series is too short, the reading is ordinary, or the measurement moved in the direction that is not a symptom.

series()

series() : array<string,\Drupal\strata\Anomaly\Series>

The window as a series per measurement, for a graph.

Returns

array

Metric key to series.

report()

report(\Drupal\strata\Anomaly\Anomaly  $anomaly) : void

Records one anomaly.

Parameters

\Drupal\strata\Anomaly\Anomaly $anomaly

What was found.

Returns

void —