Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pavelmash opened this issue Dec 12, 2020 · 2 comments

Comments

@pavelmash
Copy link
Contributor

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
Copy link
Contributor Author

pavelmash commented Dec 18, 2020

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants