Write a PromQL query
Now that you have a panel configured, it’s time to write the query. A query is an expression that specifies the dataset to be used in the visualization.
A PromQL query consists of three basic elements:
- Metric: A metric represents the specific time series data you want to analyze. It is the foundation of your query and defines the type of data to retrieve. For example,
node_cpu_usage_seconds_totalis a metric that tracks CPU usage over time. - Label filter: A label filter allows you to refine your query by specifying key-value pairs that narrow down the dataset. This helps you focus on specific subsets of data, such as a particular node or instance. For example, a label filter like
node="i-077dec042c9d8a744"retrieves data only for the specified node. - Operation: An operation modifies or processes the data retrieved by the query. It can perform calculations, aggregations, or transformations to derive meaningful insights. For example, the
rate()operation calculates the per-second rate of increase for a given metric.
To write a PromQL query using the Query Builder, complete the following steps:
Click the Metric drop-down list to select a metric.
For example, select
node_cpu_usage_seconds_total.(Optional) In the Label filters fields, select a key-value pair and operator to filter your data. For example, select
node,=, and your specific node ID.Click + Operations to add a function to your query.
For example, select Range > Rate and
$__rate_interval.Click + Operations again to add another operation.
For example, select Aggregations > Sum.
Click Refresh in the toolbar to run the query and populate the visualization with data.
Did you know? If you’re unsure of the metric name, click the Metrics explorer icon to search for metrics by name and type.
Your visualization should now display data based on your query. In the next milestone, you’ll configure the time range and refresh interval.
