Separate metrics vs one metric with separate labels

29 views
Skip to first unread message

Daniel Lo Nigro

unread,
May 16, 2020, 10:08:12 PM5/16/20
to Prometheus Users
I've noticed that for some metrics, Prometheus node_exporter will use one metric name and separate labels. For example, CPU usage has a "mode" label:

node_cpu_seconds_total{cpu="0",mode="idle"} 320045.23
node_cpu_seconds_total{cpu="0",mode="steal"} 0
node_cpu_seconds_total{cpu="0",mode="system"} 3703.1
node_cpu_seconds_total{cpu="0",mode="user"} 4713.87

Whereas for other metrics, it uses separate metric names. For example, memory usage:

node_memory_MemAvailable_bytes 1.00470784e+08
node_memory_MemFree_bytes 5.3211136e+07
node_memory_MemTotal_bytes 2.68435456e+08

Both are bounded (there's a fixed number of CPU modes, and a fixed number of memory fields) so I'm not sure why the implementation differs between the two.

Is this intentional? If so, is there a guideline or best practice as to when to do the former vs when to do the latter?

Thanks!

Brian Brazil

unread,
May 17, 2020, 3:21:39 AM5/17/20
to Daniel Lo Nigro, Prometheus Users

Brian
 

Thanks!

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/8722a500-e5c9-443e-8183-6bdb76699509%40googlegroups.com.


--

Ben Kochie

unread,
May 17, 2020, 5:12:10 AM5/17/20
to Daniel Lo Nigro, Prometheus Users
It's about aggregation and doing math on the data.

sum(node_cpu_seconds_total) makes sense, because all of the various modes can be added together.

Say you had labels for memory:

node_memory_bytes{mem_type="MemAvailable"} 1.00470784e+08
node_memory_bytes{mem_type="MemFree"} 5.3211136e+07
node_memory_bytes{mem_type="MemTotal"} 2.68435456e+08

sum(node_memory_bytes) is nonsensical because "MemTotal" + "MemFree" + "MemAvailable" doesn't add up to anything useful.

But, having them as separate metrics makes queries like "node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes" work out

Think of metric names and labels as column vs rows in a spreadsheet. Aggregation operators like sum() avg() min() max() work vertically. Mathematical operators like + - / * work horizontally.

--

Daniel Lo Nigro

unread,
May 17, 2020, 4:16:39 PM5/17/20
to Prometheus Users
Thank you Ben for the detailed explanation! This makes sense.
To unsubscribe from this group and stop receiving emails from it, send an email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages