Hi Sandesh,

There's unfortunately no way to create variables directly in a PromQL query
itself, but you could use a recording rule (see
https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/)
to pre-record the long expression into a shorter new metric name that you
can then use in your second query.

Regards,
Julius

On Tue, Dec 13, 2022 at 9:03 AM Sandesh Shivakumar <
[email protected]> wrote:

> Hello All,
>
> I wanted to store the below Prometheus query into an variable.
> (node_memory_MemTotal_bytes{job="kubernetes-service-endpoints",cluster="$cluster",instance=~"$node"}
> * on(instance) group_left(nodename)
> group(node_uname_info{})by(instance,nodename)-(node_memory_MemFree_bytes{job="kubernetes-service-endpoints",cluster="$cluster",instance=~"$node"}
> * on(instance) group_left(nodename)
> group(node_uname_info{})by(instance,nodename) ))
>
> and use it in second query ,
> z = (sum(rate(metric)[1m]) - sum(avg_over_time(metric[1w])) /
> sum(stddev_over_time(metric[1w]))
>
> Is there any way to achieve this.
> Thankyou
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-users/f8887aef-98dc-4207-b353-77247fcaf453n%40googlegroups.com
> <https://groups.google.com/d/msgid/prometheus-users/f8887aef-98dc-4207-b353-77247fcaf453n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Julius Volz
PromLabs - promlabs.com

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/CAObpH5w5iSNLrQG5R0qz%3D_L%2BeqZNyG7QAzkOvA4zt74RCx6%3DVg%40mail.gmail.com.

Reply via email to