3 int do_proc_uptime(int update_every, usec_t dt) {
6 static RRDSET *st = NULL;
7 collected_number uptime = 0;
9 #ifdef CLOCK_BOOTTIME_IS_AVAILABLE
10 uptime = now_boottime_usec() / 1000;
12 static procfile *ff = NULL;
15 char filename[FILENAME_MAX + 1];
16 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/uptime");
18 ff = procfile_open(config_get("plugin:proc:/proc/uptime", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
23 ff = procfile_readall(ff);
25 return 0; // we return 0, so that we will retry to open it next time
27 if(unlikely(procfile_lines(ff) < 1)) {
28 error("/proc/uptime has no lines.");
31 if(unlikely(procfile_linewords(ff, 0) < 1)) {
32 error("/proc/uptime has less than 1 word in it.");
36 uptime = (collected_number)(strtold(procfile_lineword(ff, 0, 0), NULL) * 1000.0);
39 // --------------------------------------------------------------------
42 st = rrdset_find("system.uptime");
45 st = rrdset_create("system", "uptime", NULL, "uptime", NULL, "System Uptime", "seconds", 1000, update_every, RRDSET_TYPE_LINE);
46 rrddim_add(st, "uptime", NULL, 1, 1000, RRDDIM_ABSOLUTE);
50 rrddim_set(st, "uptime", uptime);