How do you convert cpu_user_seconds to cpu usage in percentage?
Answer
To convert cpu_user_seconds to CPU usage in percentage, you need to divide it by the total elapsed time and the number of CPU cores, and then multiply by 100. The formula is as follows:
100 * sum(rate(process_cpu_user_seconds_total{job=""}[])) by (instance) / ( * )
Here, ** is the name of the job you want to query, ** is the time range you want to query (e.g. 5m, 1h), and ** is the number of CPU cores on the machine you are querying.
For example, to get the CPU usage in percentage for the last 5 minutes for a job named my-job running on a machine with 4 CPU cores, you can use the following query:
100 * sum(rate(process_cpu_user_seconds_total{job="my-job"}[5m])) by (instance) / (5m * 4)