The `ruby_process_cpu_seconds_total` is incorrect
We have the ruby_process_cpu_seconds_total
which seems today to be calculated with:
def self.cpu_time
Process
.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_second)
end
Which seems to be incorrect in any type of environment:
- Unicorn, we can still spawn threads in some circumstances,
- Puma, we run in multiple threads by definition,
- RubySampler anyway run in separate thread in sleep-based loop,
It seems that the proper implementation is already there, but for whatever reason we prever THREAD_CPUTIME_ID
instead of PROCESS_CPUTIME_ID
.
def self.cpu_time
Process.clock_gettime(
Process::CLOCK_PROCESS_CPUTIME_ID, :float_second)
end
The metric generated from this measurement also has the bug outlined in https://gitlab.com/gitlab-org/gitlab-ce/issues/63872:
# HELP ruby_process_cpu_seconds_total Multiprocess metric
# TYPE ruby_process_cpu_seconds_total gauge
ruby_process_cpu_seconds_total 0.97053440999999996
ruby_process_cpu_seconds_total 0.95902426299999999