diff options
author | Patrick Li <pat@FreeBSD.org> | 2001-11-19 06:38:34 +0000 |
---|---|---|
committer | Patrick Li <pat@FreeBSD.org> | 2001-11-19 06:38:34 +0000 |
commit | 4a4b0cc5d35990ebf86fce3be641f3408fa83146 (patch) | |
tree | 8043053bf2342d684cd0651e8cfc5c56c9438b24 /misc/upclient/files/patch-stats-bsd.c | |
parent | o slave port handling enhancements (diff) |
Update to 4.2.1.23 The Uptimes Project is back!
PR: 32080
Submitted by: maintainer
Approved by: lioux
Notes
Notes:
svn path=/head/; revision=50208
Diffstat (limited to 'misc/upclient/files/patch-stats-bsd.c')
-rw-r--r-- | misc/upclient/files/patch-stats-bsd.c | 184 |
1 files changed, 51 insertions, 133 deletions
diff --git a/misc/upclient/files/patch-stats-bsd.c b/misc/upclient/files/patch-stats-bsd.c index d53fa937e08c..b5aea3fa6c2c 100644 --- a/misc/upclient/files/patch-stats-bsd.c +++ b/misc/upclient/files/patch-stats-bsd.c @@ -1,21 +1,6 @@ ---- src/stats-bsd.c.orig Mon Dec 18 14:32:19 2000 -+++ src/stats-bsd.c Sat Dec 30 03:26:15 2000 -@@ -12,57 +12,153 @@ - /* System includes */ - #include <stdio.h> - #include <errno.h> -+#include <fcntl.h> -+#include <limits.h> -+#include <kvm.h> - #include <syslog.h> - #include <sys/time.h> - #include <sys/param.h> - #include <sys/sysctl.h> -+#include <sys/dkstat.h> -+#include <devstat.h> - #include <sys/utsname.h> - - /** +--- src/stats-bsd.c.orig Sat Jun 16 21:12:53 2001 ++++ src/stats-bsd.c Sun Nov 18 17:33:52 2001 +@@ -26,37 +26,50 @@ * @desc Get statistics */ void getstats(unsigned long *puptime, double *pload, int *pidle, char *os, char *oslevel, char *cpu) { @@ -24,137 +9,68 @@ - time_t now; size_t size; - double loadavgs[2]; -- int mib[2]; -+ int mib [2]; -+ -+ { /* ========== uptime ========== */ + int mib[2]; + +- /* Get uptime */ +- time(&now); ++ { /* ========== uptime ========== */ + static struct timeval boottime; + static int initialized = 0; ++ time_t now; + + if (!initialized) { + initialized = 1; + -+ mib [0] = CTL_KERN; -+ mib [1] = KERN_BOOTTIME; -+ -+ size = sizeof (boottime); - -- /* Get uptime */ -- time(&now); -- mib[0] = CTL_KERN; -- mib[1] = KERN_BOOTTIME; -- size = sizeof(boottime); + mib[0] = CTL_KERN; + mib[1] = KERN_BOOTTIME; + size = sizeof(boottime); - if(sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && (boottime.tv_sec != 0)) { -- *puptime = now - boottime.tv_sec; -- *puptime /= 60; -- } -- -- if(cfg_sendload) { -- /* Get load average */ -- getloadavg(loadavgs, 3); -- /* Use the 3rd element (15 minute load average) */ -- *pload = loadavgs[2]; ++ + if (sysctl (mib, 2, &boottime, &size, NULL, 0) == -1) + err (1, "sysctl: kern.boottime"); - } - -- if(cfg_sendos) { -- /* Get os info */ -- uname(&uts); ++ } ++ + if (boottime.tv_sec) { + time_t now; + + time (&now); + -+ *puptime = (now - boottime.tv_sec) / 60; -+ } + *puptime = now - boottime.tv_sec; + *puptime /= 60; + } + } + -+ if (cfg_sendidle) { /* ========== idle_time ========== */ -+ static kvm_t *kp; -+ static struct nlist namelist [] = { -+#define X_CP_TIME 0 -+ { "_cp_time" }, -+ { NULL }, -+ }; ++ if(cfg_sendload) { /* ========== loadavg ========== */ ++ double loadavgs[3] = { 0. }; + +- if(cfg_sendload) { +- /* Get load average */ + getloadavg(loadavgs, 3); + /* Use the 3rd element (15 minute load average) */ + *pload = loadavgs[2]; + } + +- if(cfg_sendos) { +- /* Get os info */ +- uname(&uts); +- } ++ if(cfg_sendcpu) { /* ========== cpu ========== */ ++ static char buf [CPU_SIZE] = ""; + static int initialized = 0; + + if (!initialized) { -+ char errbuf [_POSIX2_LINE_MAX]; + initialized = 1; -+ -+ setgid (getgid ()); -+ -+ kp = kvm_openfiles (NULL, NULL, NULL, O_RDONLY, errbuf); -+ -+ if (!kp) -+ warn ("kvm_openfiles: %s", errbuf); -+ else if (kvm_nlist (kp, namelist) == -1) -+ warn ("kvm_nlist: %s", kvm_geterr (kp)); -+ } -+ -+ if (kp) { -+ long ctime [CPUSTATES]; -+ static long stime [CPUSTATES]; -+ static int first_time = 1; -+ -+ if (first_time) { -+ first_time = 0; -+ -+ if (kvm_read (kp, namelist [X_CP_TIME].n_value, -+ stime, sizeof (stime)) == -1) -+ warn ("kvm_read: %s", kvm_geterr (kp)); -+ else -+ sleep (1); /* to avoid the initial 0 idle value */ - } - if(cfg_sendcpu) { - /* Get CPU info */ -- mib[0] = CTL_HW; -- mib[1] = HW_MODEL; -- size = CPU_SIZE; + mib[0] = CTL_HW; + if(cfg_sendcpulevel == 1) { + mib[1] = HW_MACHINE; /* Send architecture */ +@@ -64,17 +77,35 @@ + mib[1] = HW_MODEL; /* Send architecture's specific model */ + } + size = CPU_SIZE; - sysctl(mib, 2, cpu, &size, NULL, 0); -+ if (kvm_read(kp, namelist [X_CP_TIME].n_value, -+ ctime, sizeof (ctime)) == -1) -+ warn ("kvm_read: %s", kvm_geterr (kp)); -+ else { -+ int state; -+ double time = 0.; -+ -+ for (state = 0; state < CPUSTATES; state++) -+ time += ctime [state] - stime [state]; -+ -+ if (time == 0.) -+ time = 1.; -+ -+ *pidle = (ctime [CP_IDLE] - stime [CP_IDLE]) * 100. / time; -+ -+ for (state = 0; state < CPUSTATES; state++) -+ stime [state] = ctime [state]; -+ } -+ } else -+ cfg_sendidle = 0; -+ } -+ -+ if (cfg_sendload) { /* ========== loadavg ========== */ -+ double loadavgs [3] = { 0. }; -+ -+ getloadavg (loadavgs, 3); -+ -+ *pload = loadavgs [2]; -+ } -+ -+ if (cfg_sendcpu) { /* ========== cpu ========== */ -+ static char buf [CPU_SIZE] = ""; -+ static int initialized = 0; -+ -+ if (!initialized) { -+ initialized = 1; -+ -+ mib [0] = CTL_HW; -+ mib [1] = HW_MODEL; -+ -+ size = sizeof (buf); + + if (sysctl (mib, 2, buf, &size, NULL, 0) == -1) + warn ("sysctl: hw.model"); @@ -165,24 +81,26 @@ } if(cfg_sendos) { -- strncpy(os, uts.sysname, OS_SIZE - 1); -- if(cfg_sendoslevel) { -- strncpy(oslevel, uts.release, OSLEVEL_SIZE - 1); + static struct utsname uts; + static int initialized = 0; + + if (!initialized) { + initialized = 1; -+ ++ + uname(&uts); + } + -+ strncpy (os, uts.sysname, OS_SIZE - 1); + strncpy(os, uts.sysname, OS_SIZE - 1); + os [OS_SIZE - 1] = 0; + -+ if (cfg_sendoslevel) { -+ strncpy (oslevel, uts.release, OSLEVEL_SIZE - 1); + if(cfg_sendoslevel) { + strncpy(oslevel, uts.release, OSLEVEL_SIZE - 1); + oslevel [OSLEVEL_SIZE - 1] = 0; } } - } + +- if(cfg_sendidle) { ++ if(cfg_sendidle) { /* ========== idle_time ========== */ + static kvm_t *kp; + static int initialized = 0; + static struct nlist namelist [] = { |