Prometheus Monitoring

24 views
Skip to first unread message

Bill Zalokostas

unread,
Mar 31, 2021, 10:52:01 AM3/31/21
to Prometheus Users

Hello,
I want to measure the percentage of cpu usage that is used for a specific 
image including all containers that run this image. Can you provide me the 
query function in order to solve my problem? Also, can you share a link in 
which every expression in prometheus query is being explained (basically 
what every exprassion mean e.x. container_spec_cpu_quota) because I can't 
find anything on the Internet and the docs that you have aren't mention 
anything?

Thank you in advance

Julius Volz

unread,
Mar 31, 2021, 12:19:41 PM3/31/21
to Bill Zalokostas, Prometheus Users
Hi,

The meaning of metric names is defined by the application that exposes them, so there's no overall fixed 1:1 relationship between a metric name and its meaning in the Prometheus world. It depends on the code that outputs the metric. However, of course there are many metric names that are pretty standardized in practice, and for example, "container_spec_cpu_quota" looks like a metric that cAdvisor (or the equivalent code in a Kubernetes Kubelet) exposes about each container running on the machine. It seems that https://docs.signalfx.com/en/latest/integrations/agent/monitors/cadvisor.html has a pretty good summary of the different cAdvisor metric names, but you should also be able to go in a web browser to a cAdvisor /metrics endpoint and see a HELP comment line explaining the meaning of each metric name (this usually works for other metrics-exposing processes as well).

To get the current CPU usage (as averaged over 5 minutes) in %, summed over all containers using a certain image (e.g. "my-image-name"), you could do something like this:

sum by(image) (rate(container_cpu_usage_seconds_total{image="my-image-name"}[5m])) * 100


The "* 100" in the expression converts the per-core usage into a percentage. Note that this can go above 100% if you have more than one CPU core.

Regards,
Julius

--
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/5bd3df94-baec-41a5-b9f4-625ffb354245n%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com
Reply all
Reply to author
Forward
0 new messages