How can I calculate node process usage in percentage?

267 views
Skip to first unread message

Wang Yngwie

unread,
Jan 18, 2021, 3:32:06 AM1/18/21
to Prometheus Users
Hi, everyone. 
I use process-exporter to get some process' memory usage like: namedprocess_namegroup_memory_bytes{job="process",ip="10.1.1.2",memtype="resident"}. 
Also I can get this node's total memory by node-exporter like: node_memory_MemTotal_bytes{job="node",ip="10.1.1.2"}.
But when I divide them I got nothing: namedprocess_namegroup_memory_bytes{job="process",ip="10.1.1.2",memtype="resident"} / node_memory_MemTotal_bytes{job="node",ip="10.1.1.2"}.
So how can I get the usage in percentage?

Julius Volz

unread,
Jan 18, 2021, 3:43:58 AM1/18/21
to Wang Yngwie, Prometheus Users
By default, a binary operator will try to match series from both sides on *all* of their labels, so only series with identical labelsets will match and make it into the output.

You will need to constrain which labels are used for matching using "on()" or "ignoring()" (include-list vs. exclude-list), and potentially also allow a many-to-one match (assuming your left selector can select multiple processes, whereas the right side is only one series per "ip"). This might work:

  namedprocess_namegroup_memory_bytes{job="process",ip="10.1.1.2",memtype="resident"}
/ on(ip) group_left()
  node_memory_MemTotal_bytes{job="node",ip="10.1.1.2"}

This is assuming that the "ip" label will always be present and match on both sides, like in the two example series you provided. And then to get the same information for multiple hosts + processes you would remove the "ip" in the selector to get all of them:

  namedprocess_namegroup_memory_bytes{job="process",memtype="resident"}
/ on(ip) group_left()
  node_memory_MemTotal_bytes{job="node"}

--
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/b4fb993b-fccd-4d10-9720-32676d60eb10n%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com

Wang Yngwie

unread,
Jan 18, 2021, 4:02:31 AM1/18/21
to Prometheus Users
Brilliant, thank you very much :)
Reply all
Reply to author
Forward
0 new messages