Prometheus provides or
operator, which can be used for combining results from multiple queries in a single API call. For example, the following query returns results for q1
, q2
and q3
:
q1 or q2 or q3
The or
operator in PromQL has a quirk though - if some time series returned by q1
, q2
and q3
have the same set of labels (excluding metric name aka __name__
label), then only the first encountered time series is returned. For example, the following query returns only process_cpu_seconds_total
time series, and doesn't return process_resident_memory_bytes
time series, since they have the same set of labels except of metric name:
process_cpu_seconds_total or process_resident_memory_bytes
This can be fixed by copying the metric name into another label. For example, the following query copies the metric name into metric_name
label, so the or
result contains time series from both process_cpu_seconds_total
and process_resident_memory_bytes
sides:
label_join(process_cpu_seconds_total, "metric_name", "", "__name__")
or
label_join(process_resident_memory_bytes, "metric_name", "", "__name__")
P.S. There is a simpler solution for obtaining results from multiple queries in one call if using an alternative Prometheus-like monitoring system I work on - VictoriaMetrics - it provides union function for this task. For example, the following query returns time series for both process_cpu_seconds_total
and process_resident_memory_bytes
queries:
union(
process_cpu_seconds_total,
process_resident_memory_bytes,
)