apifrom.monitoring.exporters

Exporters for metrics data in APIFromAnything.

This module provides exporters for converting metrics data to various formats and integrating with popular monitoring systems like Prometheus, Grafana, etc.

Overview

Classes

Classes

JSONExporter(collector = None):bases: MetricsExporter

Exports metrics data in JSON format.

Initialize the exporter with a metrics collector.

apifrom.monitoring.exporters.export(pretty=False)

Export metrics as JSON.

param pretty:

Whether to format the JSON with indentation for readability.

returns:

JSON string representation of the metrics.

apifrom.monitoring.exporters.export_to_file(file_path, pretty=True)

Export metrics to a JSON file.

param file_path:

Path to the output file.

param pretty:

Whether to format the JSON with indentation for readability.

LogExporter(collector = None, logger = None, level = logging.INFO):bases: MetricsExporter

Exports metrics to Python’s logging system.

Initialize the log exporter.

param collector:

Metrics collector to export from.

param logger:

Logger to use for logging metrics.

param level:

Logging level to use.

apifrom.monitoring.exporters.export(include_details=False, **kwargs)

Export metrics to logs.

param include_details:

Whether to include detailed metrics information.

apifrom.monitoring.exporters.export_periodic(interval_seconds=60, include_details=False)

Start a background thread to periodically export metrics to logs.

param interval_seconds:

Interval between exports in seconds.

param include_details:

Whether to include detailed metrics information.

class apifrom.monitoring.exporters.Metric[source]

Represents a single metric with its metadata and values.

MetricType:bases: enum.Enum

Types of metrics that can be collected.

class apifrom.monitoring.exporters.MetricsCollector[source]

Collects and manages metrics for the API.

This class provides a centralized way to create, update, and retrieve metrics for monitoring API performance and usage.

Initialize the metrics collector.

MetricsExporter(collector = None):bases: abc.ABC

Base class for all metrics exporters.

Initialize the exporter with a metrics collector.

apifrom.monitoring.exporters.export(**kwargs)
:abstractmethod:

Export metrics in the specific format.

PrometheusExporter(collector = None):bases: MetricsExporter

Exports metrics in Prometheus text format.

Initialize the exporter with a metrics collector.

apifrom.monitoring.exporters._format_labels(labels)

Format labels for Prometheus exposition format.

apifrom.monitoring.exporters.export(**kwargs)

Export metrics in Prometheus text format.

returns:

String in Prometheus exposition format.

apifrom.monitoring.exporters.export_to_file(file_path)

Export metrics to a file in Prometheus text format.

param file_path:

Path to the output file.

apifrom.monitoring.exporters.serve_metrics(host='localhost', port=8000, endpoint='/metrics')

Start a simple HTTP server to expose metrics for Prometheus scraping.

param host:

Host to bind the server to.

param port:

Port to listen on.

param endpoint:

URL endpoint for metrics.