STATE_KEY
STATE_KEY = 'strata.metrics'
The state key the window lives under.
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.
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.
$frames : \Drupal\strata\Cas\FrameIndexInterface
$commits : \Drupal\strata\Tree\CommitIndex
__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.
| \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. |
operationRate(array|null $previous, int $now) : float
Operations an hour since the previous reading.
| array |
$previous | The previous reading, or NULL when this is the first. |
| int | $now | The current unix second. |
Operations an hour, or 0.0 when there is nothing to difference against.