Implementation:Tensorflow Serving PrometheusExporter GeneratePage
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Monitoring, Operations |
| Last Updated | 2026-02-13 17:00 GMT |
Overview
Concrete tool for exporting TensorFlow Serving metrics in Prometheus text format via HTTP endpoint, provided by the prometheus_exporter module.
Description
PrometheusExporter::GeneratePage() collects all registered metrics from CollectionRegistry::Default() and serializes them in Prometheus text format. It uses three serialization helpers:
- SerializeHistogram() (L65-115): Converts histogram/sampler metrics to Prometheus bucket format
- SerializeScalar() (L117-130): Converts counter/gauge metrics
- SerializeMetric() (L132-152): Dispatches to histogram or scalar serializer based on metric type
The exporter is exposed at kPrometheusPath ("/monitoring/prometheus/metrics") via the HTTP server when monitoring is enabled.
Usage
Accessible at http://<host>:<rest_api_port>/monitoring/prometheus/metrics. Configure Prometheus to scrape this endpoint.
Code Reference
Source Location
- Repository: tensorflow/serving
- File: tensorflow_serving/util/prometheus_exporter.cc L156-193
- Header: tensorflow_serving/util/prometheus_exporter.h L29-44
Signature
class PrometheusExporter {
public:
static const char* const kPrometheusPath; // "/monitoring/prometheus/metrics"
PrometheusExporter();
Status GeneratePage(string* http_page);
private:
monitoring::CollectionRegistry* collection_registry_;
};
Import
#include "tensorflow_serving/util/prometheus_exporter.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| http_page | string* | Yes | Output buffer for the metrics page |
Outputs
| Name | Type | Description |
|---|---|---|
| http_page | string* | Prometheus text-format metrics page |
Usage Examples
Scrape Metrics
# Get all metrics
curl http://localhost:8501/monitoring/prometheus/metrics
# Example output:
# HELP :tensorflow:serving:batching_session:queuing_latency Queuing latency
# TYPE :tensorflow:serving:batching_session:queuing_latency histogram
# :tensorflow:serving:batching_session:queuing_latency_bucket{le="100"} 42
# :tensorflow:serving:batching_session:queuing_latency_count 100
# :tensorflow:serving:batching_session:queuing_latency_sum 5432.1
Prometheus Config
# prometheus.yml
scrape_configs:
- job_name: 'tf_serving'
scrape_interval: 15s
static_configs:
- targets: ['localhost:8501']
metrics_path: '/monitoring/prometheus/metrics'
MonitoringConfig Proto
# monitoring_config.txt
prometheus_config {
enable: true
path: "/monitoring/prometheus/metrics"
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment