turbot/prometheus
steampipe plugin install prometheus

Table: prometheus_rule - Query Prometheus Rules using SQL

Prometheus is an open-source systems monitoring and alerting toolkit. It collects metrics from configured targets at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some condition is observed to be true. Prometheus's main features are a multi-dimensional data model with time series data identified by metric name and key/value pairs, a flexible query language to leverage this dimensionality, and no reliance on distributed storage.

Table Usage Guide

The prometheus_rule table provides insights into rules within the Prometheus service. As a DevOps engineer, explore rule-specific details through this table, including rule configurations, alerting rules, and associated metadata. Utilize it to uncover information about rules, such as those triggering certain alerts, the conditions set for each rule, and the verification of rule expressions.

Examples

List all rules

Explore all the rules in your Prometheus setup, organized by group name and rule number. This can help you understand the structure and hierarchy of your rules for better management and troubleshooting.

select
*
from
prometheus_rule
order by
group_name,
group_rule_num;
select
*
from
prometheus_rule
order by
group_name,
group_rule_num;

Rules with a labeled severity of high

This query is used to identify any rules within the Prometheus system that have been marked with a high severity label. This could be useful in prioritizing responses to system alerts or issues, by focusing on the most critical rules first.

select
name,
labels,
state
from
prometheus_rule
where
labels ->> 'severity' = 'high';
select
name,
labels,
state
from
prometheus_rule
where
json_extract(labels, '$.severity') = 'high';

Rules that are firing

Explore which rules are currently active or 'firing' within your Prometheus monitoring system. This can aid in identifying potential issues or anomalies in your network or system that require immediate attention.

select
name,
labels,
state
from
prometheus_rule
where
state = 'firing';
select
name,
labels,
state
from
prometheus_rule
where
state = 'firing';

Slow running rules with evaluation time > 1 sec

Analyze your system's performance by pinpointing rules that are running slowly, taking more than one second for evaluation. This can help you identify potential bottlenecks or areas for optimization to improve overall system efficiency.

select
name,
labels,
state
from
prometheus_rule
where
evaluation_time > 1;
select
name,
labels,
state
from
prometheus_rule
where
evaluation_time > 1;

Schema for prometheus_rule

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form.
alertsjsonbAlerts for the rule.
annotationsjsonbAnnotations to add to each alert.
durationdouble precisionAlerts are considered firing once they have been returned for this long. Alerts which have not yet fired for long enough are considered pending.
evaluation_timedouble precisionTime taken in seconds to run the rule evaluation.
group_filetextPath to the file that defines the rule group for this rule.
group_intervaltextInterval between evaluations for rules in this rule group.
group_nametextName of the rule group that contains the rule.
group_rule_numbigintRule number within the group. Starts at 1.
healthtextHealth of the rule, e.g. ok.
labelsjsonbLabels to add or overwrite for each alert.
last_errortextLast error message from the rule, if any.
last_evaluationtimestamp with time zoneTime when the rule was last evaluated.
nametextName of the alert.
querytextThe PromQL expression to evaluate. Every evaluation cycle this is evaluated at the current time, and all resultant time series become pending/firing alerts.
sp_connection_nametextSteampipe connection name.
sp_ctxjsonbSteampipe context in JSON form.
statetextState of the alert for this rule, e.g. firing, inactive.

Export

This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.

You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh script:

/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- prometheus

You can pass the configuration to the command with the --config argument:

steampipe_export_prometheus --config '<your_config>' prometheus_rule