October 27, 2023

Reading Time:


Validate Prometheus Alert rules and config using the promtool


Prometheus is a powerful, widely used open source monitoring tool. Alerting is one of the most critical features of Prometheus that allows users to define alerts based on predefined rules and thresholds. One of the key benefits of alerting in Prometheus is its flexibility and granularity. Users can define alerts at different levels of specificity, from individual hosts or applications to entire clusters or environments. This allows users to tailor their alerting strategies to their specific needs and requirements while ensuring they are notified only when relevant issues arise.

In typical production environments where hundreds of alerts are configured, it can quickly become difficult to ensure that changes to alert rules are valid. Invalid changes usually result in Prometheus rejecting all of the defined alert rules. It is highly recommended to validate alert rules before they are applied to Prometheus. This blog post explores a simple solution to quickly validate Prometheus alert config changes. A handy tool that can be used to validate alert rules is “promtool”, which is included in the standard Prometheus package.

Prometheus alerts are written in YAML. Here is an example of a Prometheus alert rule that is set to trigger when the free disk space on an instance falls below 10%:

Installing Promtool

Promtool can be installed on a Linux machine with the following steps:

Validating a Rules File Using Promtool

Assuming the Prometheus rules are located in a rules.yaml file, run the following command to validate it:

The tool displays a descriptive error message when there are errors in the rules file:

Promtool offers several other handy features as well. The “help” subcommand, for example, provides the following details:

We at OpsVerse use Prometheus extensively in ObserveNow, an open source-based observability tool built for enterprises. Learn more about ObserveNow here and take it for a free 14-day ride.


Written by Arul Jegadish Francis

Subscribe to the OpsVerse blog

New posts straight to your inbox