Class: Tasker::Telemetry::PrometheusExporter
- Inherits:
-
Object
- Object
- Tasker::Telemetry::PrometheusExporter
- Defined in:
- lib/tasker/telemetry/prometheus_exporter.rb
Overview
Prometheus exporter for converting native metrics to Prometheus format
This exporter transforms metrics from the MetricsBackend singleton into standard Prometheus text format for consumption by monitoring systems.
Instance Method Summary collapse
-
#export ⇒ String
Export all metrics in Prometheus text format.
-
#initialize(backend = nil) ⇒ PrometheusExporter
constructor
Initialize exporter with optional metrics backend.
-
#safe_export ⇒ Hash
Export metrics with error handling.
Constructor Details
#initialize(backend = nil) ⇒ PrometheusExporter
Initialize exporter with optional metrics backend
21 22 23 |
# File 'lib/tasker/telemetry/prometheus_exporter.rb', line 21 def initialize(backend = nil) @backend = backend || MetricsBackend.instance end |
Instance Method Details
#export ⇒ String
Export all metrics in Prometheus text format
Returns metrics in the standard Prometheus exposition format as specified at: https://prometheus.io/docs/instrumenting/exposition_formats/
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tasker/telemetry/prometheus_exporter.rb', line 31 def export return '' unless telemetry_enabled? metrics_data = @backend.export return '' if metrics_data[:metrics].empty? output = [] output << (metrics_data) output << export_metrics(metrics_data[:metrics]) "#{output.flatten.compact.join("\n")}\n" rescue StandardError => e # Log error but don't fail the export log_export_error(e) export_error_metric(e) end |
#safe_export ⇒ Hash
Export metrics with error handling
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tasker/telemetry/prometheus_exporter.rb', line 50 def safe_export { success: true, data: export, timestamp: Time.current.iso8601, total_metrics: @backend.export[:total_metrics] || 0 } rescue StandardError => e { success: false, error: e., timestamp: Time.current.iso8601, total_metrics: 0 } end |