How does one add a where clause in PromQL?
I'm trying to construct a query that displays when an application running in Kubernetes has been up for more than one minute but I want to filter by namespace.
This is what my query looks like at the moment
100 * (count(up == 1) BY (job, namespace, service) ) > 1
This works fine but it gives me additional information that I don't need.
{job="prometheus-grafana", namespace="monitor", service="prometheus-grafana"}
{job="jenkins", namespace="jenkins", service="jenkins"}
{job="kube-state-metrics", namespace="monitor", service="prometheus-kube-state-metrics"}
{job="node-exporter", namespace="monitor", service="prometheus-prometheus-node-exporter"}
{job="kubelet", namespace="kube-system", service="prometheus-kube-prometheus-kubelet"}
{job="apiserver", namespace="default", service="kubernetes"}
What I'm trying to accomplish is to get results for only the jenkins
and default
namespace.
{job="apiserver", namespace="default", service="kubernetes"}
{job="jenkins", namespace="jenkins", service="jenkins"}
I've tried doing
100 * (count(up == 1) BY (job, namespace, service) ) > 1 and ON {namespace="jenkins"}
But I get an invalid parameter "query": 1:65: parse error: unexpected "{" in grouping opts, expected "("
error.
time()-60 > (kube_pod_start_time)
Prometheus provides the following ways for filtering the data in queries:
up{namespace=~"default|jenkins"}
is a series selector, which returns only time series with the name up
, which contain label namespace
matching the given given regular expression: default|jenkins
. This is roughly equivalent to the following SQL:SELECT * FROM table WHERE name = 'up' and namespace ~ '^(default|jenkins)#x27;
up == 0
returns time series with up
name, which have 0
value. This is roughly equivalent to the following SQL:SELECT * FROM table WHERE name = 'up' and value == 0
up * on(instance) group_left(name) node_os_info
joins up
metric with node_os_info
metric via instance
label and selects additional name
label from node_os_info
metric. This is roughly equivalent to the following SQL:SELECT up.*, node_os_info.name
FROM up LEFT JOIN node_os_info ON (instance)
You would have to filter the metric "up" by the labels you want (namespaces) in your case it should look something like this:
100 * count(up{namespace=~"default|jenkins"} == 1) > 1