sedai.measurement

class MetricUnit(enum.Enum):

The unit a MetricValue is expressed in. Only a subset of these units is valid for any one kind of measurement - see MetricValue.allowed_units.

CORES = <MetricUnit.CORES: 'CORES'>

CPU cores.

MILLICORES = <MetricUnit.MILLICORES: 'MILLICORES'>

Thousandths of a CPU core. This is the unit behind Kubernetes' 250m notation.

CENTICORES = <MetricUnit.CENTICORES: 'CENTICORES'>

Hundredths of a CPU core.

MICROCORES = <MetricUnit.MICROCORES: 'MICROCORES'>

Millionths of a CPU core.

NANOCORES = <MetricUnit.NANOCORES: 'NANOCORES'>

Billionths of a CPU core.

VCPU = <MetricUnit.VCPU: 'VCPU'>

A virtual CPU. Equivalent to a core for Kubernetes, and to 1024 CPU units for ECS.

CPU_UNITS = <MetricUnit.CPU_UNITS: 'CPU_UNITS'>

ECS CPU units. 1024 CPU units make up one vCPU.

BYTES = <MetricUnit.BYTES: 'BYTES'>

Bytes.

KILO_BYTES = <MetricUnit.KILO_BYTES: 'KILO_BYTES'>

Decimal kilobytes (1000 bytes).

MEGA_BYTES = <MetricUnit.MEGA_BYTES: 'MEGA_BYTES'>

Decimal megabytes (1000^2 bytes).

GIGA_BYTES = <MetricUnit.GIGA_BYTES: 'GIGA_BYTES'>

Decimal gigabytes (1000^3 bytes).

TERA_BYTES = <MetricUnit.TERA_BYTES: 'TERA_BYTES'>

Decimal terabytes (1000^4 bytes).

PETA_BYTES = <MetricUnit.PETA_BYTES: 'PETA_BYTES'>

Decimal petabytes (1000^5 bytes).

EXA_BYTES = <MetricUnit.EXA_BYTES: 'EXA_BYTES'>

Decimal exabytes (1000^6 bytes).

KIBI_BYTES = <MetricUnit.KIBI_BYTES: 'KIBI_BYTES'>

Binary kibibytes (1024 bytes). This is the unit behind Kubernetes' 512Ki notation.

MEBI_BYTES = <MetricUnit.MEBI_BYTES: 'MEBI_BYTES'>

Binary mebibytes (1024^2 bytes). This is the unit ECS task definitions use for memory.

GIBI_BYTES = <MetricUnit.GIBI_BYTES: 'GIBI_BYTES'>

Binary gibibytes (1024^3 bytes).

TEBI_BYTES = <MetricUnit.TEBI_BYTES: 'TEBI_BYTES'>

Binary tebibytes (1024^4 bytes).

PEBI_BYTES = <MetricUnit.PEBI_BYTES: 'PEBI_BYTES'>

Binary pebibytes (1024^5 bytes).

EXBI_BYTES = <MetricUnit.EXBI_BYTES: 'EXBI_BYTES'>

Binary exbibytes (1024^6 bytes).

class MetricValue:

A measurement expressed as a number together with the unit that number is in. This is the base class for K8sCpuValue, ECSCpuValue and MemoryValue; use one of those rather than this class directly.

MetricValue( value: float | None = None, metricUnit: MetricUnit | str | None = None)
Parameters
  • value: The magnitude of the measurement. None leaves the measurement unset.
  • metricUnit: The unit value is in. Defaults to the base unit for this kind of measurement - cores for Kubernetes cpu, CPU units for ECS cpu, bytes for memory.
Raises
  • ValueError: If metricUnit is not a valid unit for this kind of measurement.
value: float | None

The magnitude of the measurement, in metricUnit. None means the measurement is not set - for a guardrail that means the guardrail is unbounded and Sedai applies its own default.

metricUnit: MetricUnit

The unit value is expressed in. The API rejects a measurement with no unit, so this is always one of allowed_units.

@classmethod
def allowed_units(cls) -> list:

The units this kind of measurement can be expressed in.

def value_in(self, metricUnit: MetricUnit | str) -> float | None:

This measurement converted to metricUnit.

Parameters
  • metricUnit: The unit to convert to.
Returns

The converted magnitude, or None if the measurement is not set.

Raises
  • ValueError: If metricUnit is not a valid unit for this kind of measurement.
class K8sCpuValue(MetricValue):

A Kubernetes cpu measurement, such as a per-container cpu guardrail. A bare number with no unit is taken to be in MetricUnit.CORES.

def to_cores(self) -> float | None:

This measurement in cpu cores, or None if it is not set.

def to_millicores(self) -> float | None:

This measurement in millicores, or None if it is not set.

class ECSCpuValue(MetricValue):

An ECS cpu measurement, such as the minimum cpu guardrail for an ECS service. A bare number with no unit is taken to be in MetricUnit.CPU_UNITS.

def to_cpu_units(self) -> float | None:

This measurement in ECS CPU units, or None if it is not set.

def to_vcpus(self) -> float | None:

This measurement in vCPUs, or None if it is not set.

class MemoryValue(MetricValue):

A memory measurement, such as a per-container memory guardrail. A bare number with no unit is taken to be in MetricUnit.BYTES.

def to_bytes(self) -> float | None:

This measurement in bytes, or None if it is not set.

def to_mib(self) -> float | None:

This measurement in mebibytes (1024^2 bytes), or None if it is not set.

def to_gib(self) -> float | None:

This measurement in gibibytes (1024^3 bytes), or None if it is not set.

def to_gb(self) -> float | None:

This measurement in decimal gigabytes (1000^3 bytes), or None if it is not set.