On Friday, 2 October 2020 19:14:49 UTC+1, Erick wrote:
>
> I understand that prometheus divides vectors via label matching. However, 
> sometimes dividing by vectors with non-matching labels "makes sense"
>

It's possible to convert a vector to a scalar.  But fundamentally you still 
need to identify which value of the other metric you want to divide by - 
since in general one metric has multiple timeseries, each identified by a 
different set of labels.
 

> Take my particular use case:
>
> I am trying to integrate two exporters, process-exporter and 
> node-exporter, correlating process memory metrics with node memory metrics.
>
> To calculate memory use, I divide a process' memory use by the total 
> memory on the machine
>
> Node-exporter exposes this as node_memory_MemTotal_bytes
>
> Now this metric will never change, this is basically a "scalar"
>
> What is the proper way to divide the first vector by the second vector?
>

First, find some label or combination of labels which matches the process 
memory to the associated node memory - in this case it might just be the 
"instance" label.

Then do something like: 

foo / on (instance) group_left bar

This assumes that for any particular value of "instance" label, there could 
be many values of the "foo" metric but only one value of the "bar" metric.
 
If you show some actual examples of the metrics you want to divide, 
complete with labels, then more specific advice is possible.  Here is a 
fairly silly example (ratio of filesystem size to node RAM size!)

node_filesystem_avail_bytes / on(instance) group_left 
node_memory_MemTotal_bytes

You can also copy labels from the right-hand metric into the result.  This 
is a more realistic example:

node_filesystem_avail_bytes * on(instance) 
group_left(domainname,machine,nodename) node_uname_info

The value of the RHS is always 1, so the multiply doesn't do anything, but 
it picks up those three extra labels from the RHS and applies them to the 
result.

I don't see anything in the docs mentioning this and have searched the 
> issues but haven't found much.
>
>
Vector matching is described here:
https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching

You may also find useful clues here:
https://www.robustperception.io/how-to-have-labels-for-machine-roles
https://www.robustperception.io/exposing-the-software-version-to-prometheus
https://www.robustperception.io/left-joins-in-promql
 

-- 
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 prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/59853d13-e294-40e8-87b4-8216ae6363cbo%40googlegroups.com.

Reply via email to