digitalocean / prometheus-client-c

A Prometheus Client in C
Other
160 stars 79 forks source link

process_start_time_seconds returns clock ticks since boot instead of time of the process since unix epoch in seconds #44

Open pavelmash opened 3 years ago

pavelmash commented 3 years ago

The solution is to read btime from /proc/stat (once) and calculate process_start_time_seconds as

long      jiffies_per_second;
jiffies_per_second=sysconf(_SC_CLK_TCK);
process_start_time_seconds = btime + stat->starttime / jiffies_per_second;
pavelmash commented 3 years ago

I create a gist what reads btime from stats

C is not my main language, I not sure where to put a readbtime function in the libprom sources.

ap-wtioit commented 1 year ago

it seems to read /proc/{pid}/stats which according to https://man7.org/linux/man-pages/man5/proc.5.html needs to be handled roughly as you described.

it is read in https://github.com/digitalocean/prometheus-client-c/blob/master/prom/src/prom_process_stat.c#L164 with sscanf. process_cpu_total_seconds already has some conversion code in https://github.com/digitalocean/prometheus-client-c/blob/master/prom/src/prom_collector.c#L225.

and i guess we could patch it in https://github.com/digitalocean/prometheus-client-c/blob/master/prom/src/prom_collector.c#L249