X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fuptime.c;h=345128da62f6750d30655d74a3f35a841ec6a110;hb=56d85ff7bc14d98da63dc443e25085bc5544a1ea;hp=d2ba9633db290aeb17ac0a064874b3c652742b3a;hpb=307459f5a1d79ee373cf59c7c8a0824d325c43e3;p=collectd.git diff --git a/src/uptime.c b/src/uptime.c index d2ba9633..345128da 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -37,6 +37,12 @@ /* Using sysctl interface to retrieve the boot time on *BSD / Darwin / OS X systems */ /* #endif HAVE_SYS_SYSCTL_H */ +#elif HAVE_PERFSTAT +# include +# include +/* Using perfstat_cpu_total to retrive the boot time in AIX */ +/* #endif HAVE_PERFSTAT */ + #else # error "No applicable input method." #endif @@ -203,7 +209,29 @@ static int uptime_init (void) /* {{{ */ "but `boottime' is zero!"); return (-1); } -#endif /* HAVE_SYS_SYSCTL_H */ +/* #endif HAVE_SYS_SYSCTL_H */ + +#elif HAVE_PERFSTAT + int status; + perfstat_cpu_total_t cputotal; + int hertz; + + status = perfstat_cpu_total(NULL, &cputotal, + sizeof(perfstat_cpu_total_t), 1); + if (status < 0) + { + char errbuf[1024]; + ERROR ("uptime plugin: perfstat_cpu_total: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + hertz = sysconf(_SC_CLK_TCK); + if (hertz <= 0) + hertz = HZ; + + boottime = time(NULL) - cputotal.lbolt / hertz; +#endif /* HAVE_PERFSTAT */ return (0); } /* }}} int uptime_init */ @@ -213,7 +241,7 @@ static int uptime_read (void) gauge_t uptime; time_t elapsed; - /* calculate the ammount of time elapsed since boot, AKA uptime */ + /* calculate the amount of time elapsed since boot, AKA uptime */ elapsed = time (NULL) - boottime; uptime = (gauge_t) elapsed;