Prometheus Console template - "Name" Label substitution clarification.

95 views
Skip to first unread message

Brett Larson

unread,
Mar 9, 2021, 5:04:34 PM3/9/21
to Prometheus Users
I have been working on a very niche prometheus console template dashboard for a product we use and i've hit a roadblock - the "name" param for the graph library isn't very clear to me on how I can use it to optionally display a value.

Here is an example of the code used to display the graph.

new PromConsole.Graph({
node: document.querySelector("#cpuGraph"),
expr: "kube_pod_labels{dag_id='{{ .Params.dag_id }}',execution_date='{{ .Params.execution_date }}'} * on(pod) group_right(dag_id,execution_date,task_id) (sum(rate(container_cpu_usage_seconds_total[3m])) by (pod,task_id) * 100)",
name: "[[pod]] - [[task_id]]",
renderer: 'line',
yAxisFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
yHoverFormatter: PromConsole.NumberFormatter.humanizeNoSmallPrefix,
yTitle: 'Cores Used'
})

The problem is that not every one of these pods has this label, so I get a nice "undefined" message as shown below -
undefined.png

Is there a way to not display this value if it's undefined? 

I see that the description and source code hint that I can use a function, but i'm not really sure what function i'm able to use.

Thanks in advance! Prometheus Console templates are really cool :)
Reply all
Reply to author
Forward
0 new messages