\Drupal\strata\Budget BudgetAssessment

One budget reading: what a month at the observed rate comes to, and what Strata does about it.

Readonly, because a reading describes a moment. A later window produces a new assessment rather than editing this one, so a figure surfaced in a report cannot drift from the rung that was derived from it.

Summary

Methods
Properties
Constants
__construct
withRung
isOverBudget
allowsRealm
allowsCapture
summary
jsonSerialize
rung
usedFraction
projectedBytes
projectedDollars
bytesCeiling
dollarsCeiling
reason
AXIS_BYTES
AXIS_DOLLARS
No protected methods found
No protected properties found
No protected constants found
readableBytes
No private properties found
No private constants found

Constant

AXIS_BYTES

AXIS_BYTES = 'bytes'

The bytes-per-month axis.

AXIS_DOLLARS

AXIS_DOLLARS = 'dollars'

The dollars-per-month axis.

Properties

$rung

$rung : string

Type

string

$usedFraction

$usedFraction : float

Type

float

$projectedBytes

$projectedBytes : int

Type

int

$projectedDollars

$projectedDollars : float

Type

float

$bytesCeiling

$bytesCeiling : int

Type

int

$dollarsCeiling

$dollarsCeiling : float

Type

float

$reason

$reason : ?string

Type

string|null

Methods

__construct()

__construct(string  $rung, float  $usedFraction, int  $projectedBytes, float  $projectedDollars, int  $bytesCeiling = 0, float  $dollarsCeiling = 0.0, string|null  $reason = null) : mixed

Constructs a reading.

Parameters

string $rung

A rung name from EscalationLadder::RUNGS.

float $usedFraction

Projected usage divided by the ceiling that binds. 0.0 when no ceiling is set, or when the window was too short to project from.

int $projectedBytes

Bytes the store would be sent over a month at the observed rate.

float $projectedDollars

What that month would cost, storage and requests together.

int $bytesCeiling

The bytes-per-month ceiling in force; 0 means no ceiling on that axis.

float $dollarsCeiling

The dollars-per-month ceiling in force; 0.0 means no ceiling on that axis.

string|null $reason

AXIS_BYTES or AXIS_DOLLARS, naming the axis that produced $usedFraction. NULL when neither ceiling is set, or when nothing could be projected.

Returns

mixed —

withRung()

withRung(string  $rung) : self

The same reading held to a different rung.

The measurement is unchanged; only what the site has agreed to do about it moves. Used to hold a measured rung down to the one budget.action allows.

Parameters

string $rung

The rung to report.

Returns

self —

A new reading, since this one is readonly.

isOverBudget()

isOverBudget() : bool

Whether the projection has passed the ceiling.

The warn rung is under this line: it reports a month heading for the ceiling, not one that has crossed it.

Returns

bool —

TRUE at or above the full ceiling.

allowsRealm()

allowsRealm(string  $realm) : bool

Whether one realm is still being captured at this rung.

Parameters

string $realm

A realm value, as Realm stores it.

Returns

bool —

TRUE when capture should continue for that realm.

allowsCapture()

allowsCapture() : bool

Whether anything at all is still being captured.

Returns

bool —

FALSE only at the stop rung, where the journal refuses appends.

summary()

summary() : string

The reading as one line for a log entry or a status report.

Returns

string —

A sentence naming the rung, the projection and the ceiling it was measured against.

jsonSerialize()

jsonSerialize() : array<string,mixed>

{@inheritdoc}

Returns

array

The reading as a plain array for a render array or a JSON response.

readableBytes()

readableBytes(int  $bytes) : string

Formats a byte count for an operator-facing line.

Steps by 1024, matching the gigabyte storage is priced by in BudgetGuard. Never parse the result; it is for a table cell or a log line.

Parameters

int $bytes

The count.

Returns

string —

A string such as "1.5 GB", or "0 B" for nothing.