Skip to content

metrics

frequenz.client.microgrid.metrics ¤

Definition to work with metric sample values.

Classes¤

frequenz.client.microgrid.metrics.AggregatedMetricValue dataclass ¤

Encapsulates derived statistical summaries of a single metric.

The message allows for the reporting of statistical summaries — minimum, maximum, and average values - as well as the complete list of individual samples if available.

This message represents derived metrics and contains fields for statistical summaries—minimum, maximum, and average values. Individual measurements are are optional, accommodating scenarios where only subsets of this information are available.

Source code in frequenz/client/microgrid/metrics.py
@dataclass(frozen=True, kw_only=True)
class AggregatedMetricValue:
    """Encapsulates derived statistical summaries of a single metric.

    The message allows for the reporting of statistical summaries — minimum,
    maximum, and average values - as well as the complete list of individual
    samples if available.

    This message represents derived metrics and contains fields for statistical
    summaries—minimum, maximum, and average values. Individual measurements are
    are optional, accommodating scenarios where only subsets of this information
    are available.
    """

    avg: float
    """The derived average value of the metric."""

    min: float | None
    """The minimum measured value of the metric."""

    max: float | None
    """The maximum measured value of the metric."""

    raw_values: Sequence[float]
    """All the raw individual values (it might be empty if not provided by the component)."""

    def __str__(self) -> str:
        """Return the short string representation of this instance."""
        extra: list[str] = []
        if self.min is not None:
            extra.append(f"min:{self.min}")
        if self.max is not None:
            extra.append(f"max:{self.max}")
        if len(self.raw_values) > 0:
            extra.append(f"num_raw:{len(self.raw_values)}")
        extra_str = f"<{' '.join(extra)}>" if extra else ""
        return f"avg:{self.avg}{extra_str}"
Attributes¤
avg instance-attribute ¤
avg: float

The derived average value of the metric.

max instance-attribute ¤
max: float | None

The maximum measured value of the metric.

min instance-attribute ¤
min: float | None

The minimum measured value of the metric.

raw_values instance-attribute ¤
raw_values: Sequence[float]

All the raw individual values (it might be empty if not provided by the component).

Functions¤
__str__ ¤
__str__() -> str

Return the short string representation of this instance.

Source code in frequenz/client/microgrid/metrics.py
def __str__(self) -> str:
    """Return the short string representation of this instance."""
    extra: list[str] = []
    if self.min is not None:
        extra.append(f"min:{self.min}")
    if self.max is not None:
        extra.append(f"max:{self.max}")
    if len(self.raw_values) > 0:
        extra.append(f"num_raw:{len(self.raw_values)}")
    extra_str = f"<{' '.join(extra)}>" if extra else ""
    return f"avg:{self.avg}{extra_str}"

frequenz.client.microgrid.metrics.AggregationMethod ¤

Bases: Enum

The type of the aggregated value.

Source code in frequenz/client/microgrid/metrics.py
@enum.unique
class AggregationMethod(enum.Enum):
    """The type of the aggregated value."""

    AVG = "avg"
    """The average value of the metric."""

    MIN = "min"
    """The minimum value of the metric."""

    MAX = "max"
    """The maximum value of the metric."""
Attributes¤
AVG class-attribute instance-attribute ¤
AVG = 'avg'

The average value of the metric.

MAX class-attribute instance-attribute ¤
MAX = 'max'

The maximum value of the metric.

MIN class-attribute instance-attribute ¤
MIN = 'min'

The minimum value of the metric.