@@ -101,6 +101,7 @@ type collector struct {
101101 errors []error
102102 httpCollector * collectors.HTTPCollector
103103 tsStorage * storage.TimeSeriesStorage
104+ promBridge * exporters.PrometheusBridge
104105}
105106
106107// CollectorConfig contains configuration for the metrics collector.
@@ -154,6 +155,13 @@ func New(config *CollectorConfig, logger logger.Logger) Metrics {
154155 // Initialize exporters
155156 c .initializeExporters ()
156157
158+ // Prometheus bridge: reads the merged snapshot fresh on each scrape.
159+ c .promBridge = exporters .NewPrometheusBridge (c .GetMetrics , exporters.PrometheusConfig {
160+ Namespace : c .config .Collection .Namespace ,
161+ EnableGoCollector : true ,
162+ EnableProcessCollector : true ,
163+ })
164+
157165 // Initialize time-series storage for historical metric queries.
158166 c .tsStorage = storage .NewTimeSeriesStorageWithConfig (& storage.TimeSeriesStorageConfig {
159167 Retention : time .Hour ,
@@ -582,7 +590,10 @@ func (c *collector) GetMetricsByTag(tagKey, tagValue string) map[string]any {
582590
583591// Export exports metrics in the specified format.
584592func (c * collector ) Export (format metrics.ExportFormat ) ([]byte , error ) {
585- // Snapshot exporter without holding lock during export operation
593+ if format == metrics .ExportFormatPrometheus && c .promBridge != nil {
594+ return c .promBridge .GatherText ()
595+ }
596+
586597 c .mu .RLock ()
587598 exporter , exists := c .exporters [format ]
588599 c .mu .RUnlock ()
@@ -593,9 +604,15 @@ func (c *collector) Export(format metrics.ExportFormat) ([]byte, error) {
593604
594605 // Get metrics without holding the collector lock
595606 // This prevents deadlock with other systems (health checks, etc.) that may need locks
596- metrics := c .GetMetrics ()
607+ allMetrics := c .GetMetrics ()
597608
598- return exporter .Export (metrics )
609+ return exporter .Export (allMetrics )
610+ }
611+
612+ // PrometheusHandler returns an http.Handler that serves the Prometheus scrape
613+ // endpoint. Implements shared.PrometheusProvider.
614+ func (c * collector ) PrometheusHandler () http.Handler {
615+ return c .promBridge .Handler ()
599616}
600617
601618// ExportToFile exports metrics to a file.
@@ -739,14 +756,6 @@ func (c *collector) initializeBuiltinCollectors() error {
739756 }
740757 }
741758
742- // Register runtime metrics collector
743- if c .config .Features .RuntimeMetrics {
744- runtimeCollector := collectors .NewRuntimeCollector ()
745- if err := c .registerCollectorLocked (runtimeCollector ); err != nil {
746- return fmt .Errorf ("failed to register runtime collector: %w" , err )
747- }
748- }
749-
750759 // Register HTTP collector
751760 if c .config .Features .HTTPMetrics {
752761 httpCollector := collectors .NewHTTPCollector ()
0 commit comments