C3 AI Documentation Home

Prometheus API

The Prometheus type provides access to the Prometheus HTTP API for querying metrics, retrieving metadata, and monitoring Prometheus server status. The type mixes REST and can be configured with a base URL and authentication.

Getting Started

Create a Prometheus instance by specifying a name and configuring the base URL:

JavaScript
var prom = Prometheus.forName('app');

The Prometheus instance must be configured with a base URL pointing to your Prometheus server. Configuration is typically stored in config/rest/Prometheus/<instance-name>.json.

API Methods

Discovering Metrics

Getting Metric Names

JavaScript
prom.metricNames()
prom.metricNames('{__name__=~".+"}')
prom.metricNames('{job=~".+"}', DateTime.now().minusDays(7), DateTime.now())  // names for jobs in the last 7 days
prom.metricNames(null, DateTime.now().minusHours(1), DateTime.now())  // names from the last hour
prom.metricNames('{__name__=~"^http.*"}')  // names that start with 'http'
prom.metricNames('{__name__=~".*error.*"}')  // names that contain 'error'
prom.metricNames(null, null, null, 100)  // limit to first 100 names
prom.metricNames('{__name__=~"^http.*"}', null, null, 50)  // limit to first 50 names starting with 'http'

Getting Metadata

JavaScript
prom.metadata()
prom.metadata('http_requests_total')  // metadata for specific metric
prom.metadata(null, 100)  // limit to 100 metrics
prom.metadata(null, null, 1)  // limit to 1 metadata entry per metric
prom.metadata('http_requests_total', null, 1)  // specific metric with 1 entry per metric

Getting Label Names

JavaScript
prom.labels()
prom.labels('{job=~".+"}')  // label names for series matching job filter
prom.labels(null, DateTime.now().minusDays(7), DateTime.now())  // label names in time range
prom.labels('{__name__=~".+"}', null, null, 100)  // limit to 100 label names

Querying Label Values

JavaScript
prom.label('job')
prom.label('job', '{__name__="up"}')
prom.label('instance', null, DateTime.now().minusMinutes(15), DateTime.now())  // time range without match filter
prom.label('job', '{__name__=~".+"}', DateTime.now().minusDays(1), DateTime.now(), 100)

Querying Metrics

Instant Query

JavaScript
prom.query('up', DateTime.now())
prom.query('rate(http_requests_total[5m])', DateTime.now().minusMinutes(5))

Range Query

JavaScript
prom.queryRange('rate(http_requests_total[5m])', DateTime.now().minusHours(1), DateTime.now(), '15s')
prom.queryRange('up', DateTime.now().minusDays(7), DateTime.now(), '1h')

Series Query

JavaScript
prom.series('{job=~".+"}', DateTime.now().minusDays(1), DateTime.now())
prom.series('{__name__=~"http.*"}', DateTime.now().minusHours(6), DateTime.now())

Status and Monitoring

Configuration Status

JavaScript
prom.statusConfig()

Runtime Information

JavaScript
prom.statusRuntimeInfo()

Build Information

JavaScript
prom.statusBuildInfo()

TSDB Statistics

JavaScript
prom.statusTsdb()

Targets

JavaScript
prom.targets()
prom.targets('active')
prom.targets('dropped')

Rules

JavaScript
prom.rules()
prom.rules('alert')
prom.rules('record')

Alerts

JavaScript
prom.alerts()
prom.alerts('{alertname="HighErrorRate"}')
prom.alerts('{severity="critical"}')

See Also

Was this page helpful?