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
JSONExporterLogExporterMetricTypeMetricsExporterPrometheusExporter
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.
Represents a single metric with its metadata and values.
- MetricType:bases: enum.Enum
Types of metrics that can be collected.
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.