Reporters¤
Output metrics to console, files, or external services.
See Also¤
- Monitoring Overview - All monitoring tools
- Metrics - Metric tracking
- Benchmarking - Performance measurement
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.
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
|
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 |
FileReporter ¤
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. |
{}
|
update ¤
update(metrics: list[MetricRecord]) -> None
Handle updated metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
list[MetricRecord]
|
List of new metric records. |
required |
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. |