Skip to content

Reporters¤

Output metrics to console, files, or external services.

See Also¤


datarax.monitoring.reporters ¤

Reporters for Datarax monitoring.

This module provides implementations of MetricsObservers that report metrics to various outputs like console, files, or external systems.

logger module-attribute ¤

logger = getLogger(__name__)

ConsoleReporter ¤

ConsoleReporter(report_interval: float = 5.0, show_components: bool = True, filter_components: set[str] | None = None, filter_metrics: set[str] | None = None, output: TextIO = stdout)

Bases: MetricsObserver

Reports metrics to the console.

This reporter displays metrics in a formatted way to the console, with optional filtering and aggregation.

Parameters:

Name Type Description Default
report_interval float

Minimum time in seconds between reports.

5.0
show_components bool

Whether to show component names in reports.

True
filter_components set[str] | None

Set of component names to include, or None for all.

None
filter_metrics set[str] | None

Set of metric names to include, or None for all.

None
output TextIO

Text stream to write reports to.

stdout

report_interval instance-attribute ¤

report_interval = report_interval

show_components instance-attribute ¤

show_components = show_components

filter_components instance-attribute ¤

filter_components = filter_components

filter_metrics instance-attribute ¤

filter_metrics = filter_metrics

output instance-attribute ¤

output = output

last_report_time instance-attribute ¤

last_report_time = 0.0

aggregated instance-attribute ¤

aggregated = AggregatedMetrics()

is_record_reportable ¤

is_record_reportable(metric: MetricRecord) -> bool

Check if a metric should be included in reports.

Parameters:

Name Type Description Default
metric MetricRecord

Metric record to check.

required

Returns:

Type Description
bool

True if the metric should be included, False otherwise.

update ¤

update(metrics: list[MetricRecord]) -> None

Handle updated metrics.

Parameters:

Name Type Description Default
metrics list[MetricRecord]

List of new metric records.

required

clear ¤

clear() -> None

Clear all aggregated metrics.

reset ¤

reset() -> None

Reset observer-local state before a new monitoring run.

FileReporter ¤

FileReporter(filename: str, mode: str = 'a', report_interval: float = 60.0, **kwargs: Any)

Bases: ConsoleReporter

Reports metrics to a file.

This extends ConsoleReporter to write metrics to a file instead of stdout. By default, metrics are written to the temp/monitoring directory.

Parameters:

Name Type Description Default
filename str

Path to the file to write reports to. If not an absolute path, it will be placed in temp/monitoring/ directory by default.

required
mode str

File open mode, typically "a" for append or "w" for write.

'a'
report_interval float

Minimum time in seconds between reports.

60.0
**kwargs Any

Additional arguments to pass to ConsoleReporter.

{}

file instance-attribute ¤

file = enter_context(open_file(mode))

report_interval instance-attribute ¤

report_interval = report_interval

show_components instance-attribute ¤

show_components = show_components

filter_components instance-attribute ¤

filter_components = filter_components

filter_metrics instance-attribute ¤

filter_metrics = filter_metrics

output instance-attribute ¤

output = output

last_report_time instance-attribute ¤

last_report_time = 0.0

aggregated instance-attribute ¤

aggregated = AggregatedMetrics()

close ¤

close() -> None

Close the file handle. Idempotent.

update ¤

update(metrics: list[MetricRecord]) -> None

Handle updated metrics.

Parameters:

Name Type Description Default
metrics list[MetricRecord]

List of new metric records.

required

reset ¤

reset() -> None

Reset observer-local state before a new monitoring run.

is_record_reportable ¤

is_record_reportable(metric: MetricRecord) -> bool

Check if a metric should be included in reports.

Parameters:

Name Type Description Default
metric MetricRecord

Metric record to check.

required

Returns:

Type Description
bool

True if the metric should be included, False otherwise.

clear ¤

clear() -> None

Clear all aggregated metrics.