X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fuptime.c;h=345128da62f6750d30655d74a3f35a841ec6a110;hb=5523a080010dcb7a61dc0dccc3969a2a048e52f9;hp=d2ba9633db290aeb17ac0a064874b3c652742b3a;hpb=b3bfb951c73ea3d232e0e97a42479a5e3310125d;p=collectd.git diff --git a/src/uptime.c b/src/uptime.c index d2ba9633..cbe2f8c5 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -20,6 +20,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -37,6 +38,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 @@ -173,17 +180,13 @@ static int uptime_init (void) /* {{{ */ /* #endif HAVE_LIBKSTAT */ # elif HAVE_SYS_SYSCTL_H - struct timeval boottv; + struct timeval boottv = { 0 }; size_t boottv_len; int status; - int mib[2]; - - mib[0] = CTL_KERN; - mib[1] = KERN_BOOTTIME; + int mib[] = { CTL_KERN, KERN_BOOTTIME }; boottv_len = sizeof (boottv); - memset (&boottv, 0, boottv_len); status = sysctl (mib, STATIC_ARRAY_SIZE (mib), &boottv, &boottv_len, /* new_value = */ NULL, /* new_length = */ 0); @@ -203,7 +206,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 +238,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;