From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ksysguard/ksysguardd/FreeBSD/CPU.c | 263 ++++++++++++++ ksysguard/ksysguardd/FreeBSD/CPU.h | 49 +++ ksysguard/ksysguardd/FreeBSD/Makefile.am | 8 + ksysguard/ksysguardd/FreeBSD/Memory.c | 209 +++++++++++ ksysguard/ksysguardd/FreeBSD/Memory.h | 45 +++ ksysguard/ksysguardd/FreeBSD/ProcessList.c | 556 +++++++++++++++++++++++++++++ ksysguard/ksysguardd/FreeBSD/ProcessList.h | 38 ++ ksysguard/ksysguardd/FreeBSD/apm.c | 102 ++++++ ksysguard/ksysguardd/FreeBSD/apm.h | 34 ++ ksysguard/ksysguardd/FreeBSD/diskstat.c | 256 +++++++++++++ ksysguard/ksysguardd/FreeBSD/diskstat.h | 40 +++ ksysguard/ksysguardd/FreeBSD/loadavg.c | 96 +++++ ksysguard/ksysguardd/FreeBSD/loadavg.h | 36 ++ ksysguard/ksysguardd/FreeBSD/logfile.c | 175 +++++++++ ksysguard/ksysguardd/FreeBSD/logfile.h | 36 ++ ksysguard/ksysguardd/FreeBSD/netdev.c | 353 ++++++++++++++++++ ksysguard/ksysguardd/FreeBSD/netdev.h | 35 ++ 17 files changed, 2331 insertions(+) create mode 100644 ksysguard/ksysguardd/FreeBSD/CPU.c create mode 100644 ksysguard/ksysguardd/FreeBSD/CPU.h create mode 100644 ksysguard/ksysguardd/FreeBSD/Makefile.am create mode 100644 ksysguard/ksysguardd/FreeBSD/Memory.c create mode 100644 ksysguard/ksysguardd/FreeBSD/Memory.h create mode 100644 ksysguard/ksysguardd/FreeBSD/ProcessList.c create mode 100644 ksysguard/ksysguardd/FreeBSD/ProcessList.h create mode 100644 ksysguard/ksysguardd/FreeBSD/apm.c create mode 100644 ksysguard/ksysguardd/FreeBSD/apm.h create mode 100644 ksysguard/ksysguardd/FreeBSD/diskstat.c create mode 100644 ksysguard/ksysguardd/FreeBSD/diskstat.h create mode 100644 ksysguard/ksysguardd/FreeBSD/loadavg.c create mode 100644 ksysguard/ksysguardd/FreeBSD/loadavg.h create mode 100644 ksysguard/ksysguardd/FreeBSD/logfile.c create mode 100644 ksysguard/ksysguardd/FreeBSD/logfile.h create mode 100644 ksysguard/ksysguardd/FreeBSD/netdev.c create mode 100644 ksysguard/ksysguardd/FreeBSD/netdev.h (limited to 'ksysguard/ksysguardd/FreeBSD') diff --git a/ksysguard/ksysguardd/FreeBSD/CPU.c b/ksysguard/ksysguardd/FreeBSD/CPU.c new file mode 100644 index 000000000..90d0c4721 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/CPU.c @@ -0,0 +1,263 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include + +#include +#if defined(__DragonFly__) +#include +#include +#elif __FreeBSD_version < 500101 + #include +#else + #include +#endif +#include + +#include +#include +#include +#include +#include +#include + +#include "CPU.h" +#include "Command.h" +#include "ksysguardd.h" + +#if defined(__DragonFly__) +static void cputime_percentages(int[4], struct kinfo_cputime *, + struct kinfo_cputime *); +static struct kinfo_cputime cp_time, cp_old; + +#define CPUSTATES 4 +#define CP_USER 0 +#define CP_NICE 1 +#define CP_SYS 2 +#define CP_IDLE 3 + +#else +long percentages(int cnt, int *out, long *new, long *old, long *diffs); + +unsigned long cp_time_offset; + +long cp_time[CPUSTATES]; +long cp_old[CPUSTATES]; +long cp_diff[CPUSTATES]; +#endif + +int cpu_states[CPUSTATES]; + +void +initCpuInfo(struct SensorModul* sm) +{ + /* Total CPU load */ + registerMonitor("cpu/user", "integer", printCPUUser, + printCPUUserInfo, sm); + registerMonitor("cpu/nice", "integer", printCPUNice, + printCPUNiceInfo, sm); + registerMonitor("cpu/sys", "integer", printCPUSys, + printCPUSysInfo, sm); + registerMonitor("cpu/idle", "integer", printCPUIdle, + printCPUIdleInfo, sm); + + updateCpuInfo(); +} + +void +exitCpuInfo(void) +{ +} + +int +updateCpuInfo(void) +{ +#if defined(__DragonFly__) + kinfo_get_sched_cputime(&cp_time); + cputime_percentages(cpu_states, &cp_time, &cp_old); +#else + size_t len = sizeof(cp_time); + sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0); + percentages(CPUSTATES, cpu_states, cp_time, cp_old, cp_diff); +#endif + return (0); +} + +void +printCPUUser(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", cpu_states[CP_USER]/10); +} + +void +printCPUUserInfo(const char* cmd) +{ + fprintf(CurrentClient, "CPU User Load\t0\t100\t%%\n"); +} + +void +printCPUNice(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", cpu_states[CP_NICE]/10); +} + +void +printCPUNiceInfo(const char* cmd) +{ + fprintf(CurrentClient, "CPU Nice Load\t0\t100\t%%\n"); +} + +void +printCPUSys(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", cpu_states[CP_SYS]/10); +} + +void +printCPUSysInfo(const char* cmd) +{ + fprintf(CurrentClient, "CPU System Load\t0\t100\t%%\n"); +} + +void +printCPUIdle(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", cpu_states[CP_IDLE]/10); +} + +void +printCPUIdleInfo(const char* cmd) +{ + fprintf(CurrentClient, "CPU Idle Load\t0\t100\t%%\n"); +} + + +/* The part ripped from top... */ +/* + * Top users/processes display for Unix + * Version 3 + * + * This program may be freely redistributed, + * but this entire comment MUST remain intact. + * + * Copyright (c) 1984, 1989, William LeFebvre, Rice University + * Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University + */ + +/* + * percentages(cnt, out, new, old, diffs) - calculate percentage change + * between array "old" and "new", putting the percentages i "out". + * "cnt" is size of each array and "diffs" is used for scratch space. + * The array "old" is updated on each call. + * The routine assumes modulo arithmetic. This function is especially + * useful on BSD mchines for calculating cpu state percentages. + */ +#if defined(__DragonFly__) +static void +cputime_percentages(int out[4], struct kinfo_cputime *new, struct kinfo_cputime * old) +{ + struct kinfo_cputime diffs; + int i; + uint64_t total_change, half_total; + + /* initialization */ + total_change = 0; + + diffs.cp_user = new->cp_user - old->cp_user; + diffs.cp_nice = new->cp_nice - old->cp_nice; + diffs.cp_sys = new->cp_sys - old->cp_sys; + diffs.cp_intr = new->cp_intr - old->cp_intr; + diffs.cp_idle = new->cp_idle - old->cp_idle; + total_change = diffs.cp_user + diffs.cp_nice + diffs.cp_sys + + diffs.cp_intr + diffs.cp_idle; + old->cp_user = new->cp_user; + old->cp_nice = new->cp_nice; + old->cp_sys = new->cp_sys; + old->cp_intr = new->cp_intr; + old->cp_idle = new->cp_idle; + + /* avoid divide by zero potential */ + if (total_change == 0) + total_change = 1; + + /* calculate percentages based on overall change, rounding up */ + half_total = total_change >> 1; + + out[0] = ((diffs.cp_user * 1000LL + half_total) / total_change); + out[1] = ((diffs.cp_nice * 1000LL + half_total) / total_change); + out[2] = (((diffs.cp_sys + diffs.cp_intr) * 1000LL + half_total) / total_change); + out[4] = ((diffs.cp_idle * 1000LL + half_total) / total_change); +} + +#else +long percentages(cnt, out, new, old, diffs) + +int cnt; +int *out; +register long *new; +register long *old; +long *diffs; + +{ + register int i; + register long change; + register long total_change; + register long *dp; + long half_total; + + /* initialization */ + total_change = 0; + dp = diffs; + + /* calculate changes for each state and the overall change */ + for (i = 0; i < cnt; i++) + { + if ((change = *new - *old) < 0) + { + /* this only happens when the counter wraps */ + change = (int) + ((unsigned long)*new-(unsigned long)*old); + } + total_change += (*dp++ = change); + *old++ = *new++; + } + + /* avoid divide by zero potential */ + if (total_change == 0) + { + total_change = 1; + } + + /* calculate percentages based on overall change, rounding up */ + half_total = total_change / 2l; + + /* Do not divide by 0. Causes Floating point exception */ + if(total_change) { + for (i = 0; i < cnt; i++) + { + *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); + } + } + + /* return the total in case the caller wants to use it */ + return(total_change); +} +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/CPU.h b/ksysguard/ksysguardd/FreeBSD/CPU.h new file mode 100644 index 000000000..c35932ac8 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/CPU.h @@ -0,0 +1,49 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _cpuinfo_h_ +#define _cpuinfo_h_ + +struct SensorModul; + +void initCpuInfo(struct SensorModul* sm); +void exitCpuInfo(void); + +int updateCpuInfo(void); + +void printCPUUser(const char* cmd); +void printCPUUserInfo(const char* cmd); +void printCPUNice(const char* cmd); +void printCPUNiceInfo(const char* cmd); +void printCPUSys(const char* cmd); +void printCPUSysInfo(const char* cmd); +void printCPUIdle(const char* cmd); +void printCPUIdleInfo(const char* cmd); +void printCPUxUser(const char* cmd); +void printCPUxUserInfo(const char* cmd); +void printCPUxNice(const char* cmd); +void printCPUxNiceInfo(const char* cmd); +void printCPUxSys(const char* cmd); +void printCPUxSysInfo(const char* cmd); +void printCPUxIdle(const char* cmd); +void printCPUxIdleInfo(const char* cmd); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/Makefile.am b/ksysguard/ksysguardd/FreeBSD/Makefile.am new file mode 100644 index 000000000..29860a407 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/Makefile.am @@ -0,0 +1,8 @@ +# +# + +INCLUDES = -I$(srcdir)/../../CContLib -I$(srcdir)/.. + +noinst_LIBRARIES = libksysguardd.a +libksysguardd_a_SOURCES = CPU.c Memory.c ProcessList.c apm.c diskstat.c \ + loadavg.c logfile.c netdev.c diff --git a/ksysguard/ksysguardd/FreeBSD/Memory.c b/ksysguard/ksysguardd/FreeBSD/Memory.c new file mode 100644 index 000000000..9e3db646c --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/Memory.c @@ -0,0 +1,209 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999-2000 Hans Petter Bieker + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "Command.h" +#include "Memory.h" +#include "ksysguardd.h" + +static size_t Total = 0; +static size_t MFree = 0; +static size_t Used = 0; +static size_t Buffers = 0; +static size_t Cached = 0; +static size_t Application = 0; +static size_t STotal = 0; +static size_t SFree = 0; +static size_t SUsed = 0; +static kvm_t *kd; + +void +initMemory(struct SensorModul* sm) +{ + char *nlistf = NULL; + char *memf = NULL; + char buf[_POSIX2_LINE_MAX]; + + if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) { + log_error("kvm_openfiles()"); + return; + } + + registerMonitor("mem/physical/free", "integer", printMFree, printMFreeInfo, sm); + registerMonitor("mem/physical/used", "integer", printUsed, printUsedInfo, sm); + registerMonitor("mem/physical/buf", "integer", printBuffers, printBuffersInfo, sm); + registerMonitor("mem/physical/cached", "integer", printCached, printCachedInfo, sm); + registerMonitor("mem/physical/application", "integer", printApplication, printApplicationInfo, sm); + registerMonitor("mem/swap/free", "integer", printSwapFree, printSwapFreeInfo, sm); + registerMonitor("mem/swap/used", "integer", printSwapUsed, printSwapUsedInfo, sm); +} + +void +exitMemory(void) +{ + kvm_close(kd); +} + +int +updateMemory(void) +{ + size_t len; + FILE *file; + char buf[256]; + struct kvm_swap kswap[16]; + int i, swap_count, hlen, pagesize = getpagesize(); + long blocksize; + + len = sizeof (Total); + sysctlbyname("hw.physmem", &Total, &len, NULL, 0); + Total /= 1024; + + /* Borrowed from pstat */ + swap_count = kvm_getswapinfo(kd, kswap, 16, SWIF_DEV_PREFIX); + getbsize(&hlen, &blocksize); + +#define CONVERT(v) ((int)((quad_t)(v) * pagesize / blocksize)) + + if (swap_count > 0) { + STotal = CONVERT(kswap[0].ksw_total); + SUsed = CONVERT(kswap[0].ksw_used); + SFree = CONVERT(kswap[0].ksw_total - kswap[0].ksw_used); + } + + len = sizeof (Buffers); + if ((sysctlbyname("vfs.bufspace", &Buffers, &len, NULL, 0) == -1) || !len) + Buffers = 0; /* Doesn't work under FreeBSD v2.2.x */ + Buffers /= 1024; + + len = sizeof (Cached); + if ((sysctlbyname("vm.stats.vm.v_cache_count", &Cached, &len, NULL, 0) == -1) || !len) + Cached = 0; /* Doesn't work under FreeBSD v2.2.x */ + Cached *= pagesize / 1024; + + len = sizeof (MFree); + if ((sysctlbyname("vm.stats.vm.v_free_count", &MFree, &len, NULL, 0) == -1) || !len) + MFree = 0; /* Doesn't work under FreeBSD v2.2.x */ + MFree *= pagesize / 1024; + + Used = Total - MFree; + Application = Used - Buffers - Cached; + + return 0; +} + +void +printMFree(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", MFree); +} + +void +printMFreeInfo(const char* cmd) +{ + fprintf(CurrentClient, "Free Memory\t0\t%d\tKB\n", Total); +} + +void +printUsed(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Used); +} + +void +printUsedInfo(const char* cmd) +{ + fprintf(CurrentClient, "Used Memory\t0\t%d\tKB\n", Total); +} + +void +printBuffers(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Buffers); +} + +void +printBuffersInfo(const char* cmd) +{ + fprintf(CurrentClient, "Buffer Memory\t0\t%d\tKB\n", Total); +} + +void +printCached(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Cached); +} + +void +printCachedInfo(const char* cmd) +{ + fprintf(CurrentClient, "Cached Memory\t0\t%d\tKB\n", Total); +} + +void +printApplication(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", Application); +} + +void +printApplicationInfo(const char* cmd) +{ + fprintf(CurrentClient, "Application Memory\t0\t%ld\tKB\n", Total); +} + +void +printSwapUsed(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", SUsed); +} + +void +printSwapUsedInfo(const char* cmd) +{ + fprintf(CurrentClient, "Used Swap Memory\t0\t%d\tKB\n", STotal); +} + +void +printSwapFree(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", SFree); +} + +void +printSwapFreeInfo(const char* cmd) +{ + fprintf(CurrentClient, "Free Swap Memory\t0\t%d\tKB\n", STotal); +} diff --git a/ksysguard/ksysguardd/FreeBSD/Memory.h b/ksysguard/ksysguardd/FreeBSD/Memory.h new file mode 100644 index 000000000..66b521617 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/Memory.h @@ -0,0 +1,45 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _memory_h_ +#define _memory_h_ + +void initMemory(struct SensorModul* sm); +void exitMemory(void); + +int updateMemory(void); + +void printMFree(const char* cmd); +void printMFreeInfo(const char* cmd); +void printUsed(const char* cmd); +void printUsedInfo(const char* cmd); +void printBuffers(const char* cmd); +void printBuffersInfo(const char* cmd); +void printCached(const char* cmd); +void printCachedInfo(const char* cmd); +void printApplication(const char* cmd); +void printApplicationInfo(const char* cmd); +void printSwapUsed(const char* cmd); +void printSwapUsedInfo(const char* cmd); +void printSwapFree(const char* cmd); +void printSwapFreeInfo(const char* cmd); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/ProcessList.c b/ksysguard/ksysguardd/FreeBSD/ProcessList.c new file mode 100644 index 000000000..f8d2c3ba6 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/ProcessList.c @@ -0,0 +1,556 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999-2000 Hans Petter Bieker + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#if defined(__DragonFly__) +#include +#include +#endif + +#if __FreeBSD_version > 500015 +#include +#endif +#include +#include +#include +#include +#include +#include + +#include "../../gui/SignalIDs.h" +#include "Command.h" +#include "ProcessList.h" +#include "ccont.h" +#include "ksysguardd.h" + +CONTAINER ProcessList = 0; + +int fscale; + +#define BUFSIZE 1024 + +typedef struct +{ + /* This flag is set for all found processes at the beginning of the + * process list update. Processes that do not have this flag set will + * be assumed dead and removed from the list. The flag is cleared after + * each list update. */ + int alive; + + /* the process ID */ + pid_t pid; + + /* the parent process ID */ + pid_t ppid; + + /* the real user ID */ + uid_t uid; + + /* the real group ID */ + gid_t gid; + + /* a character description of the process status */ + char status[16]; + + /* the number of the tty the process owns */ + int ttyNo; + + /* + * The nice level. The range should be -20 to 20. I'm not sure + * whether this is true for all platforms. + */ + int niceLevel; + + /* + * The scheduling priority. + */ + int priority; + + /* + * The total amount of memory the process uses. This includes shared and + * swapped memory. + */ + unsigned int vmSize; + + /* + * The amount of physical memory the process currently uses. + */ + unsigned int vmRss; + + /* + * The amount of memory (shared/swapped/etc) the process shares with + * other processes. + */ + unsigned int vmLib; + + /* + * The number of 1/100 of a second the process has spend in user space. + * If a machine has an uptime of 1 1/2 years or longer this is not a + * good idea. I never thought that the stability of UNIX could get me + * into trouble! ;) + */ +#if !defined(__DragonFly__) + unsigned int userTime; +#else + long userTime; +#endif + + /* + * The number of 1/100 of a second the process has spend in system space. + * If a machine has an uptime of 1 1/2 years or longer this is not a + * good idea. I never thought that the stability of UNIX could get me + * into trouble! ;) + */ + unsigned int sysTime; + + /* system time as multime of 100ms */ + int centStamp; + + /* the current CPU load (in %) from user space */ + double userLoad; + + /* the current CPU load (in %) from system space */ + double sysLoad; + + /* the name of the process */ + char name[64]; + + /* the command used to start the process */ + char cmdline[256]; + + /* the login name of the user that owns this process */ + char userName[32]; +} ProcessInfo; + +static unsigned ProcessCount; + +static int +processCmp(void* p1, void* p2) +{ + return (((ProcessInfo*) p1)->pid - ((ProcessInfo*) p2)->pid); +} + +static ProcessInfo* +findProcessInList(int pid) +{ + ProcessInfo key; + long index; + + key.pid = pid; + if ((index = search_ctnr(ProcessList, processCmp, &key)) < 0) + return (0); + + return (get_ctnr(ProcessList, index)); +} + +static int +updateProcess(int pid) +{ + static char *statuses[] = { "idle","run","sleep","stop","zombie" }; + + ProcessInfo* ps; + struct passwd* pwent; + int mib[4]; + struct kinfo_proc p; + struct rusage pru; + size_t len; + size_t buflen = 256; + char buf[256]; + + if ((ps = findProcessInList(pid)) == 0) + { + ps = (ProcessInfo*) malloc(sizeof(ProcessInfo)); + ps->pid = pid; + ps->centStamp = 0; + push_ctnr(ProcessList, ps); + bsort_ctnr(ProcessList, processCmp); + } + + ps->alive = 1; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PID; + mib[3] = pid; + + len = sizeof (p); + if (sysctl(mib, 4, &p, &len, NULL, 0) == -1 || !len) + return -1; + +#if __FreeBSD_version >= 500015 + ps->pid = p.ki_pid; + ps->ppid = p.ki_ppid; + ps->uid = p.ki_uid; + ps->gid = p.ki_pgid; + ps->priority = p.ki_pri.pri_user; + ps->niceLevel = p.ki_nice; +#elif defined(__DragonFly__) && __DragonFly_version >= 190000 + ps->pid = p.kp_pid; + ps->ppid = p.kp_ppid; + ps->uid = p.kp_uid; + ps->gid = p.kp_pgid; + ps->priority = p.kp_lwp.kl_tdprio; +#else + ps->pid = p.kp_proc.p_pid; + ps->ppid = p.kp_eproc.e_ppid; + ps->uid = p.kp_eproc.e_ucred.cr_uid; + ps->gid = p.kp_eproc.e_pgid; +#if defined(__DragonFly__) + ps->priority = p.kp_thread.td_pri; +#else + ps->priority = p.kp_proc.p_priority; +#endif + ps->niceLevel = p.kp_proc.p_nice; +#endif + + /* this isn't usertime -- it's total time (??) */ +#if __FreeBSD_version >= 500015 + ps->userTime = p.ki_runtime / 10000; +#elif defined(__DragonFly__) +#if __DragonFly_version >= 190000 + if (!getrusage(p.kp_pid, &pru)) +#else + if (!getrusage(p.kp_proc.p_pid, &pru)) +#endif + { + errx(1, "failed to get rusage info"); + } + ps->userTime = pru.ru_utime.tv_usec / 1000; /*p_runtime / 1000*/ +#elif __FreeBSD_version >= 300000 + ps->userTime = p.kp_proc.p_runtime / 10000; +#else + ps->userTime = p.kp_proc.p_rtime.tv_sec*100+p.kp_proc.p_rtime.tv_usec/100; +#endif + ps->sysTime = 0; + ps->sysLoad = 0; + + /* memory, process name, process uid */ + /* find out user name with process uid */ + pwent = getpwuid(ps->uid); + strncpy(ps->userName,pwent&&pwent->pw_name? pwent->pw_name:"????",sizeof(ps->userName)); + ps->userName[sizeof(ps->userName)-1]='\0'; + + if (fscale == 0) + ps->userLoad = 0; + else +#if __FreeBSD_version >= 500015 + ps->userLoad = 100.0 * (double) p.ki_pctcpu / fscale; + ps->vmSize = p.ki_size; + ps->vmRss = p.ki_rssize * getpagesize(); + strlcpy(ps->name,p.ki_comm? p.ki_comm:"????",sizeof(ps->name)); + strcpy(ps->status,(p.ki_stat>=1)&&(p.ki_stat<=5)? statuses[p.ki_stat-1]:"????"); +#elif defined (__DragonFly__) && __DragonFly_version >= 190000 + ps->userLoad = 100.0 * (double) p.kp_lwp.kl_pctcpu / fscale; + ps->vmSize = p.kp_vm_map_size; + ps->vmRss = p.kp_vm_rssize * getpagesize(); + strlcpy(ps->name,p.kp_comm ? p.kp_comm : "????", + sizeof(ps->name)); + strcpy(ps->status,(p.kp_stat>=1)&&(p.kp_stat<=5)? statuses[p.kp_stat-1]:"????"); +#else + ps->userLoad = 100.0 * (double) p.kp_proc.p_pctcpu / fscale; + ps->vmSize = p.kp_eproc.e_vm.vm_map.size; + ps->vmRss = p.kp_eproc.e_vm.vm_rssize * getpagesize(); +#if defined (__DragonFly__) + strlcpy(ps->name,p.kp_thread.td_comm ? p.kp_thread.td_comm : "????", + sizeof(ps->name)); +#else + strlcpy(ps->name,p.kp_proc.p_comm ? p.kp_proc.p_comm : "????", sizeof(ps->name)); + strcpy(ps->status,(p.kp_proc.p_stat>=1)&&(p.kp_proc.p_stat<=5)? statuses[p.kp_proc.p_stat-1]:"????"); +#endif +#endif + + /* process command line */ + /* do a sysctl to get the command line args. */ + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ARGS; + mib[3] = pid; + + if ((sysctl(mib, 4, buf, &buflen, 0, 0) == -1) || !buflen) + strcpy(ps->cmdline, "????"); + else + strncpy(ps->cmdline, buf, buflen); + + return (0); +} + +static void +cleanupProcessList(void) +{ + ProcessInfo* ps; + + ProcessCount = 0; + /* All processes that do not have the active flag set are assumed dead + * and will be removed from the list. The alive flag is cleared. */ + for (ps = first_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) + { + if (ps->alive) + { + /* Process is still alive. Just clear flag. */ + ps->alive = 0; + ProcessCount++; + } + else + { + /* Process has probably died. We remove it from the list and + * destruct the data structure. i needs to be decremented so + * that after i++ the next list element will be inspected. */ + free(remove_ctnr(ProcessList)); + } + } +} + +/* +================================ public part ================================== +*/ + +void +initProcessList(struct SensorModul* sm) +{ + size_t fscalelen; + ProcessList = new_ctnr(); + + registerMonitor("ps", "table", printProcessList, printProcessListInfo, sm); + registerMonitor("pscount", "integer", printProcessCount, printProcessCountInfo, sm); + + if (!RunAsDaemon) + { + registerCommand("kill", killProcess); + registerCommand("setpriority", setPriority); + } + + fscalelen = sizeof(fscale); + if (sysctlbyname("kern.fscale", &fscale, &fscalelen, NULL, 0) == -1) + fscale = 0; + + updateProcessList(); +} + +void +exitProcessList(void) +{ + removeMonitor("ps"); + removeMonitor("pscount"); + + if (ProcessList) + free (ProcessList); +} + +int +updateProcessList(void) +{ + int mib[3]; + size_t len; + size_t num; + struct kinfo_proc *p; + + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ALL; + sysctl(mib, 3, NULL, &len, NULL, 0); + p = malloc(len); + sysctl(mib, 3, p, &len, NULL, 0); + + for (num = 0; num < len / sizeof(struct kinfo_proc); num++) +#if __FreeBSD_version >= 500015 + updateProcess(p[num].ki_pid); +#elif __DragonFly_version >= 190000 + /* Skip kernel threads with pid -1. Swapper with pid 0 also + * causing problems is skipped in printProcessList() as 'kernel' + * entry. */ + if (p[num].kp_pid >= 0) + updateProcess(p[num].kp_pid); +#elif defined(__DragonFly__) + if (p[num].kp_proc.p_pid >= 0) + updateProcess(p[num].kp_proc.p_pid); +#else + updateProcess(p[num].kp_proc.p_pid); +#endif + free(p); + cleanupProcessList(); + + return (0); +} + +void +printProcessListInfo(const char* cmd) +{ + fprintf(CurrentClient, "Name\tPID\tPPID\tUID\tGID\tStatus\tUser%%\tSystem%%\tNice\tVmSize\tVmRss\tLogin\tCommand\n"); + fprintf(CurrentClient, "s\td\td\td\td\tS\tf\tf\td\tD\tD\ts\ts\n"); +} + +void +printProcessList(const char* cmd) +{ + ProcessInfo* ps; + + ps = first_ctnr(ProcessList); /* skip 'kernel' entry */ + for (ps = next_ctnr(ProcessList); ps; ps = next_ctnr(ProcessList)) + { + fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%ld\t%s\t%.2f\t%.2f\t%d\t%d\t%d\t%s\t%s\n", + ps->name, (long)ps->pid, (long)ps->ppid, + (long)ps->uid, (long)ps->gid, ps->status, + ps->userLoad, ps->sysLoad, ps->niceLevel, + ps->vmSize / 1024, ps->vmRss / 1024, ps->userName, ps->cmdline); + } +} + +void +printProcessCount(const char* cmd) +{ + fprintf(CurrentClient, "%d\n", ProcessCount); +} + +void +printProcessCountInfo(const char* cmd) +{ + fprintf(CurrentClient, "Number of Processes\t1\t65535\t\n"); +} + +void +killProcess(const char* cmd) +{ + int sig, pid; + + sscanf(cmd, "%*s %d %d", &pid, &sig); + switch(sig) + { + case MENU_ID_SIGABRT: + sig = SIGABRT; + break; + case MENU_ID_SIGALRM: + sig = SIGALRM; + break; + case MENU_ID_SIGCHLD: + sig = SIGCHLD; + break; + case MENU_ID_SIGCONT: + sig = SIGCONT; + break; + case MENU_ID_SIGFPE: + sig = SIGFPE; + break; + case MENU_ID_SIGHUP: + sig = SIGHUP; + break; + case MENU_ID_SIGILL: + sig = SIGILL; + break; + case MENU_ID_SIGINT: + sig = SIGINT; + break; + case MENU_ID_SIGKILL: + sig = SIGKILL; + break; + case MENU_ID_SIGPIPE: + sig = SIGPIPE; + break; + case MENU_ID_SIGQUIT: + sig = SIGQUIT; + break; + case MENU_ID_SIGSEGV: + sig = SIGSEGV; + break; + case MENU_ID_SIGSTOP: + sig = SIGSTOP; + break; + case MENU_ID_SIGTERM: + sig = SIGTERM; + break; + case MENU_ID_SIGTSTP: + sig = SIGTSTP; + break; + case MENU_ID_SIGTTIN: + sig = SIGTTIN; + break; + case MENU_ID_SIGTTOU: + sig = SIGTTOU; + break; + case MENU_ID_SIGUSR1: + sig = SIGUSR1; + break; + case MENU_ID_SIGUSR2: + sig = SIGUSR2; + break; + } + if (kill((pid_t) pid, sig)) + { + switch(errno) + { + case EINVAL: + fprintf(CurrentClient, "4\t%d\n", pid); + break; + case ESRCH: + fprintf(CurrentClient, "3\t%d\n", pid); + break; + case EPERM: + fprintf(CurrentClient, "2\t%d\n", pid); + break; + default: + fprintf(CurrentClient, "1\t%d\n", pid); /* unknown error */ + break; + } + + } + else + fprintf(CurrentClient, "0\t%d\n", pid); +} + +void +setPriority(const char* cmd) +{ + int pid, prio; + + sscanf(cmd, "%*s %d %d", &pid, &prio); + if (setpriority(PRIO_PROCESS, pid, prio)) + { + switch(errno) + { + case EINVAL: + fprintf(CurrentClient, "4\n"); + break; + case ESRCH: + fprintf(CurrentClient, "3\n"); + break; + case EPERM: + case EACCES: + fprintf(CurrentClient, "2\n"); + break; + default: + fprintf(CurrentClient, "1\n"); /* unknown error */ + break; + } + } + else + fprintf(CurrentClient, "0\n"); +} diff --git a/ksysguard/ksysguardd/FreeBSD/ProcessList.h b/ksysguard/ksysguardd/FreeBSD/ProcessList.h new file mode 100644 index 000000000..925c55f5a --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/ProcessList.h @@ -0,0 +1,38 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 Chris Schlaeger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _process_list_h_ +#define _process_list_h_ + +void initProcessList(struct SensorModul* sm); +void exitProcessList(void); + +int updateProcessList(void); + +void printProcessList(const char*); +void printProcessListInfo(const char*); +void printProcessCount(const char* cmd); +void printProcessCountInfo(const char* cmd); + +void killProcess(const char* cmd); +void setPriority(const char* cmd); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/apm.c b/ksysguard/ksysguardd/FreeBSD/apm.c new file mode 100644 index 000000000..95efec792 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/apm.c @@ -0,0 +1,102 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifdef __i386__ + +#include +#include +#include +#include + +#include "Command.h" +#include "apm.h" +#include "ksysguardd.h" + +static int ApmFD, BattFill, BattTime; + +#define APMDEV "/dev/apm" + +/* +================================ public part ================================= +*/ + +void +initApm(struct SensorModul* sm) +{ + if ((ApmFD = open(APMDEV, O_RDONLY)) < 0) + return; + + if (updateApm() < 0) + return; + + registerMonitor("apm/batterycharge", "integer", printApmBatFill, + printApmBatFillInfo, sm); + registerMonitor("apm/remainingtime", "integer", printApmBatTime, + printApmBatTimeInfo, sm); +} + +void +exitApm(void) +{ + removeMonitor("apm/batterycharge"); + removeMonitor("apm/remainingtime"); + + close(ApmFD); +} + +int +updateApm(void) +{ + struct apm_info info; + int retval; + + retval = ioctl(ApmFD, APMIO_GETINFO, &info); + + BattFill = info.ai_batt_life; + BattTime = info.ai_batt_time; + + return retval; +} + +void +printApmBatFill(const char* c) +{ + fprintf(CurrentClient, "%d\n", BattFill); +} + +void +printApmBatFillInfo(const char* c) +{ + fprintf(CurrentClient, "Battery charge\t0\t100\t%%\n"); +} + +void +printApmBatTime(const char* c) +{ + fprintf(CurrentClient, "%d\n", BattTime); +} + +void +printApmBatTimeInfo(const char* c) +{ + fprintf(CurrentClient, "Remaining battery time\t0\t0\tmin\n"); +} + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/apm.h b/ksysguard/ksysguardd/FreeBSD/apm.h new file mode 100644 index 000000000..4e3c0c0d3 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/apm.h @@ -0,0 +1,34 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _apm_h_ +#define _apm_h_ + +void initApm(struct SensorModul* sm); +void exitApm(void); + +int updateApm(void); + +void printApmBatFill(const char*); +void printApmBatFillInfo(const char*); +void printApmBatTime(const char*); +void printApmBatTimeInfo(const char*); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/diskstat.c b/ksysguard/ksysguardd/FreeBSD/diskstat.c new file mode 100644 index 000000000..04f64a706 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/diskstat.c @@ -0,0 +1,256 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Command.h" +#include "ccont.h" +#include "diskstat.h" +#include "ksysguardd.h" + +typedef struct { + char device[256]; + char mntpnt[256]; + long blocks; + long bfree; + long bused; + int bused_percent; +} DiskInfo; + +static CONTAINER DiskStatList = 0; +static struct SensorModul* DiskStatSM; + +char *getMntPnt(const char *cmd) +{ + static char device[1025]; + char *ptr; + + memset(device, 0, sizeof(device)); + sscanf(cmd, "partitions%1024s", device); + + ptr = (char *)rindex(device, '/'); + *ptr = '\0'; + + return (char *)device; +} + +int numMntPnt(void) +{ + struct statfs *fs_info; + int i, n, counter = 0; + + n = getmntinfo(&fs_info, MNT_WAIT); + for (i = 0; i < n; i++) + if (strcmp(fs_info[i].f_fstypename, "procfs") && strcmp(fs_info[i].f_fstypename, "swap") && strcmp(fs_info[i].f_fstypename, "devfs")) + counter++; + + return counter; +} + +/* ------------------------------ public part --------------------------- */ + +void initDiskStat(struct SensorModul* sm) +{ + char monitor[1024]; + DiskInfo* disk_info; + + DiskStatList = new_ctnr(); + DiskStatSM = sm; + + updateDiskStat(); + + registerMonitor("partitions/list", "listview", printDiskStat, printDiskStatInfo, DiskStatSM); + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + snprintf(monitor, sizeof(monitor), "partitions%s/usedspace", disk_info->mntpnt); + registerMonitor(monitor, "integer", printDiskStatUsed, printDiskStatUsedInfo, DiskStatSM); + snprintf(monitor, sizeof(monitor), "partitions%s/freespace", disk_info->mntpnt); + registerMonitor(monitor, "integer", printDiskStatFree, printDiskStatFreeInfo, DiskStatSM); + snprintf(monitor, sizeof(monitor), "partitions%s/filllevel", disk_info->mntpnt); + registerMonitor(monitor, "integer", printDiskStatPercent, printDiskStatPercentInfo, DiskStatSM); + } +} + +void checkDiskStat(void) +{ + if (numMntPnt() != level_ctnr(DiskStatList)) { + /* a filesystem was mounted or unmounted + so we do a reset */ + exitDiskStat(); + initDiskStat(DiskStatSM); + } +} + +void exitDiskStat(void) +{ + DiskInfo *disk_info; + char monitor[1024]; + + removeMonitor("partitions/list"); + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + snprintf(monitor, sizeof(monitor), "partitions%s/usedspace", disk_info->mntpnt); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "partitions%s/freespace", disk_info->mntpnt); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "partitions%s/filllevel", disk_info->mntpnt); + removeMonitor(monitor); + } + + destr_ctnr(DiskStatList, free); +} + +int updateDiskStat(void) +{ + struct statfs *fs_info; + struct statfs fs; + float percent; + int i, mntcount; + DiskInfo *disk_info; + + /* let's hope there is no difference between the DiskStatList and + the number of mounted filesystems */ + for (i = level_ctnr(DiskStatList); i >= 0; --i) + free(pop_ctnr(DiskStatList)); + + mntcount = getmntinfo(&fs_info, MNT_WAIT); + + for (i = 0; i < mntcount; i++) { + fs = fs_info[i]; + if (strcmp(fs.f_fstypename, "procfs") && strcmp(fs.f_fstypename, "devfs") && strcmp(fs.f_fstypename, "devfs")) { + + if ( fs.f_blocks != 0 ) + { + percent = (((float)fs.f_blocks - (float)fs.f_bfree)/(float)fs.f_blocks); + percent = percent * 100; + } + else + percent = 0; + + if ((disk_info = (DiskInfo *)malloc(sizeof(DiskInfo))) == NULL) { + continue; + } + memset(disk_info, 0, sizeof(DiskInfo)); + strlcpy(disk_info->device, fs.f_mntfromname, sizeof(disk_info->device)); + if (!strcmp(fs.f_mntonname, "/")) { + strncpy(disk_info->mntpnt, "/root", 6); + } else { + strlcpy(disk_info->mntpnt, fs.f_mntonname, sizeof(disk_info->mntpnt)); + } + disk_info->blocks = fs.f_blocks; + disk_info->bfree = fs.f_bfree; + disk_info->bused = (fs.f_blocks - fs.f_bfree); + disk_info->bused_percent = (int)percent; + + push_ctnr(DiskStatList, disk_info); + } + } + + return 0; +} + +void printDiskStat(const char* cmd) +{ + DiskInfo* disk_info; + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + fprintf(CurrentClient, "%s\t%ld\t%ld\t%ld\t%d\t%s\n", + disk_info->device, + disk_info->blocks, + disk_info->bused, + disk_info->bfree, + disk_info->bused_percent, + disk_info->mntpnt); + } + + fprintf(CurrentClient, "\n"); +} + +void printDiskStatInfo(const char* cmd) +{ + fprintf(CurrentClient, "Device\tBlocks\tUsed\tAvailable\tUsed %%\tMountPoint\nM\tD\tD\tD\td\ts\n"); +} + +void printDiskStatUsed(const char* cmd) +{ + DiskInfo* disk_info; + char *mntpnt = (char *)getMntPnt(cmd); + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + if (!strcmp(mntpnt, disk_info->mntpnt)) { + fprintf(CurrentClient, "%ld\n", disk_info->bused); + } + } + + fprintf(CurrentClient, "\n"); +} + +void printDiskStatUsedInfo(const char* cmd) +{ + fprintf(CurrentClient, "Used Blocks\t0\t-\tBlocks\n"); +} + +void printDiskStatFree(const char* cmd) +{ + DiskInfo* disk_info; + char *mntpnt = (char *)getMntPnt(cmd); + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + if (!strcmp(mntpnt, disk_info->mntpnt)) { + fprintf(CurrentClient, "%ld\n", disk_info->bfree); + } + } + + fprintf(CurrentClient, "\n"); +} + +void printDiskStatFreeInfo(const char* cmd) +{ + fprintf(CurrentClient, "Free Blocks\t0\t-\tBlocks\n"); +} + +void printDiskStatPercent(const char* cmd) +{ + DiskInfo* disk_info; + char *mntpnt = (char *)getMntPnt(cmd); + + for (disk_info = first_ctnr(DiskStatList); disk_info; disk_info = next_ctnr(DiskStatList)) { + if (!strcmp(mntpnt, disk_info->mntpnt)) { + fprintf(CurrentClient, "%d\n", disk_info->bused_percent); + } + } + + fprintf(CurrentClient, "\n"); +} + +void printDiskStatPercentInfo(const char* cmd) +{ + fprintf(CurrentClient, "Used Blocks\t0\t100\t%%\n"); +} diff --git a/ksysguard/ksysguardd/FreeBSD/diskstat.h b/ksysguard/ksysguardd/FreeBSD/diskstat.h new file mode 100644 index 000000000..06f247837 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/diskstat.h @@ -0,0 +1,40 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _diskstat_h_ +#define _diskstat_h_ + +void initDiskStat(struct SensorModul* sm); +void exitDiskStat(void); + +int updateDiskStat(void); +void checkDiskStat(void); + +void printDiskStat(const char* cmd); +void printDiskStatInfo(const char* cmd); + +void printDiskStatUsed(const char* cmd); +void printDiskStatUsedInfo(const char* cmd); +void printDiskStatFree(const char* cmd); +void printDiskStatFreeInfo(const char* cmd); +void printDiskStatPercent(const char* cmd); +void printDiskStatPercentInfo(const char* cmd); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/loadavg.c b/ksysguard/ksysguardd/FreeBSD/loadavg.c new file mode 100644 index 000000000..53eb9fc4e --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/loadavg.c @@ -0,0 +1,96 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include +#include + +#include "Command.h" +#include "ksysguardd.h" +#include "loadavg.h" + +static double LoadAvg[3]; + +/* +================================ public part ================================= +*/ + +void +initLoadAvg(struct SensorModul* sm) +{ + if (updateLoadAvg() < 0) + return; + + registerMonitor("cpu/loadavg1", "float", printLoadAvg1, + printLoadAvg1Info, sm); + registerMonitor("cpu/loadavg5", "float", printLoadAvg5, + printLoadAvg5Info, sm); + registerMonitor("cpu/loadavg15", "float", printLoadAvg15, + printLoadAvg15Info, sm); +} + +void +exitLoadAvg(void) +{ + removeMonitor("cpu/loadavg1"); + removeMonitor("cpu/loadavg5"); + removeMonitor("cpu/loadavg15"); +} + +int +updateLoadAvg(void) +{ + return getloadavg(LoadAvg, 3); +} + +void +printLoadAvg1(const char* c) +{ + fprintf(CurrentClient, "%f\n", LoadAvg[0]); +} + +void +printLoadAvg1Info(const char* c) +{ + fprintf(CurrentClient, "Load average 1 min\t0\t0\t\n"); +} + +void +printLoadAvg5(const char* c) +{ + fprintf(CurrentClient, "%f\n", LoadAvg[1]); +} + +void +printLoadAvg5Info(const char* c) +{ + fprintf(CurrentClient, "Load average 5 min\t0\t0\t\n"); +} + +void +printLoadAvg15(const char* c) +{ + fprintf(CurrentClient, "%f\n", LoadAvg[2]); +} + +void +printLoadAvg15Info(const char* c) +{ + fprintf(CurrentClient, "Load average 15 min\t0\t0\t\n"); +} diff --git a/ksysguard/ksysguardd/FreeBSD/loadavg.h b/ksysguard/ksysguardd/FreeBSD/loadavg.h new file mode 100644 index 000000000..801e4ef8d --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/loadavg.h @@ -0,0 +1,36 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _loadavg_h_ +#define _loadavg_h_ + +void initLoadAvg(struct SensorModul* sm); +void exitLoadAvg(void); + +int updateLoadAvg(void); + +void printLoadAvg1(const char*); +void printLoadAvg1Info(const char*); +void printLoadAvg5(const char*); +void printLoadAvg5Info(const char*); +void printLoadAvg15(const char*); +void printLoadAvg15Info(const char*); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/logfile.c b/ksysguard/ksysguardd/FreeBSD/logfile.c new file mode 100644 index 000000000..3b07ad8ac --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/logfile.c @@ -0,0 +1,175 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include + +#include +#include +#include + +#include "Command.h" +#include "ccont.h" +#include "conf.h" +#include "ksysguardd.h" +#include "logfile.h" + +static CONTAINER LogFiles = 0; +static unsigned long counter = 1; + +typedef struct { + char name[256]; + FILE* fh; + unsigned long id; +} LogFileEntry; + +extern CONTAINER LogFileList; + +/* +================================ public part ================================= +*/ + +void initLogFile(struct SensorModul* sm) +{ + char monitor[1024]; + ConfigLogFile *entry; + + registerCommand("logfile_register", registerLogFile); + registerCommand("logfile_unregister", unregisterLogFile); + registerCommand("logfile_registered", printRegistered); + + for (entry = first_ctnr(LogFileList); entry; entry = next_ctnr(LogFileList)) + { + FILE* fp; + + /* register the log file if we can actually read the file. */ + if ((fp = fopen(entry->path, "r")) != NULL) + { + fclose(fp); + snprintf(monitor, 1024, "logfiles/%s", entry->name); + registerMonitor(monitor, "logfile", printLogFile, + printLogFileInfo, sm); + } + } + + LogFiles = new_ctnr(); +} + +void exitLogFile(void) +{ + destr_ctnr(LogFiles, free); +} + +void printLogFile(const char* cmd) +{ + char line[1024]; + unsigned long id; + int i; + char ch; + LogFileEntry *entry; + + sscanf(cmd, "%*s %lu", &id); + + for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles)) { + if (entry->id == id) { + while (fgets(line, sizeof(line), entry->fh) != NULL) { + fprintf(CurrentClient, "%s", line); + } + clearerr(entry->fh); + } + } + + fprintf(CurrentClient, "\n"); +} + +void printLogFileInfo(const char* cmd) +{ + fprintf(CurrentClient, "LogFile\n"); +} + +void registerLogFile(const char* cmd) +{ + char name[257]; + FILE* file; + LogFileEntry *entry; + ConfigLogFile *conf; + + memset(name, 0, sizeof(name)); + sscanf(cmd, "%*s %256s", name); + + for (conf = first_ctnr(LogFileList); conf; conf = next_ctnr(LogFileList)) { + if (!strcmp(conf->name, name)) { + if ((file = fopen(conf->path, "r")) == NULL) { + print_error("fopen()"); + fprintf(CurrentClient, "0\n"); + return; + } + + fseek(file, 0, SEEK_END); + + if ((entry = (LogFileEntry *)malloc(sizeof(LogFileEntry))) == NULL) { + print_error("malloc()"); + fprintf(CurrentClient, "0\n"); + return; + } + + entry->fh = file; + strlcpy(entry->name, conf->name, sizeof(entry->name)); + entry->id = counter; + + push_ctnr(LogFiles, entry); + + fprintf(CurrentClient, "%lu\n", counter); + counter++; + + return; + } + } + + fprintf(CurrentClient, "0\n"); +} + +void unregisterLogFile(const char* cmd) +{ + unsigned long id; + LogFileEntry *entry; + + sscanf(cmd, "%*s %lu", &id); + + for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles)) { + if (entry->id == id) { + fclose(entry->fh); + free(remove_ctnr(LogFiles)); + fprintf(CurrentClient, "\n"); + return; + } + } + + fprintf(CurrentClient, "\n"); +} + +void printRegistered(const char* cmd) +{ + LogFileEntry *entry; + + for (entry = first_ctnr(LogFiles); entry; entry = next_ctnr(LogFiles)) + fprintf(CurrentClient, "%s:%lu\n", entry->name, entry->id); + + fprintf(CurrentClient, "\n"); +} diff --git a/ksysguard/ksysguardd/FreeBSD/logfile.h b/ksysguard/ksysguardd/FreeBSD/logfile.h new file mode 100644 index 000000000..45ade9013 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/logfile.h @@ -0,0 +1,36 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _logfile_h_ +#define _logfile_h_ + +void initLogFile(struct SensorModul* sm); +void exitLogFile(void); + +void printLogFile(const char* cmd); +void printLogFileInfo(const char* cmd); + +void registerLogFile(const char* cmd); +void unregisterLogFile(const char* cmd); + +/* debug command */ +void printRegistered(const char* cmd); + +#endif diff --git a/ksysguard/ksysguardd/FreeBSD/netdev.c b/ksysguard/ksysguardd/FreeBSD/netdev.c new file mode 100644 index 000000000..cec8be590 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/netdev.c @@ -0,0 +1,353 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "Command.h" +#include "ksysguardd.h" +#include "netdev.h" + + +typedef struct { + char name[32]; + u_long recBytes; + u_long recPacks; + u_long recErrs; + u_long recDrop; + u_long recMulticast; + u_long sentBytes; + u_long sentPacks; + u_long sentErrs; + u_long sentMulticast; + u_long sentColls; +} NetDevInfo; + +#define MAXNETDEVS 64 +static NetDevInfo NetDevs[MAXNETDEVS]; +static NetDevInfo NetDevsOld[MAXNETDEVS]; +static int NetDevCnt = 0; +static struct SensorModul* NetDevSM; + +static float elapsed = 0.0; +static struct timeval old_tv; + +char **parseCommand(const char *cmd) +{ + char *tmp_cmd = strdup(cmd); + char *begin; + char **retval = malloc(sizeof(char *)*2); + + begin = rindex(tmp_cmd, '/'); + *begin = '\0'; + begin++; + retval[1] = strdup((const char *)begin); /* sensor */ + + begin = rindex(tmp_cmd, '/'); + *begin = '\0'; + begin = rindex(tmp_cmd, '/'); + begin++; + retval[0] = strdup((const char *)begin); /* interface */ + free(tmp_cmd); + + return retval; +} + +int numActivIfaces(void) +{ + int counter = 0; + int name[6]; + int num_iface, i; + size_t len; + struct ifmibdata ifmd; + + len = sizeof(num_iface); + sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); + + for (i = 1; i < num_iface + 1; i++) { + name[0] = CTL_NET; + name[1] = PF_LINK; + name[2] = NETLINK_GENERIC; + name[3] = IFMIB_IFDATA; + name[4] = i; + name[5] = IFDATA_GENERAL; + + len = sizeof(ifmd); + sysctl(name, 6, &ifmd, &len, NULL, 0); + if (ifmd.ifmd_flags & IFF_UP) + counter++; + } + + return counter; +} + +/* ------------------------------ public part --------------------------- */ + +void initNetDev(struct SensorModul* sm) +{ + int i; + char monitor[1024]; + gettimeofday(&old_tv, (struct timezone *)0); + + NetDevSM = sm; + + updateNetDev(); + + for (i = 0; i < NetDevCnt; i++) { + /* init data */ + NetDevsOld[i] = NetDevs[i]; + + /* register monitors */ + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/data", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/packets", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/errors", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/drops", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/multicast", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevRecBytes, printNetDevRecBytesInfo, NetDevSM); + + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/data", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/packets", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/errors", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/multicast", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, NetDevSM); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/collisions", NetDevs[i].name); + registerMonitor(monitor, "integer", printNetDevSentBytes, printNetDevSentBytesInfo, NetDevSM); + } +} + +void exitNetDev(void) +{ + int i; + char monitor[1024]; + + for (i = 0; i < NetDevCnt; i++) { + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/data", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/packets", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/errors", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/drops", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/receiver/multicast", NetDevs[i].name); + removeMonitor(monitor); + + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/data", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/packets", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/errors", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/multicast", NetDevs[i].name); + removeMonitor(monitor); + snprintf(monitor, sizeof(monitor), "network/interfaces/%s/transmitter/collisions", NetDevs[i].name); + removeMonitor(monitor); + } +} + +int updateNetDev(void) +{ + int name[6]; + int num_iface, i; + size_t len; + struct ifmibdata ifmd; + struct timeval new_tv, tv; + + len = sizeof(num_iface); + sysctlbyname("net.link.generic.system.ifcount", &num_iface, &len, NULL, 0); + + NetDevCnt = 0; + for (i = 1; i < num_iface + 1; i++) { + name[0] = CTL_NET; + name[1] = PF_LINK; + name[2] = NETLINK_GENERIC; + name[3] = IFMIB_IFDATA; + name[4] = i; + name[5] = IFDATA_GENERAL; + + len = sizeof(ifmd); + sysctl(name, 6, &ifmd, &len, NULL, 0); + if (ifmd.ifmd_flags & IFF_UP) { + NetDevsOld[NetDevCnt] = NetDevs[NetDevCnt]; + + strlcpy(NetDevs[NetDevCnt].name, ifmd.ifmd_name, sizeof(NetDevs[NetDevCnt].name)); + NetDevs[NetDevCnt].recBytes = ifmd.ifmd_data.ifi_ibytes; + NetDevs[NetDevCnt].recPacks = ifmd.ifmd_data.ifi_ipackets; + NetDevs[NetDevCnt].recErrs = ifmd.ifmd_data.ifi_ierrors; + NetDevs[NetDevCnt].recDrop = ifmd.ifmd_data.ifi_iqdrops; + NetDevs[NetDevCnt].recMulticast = ifmd.ifmd_data.ifi_imcasts; + NetDevs[NetDevCnt].sentBytes = ifmd.ifmd_data.ifi_obytes; + NetDevs[NetDevCnt].sentPacks = ifmd.ifmd_data.ifi_opackets; + NetDevs[NetDevCnt].sentErrs = ifmd.ifmd_data.ifi_oerrors; + NetDevs[NetDevCnt].sentMulticast = ifmd.ifmd_data.ifi_omcasts; + NetDevs[NetDevCnt].sentColls = ifmd.ifmd_data.ifi_collisions; + NetDevCnt++; + } + } + + gettimeofday(&new_tv, (struct timezone *)0); + timersub(&new_tv, &old_tv, &tv); + elapsed = tv.tv_sec + (tv.tv_usec * 1e-6); + old_tv = new_tv; + + return 0; +} + +void checkNetDev(void) +{ + if (numActivIfaces() != NetDevCnt) { + /* interface has been added or removed + so we do a reset */ + exitNetDev(); + initNetDev(NetDevSM); + } +} + +void printNetDevRecBytes(const char *cmd) +{ + int i; + char **retval; + + retval = parseCommand(cmd); + + if (retval == NULL) + return; + + for (i = 0; i < NetDevCnt; i++) { + if (!strcmp(NetDevs[i].name, retval[0])) { + if (!strncmp(retval[1], "data", 4)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].recBytes - NetDevsOld[i].recBytes) / (1024 * elapsed))); + if (!strncmp(retval[1], "packets", 7)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].recPacks - NetDevsOld[i].recPacks) / elapsed)); + if (!strncmp(retval[1], "errors", 6)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].recErrs - NetDevsOld[i].recErrs) / elapsed)); + if (!strncmp(retval[1], "drops", 5)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].recDrop - NetDevsOld[i].recDrop) / elapsed)); + if (!strncmp(retval[1], "multicast", 9)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].recMulticast - NetDevsOld[i].recMulticast) / elapsed)); + } + } + free(retval[0]); + free(retval[1]); + free(retval); + + fprintf(CurrentClient, "\n"); +} + +void printNetDevRecBytesInfo(const char *cmd) +{ + char **retval; + + retval = parseCommand(cmd); + + if (retval == NULL) + return; + + if (!strncmp(retval[1], "data", 4)) + fprintf(CurrentClient, "Received Data\t0\t0\tkBytes/s\n"); + if (!strncmp(retval[1], "packets", 7)) + fprintf(CurrentClient, "Received Packets\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "errors", 6)) + fprintf(CurrentClient, "Receiver Errors\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "drops", 5)) + fprintf(CurrentClient, "Receiver Drops\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "multicast", 9)) + fprintf(CurrentClient, "Received Multicast Packets\t0\t0\t1/s\n"); + + free(retval[0]); + free(retval[1]); + free(retval); +} + +void printNetDevSentBytes(const char *cmd) +{ + int i; + char **retval; + + retval = parseCommand(cmd); + + if (retval == NULL) + return; + + for (i = 0; i < NetDevCnt; i++) { + if (!strcmp(NetDevs[i].name, retval[0])) { + if (!strncmp(retval[1], "data", 4)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentBytes - NetDevsOld[i].sentBytes) / (1024 * elapsed))); + if (!strncmp(retval[1], "packets", 7)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentPacks - NetDevsOld[i].sentPacks) / elapsed)); + if (!strncmp(retval[1], "errors", 6)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentErrs - NetDevsOld[i].sentErrs) / elapsed)); + if (!strncmp(retval[1], "multicast", 9)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentMulticast - NetDevsOld[i].sentMulticast) / elapsed)); + if (!strncmp(retval[1], "collisions", 10)) + fprintf(CurrentClient, "%lu", (u_long)((NetDevs[i].sentColls - NetDevsOld[i].sentColls) / elapsed)); + } + } + free(retval[0]); + free(retval[1]); + free(retval); + + fprintf(CurrentClient, "\n"); +} + +void printNetDevSentBytesInfo(const char *cmd) +{ + char **retval; + + retval = parseCommand(cmd); + + if (retval == NULL) + return; + + if (!strncmp(retval[1], "data", 4)) + fprintf(CurrentClient, "Sent Data\t0\t0\tkBytes/s\n"); + if (!strncmp(retval[1], "packets", 7)) + fprintf(CurrentClient, "Sent Packets\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "errors", 6)) + fprintf(CurrentClient, "Transmitter Errors\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "multicast", 9)) + fprintf(CurrentClient, "Sent Multicast Packets\t0\t0\t1/s\n"); + if (!strncmp(retval[1], "collisions", 10)) + fprintf(CurrentClient, "Transmitter Collisions\t0\t0\t1/s\n"); + + free(retval[0]); + free(retval[1]); + free(retval); +} diff --git a/ksysguard/ksysguardd/FreeBSD/netdev.h b/ksysguard/ksysguardd/FreeBSD/netdev.h new file mode 100644 index 000000000..17d9c89e9 --- /dev/null +++ b/ksysguard/ksysguardd/FreeBSD/netdev.h @@ -0,0 +1,35 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2001 Tobias Koenig + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +#ifndef _netdev_h_ +#define _netdev_h_ + +void initNetDev(struct SensorModul* sm); +void exitNetDev(void); + +int updateNetDev(void); +void checkNetDev(void); + +void printNetDevRecBytes(const char* cmd); +void printNetDevRecBytesInfo(const char* cmd); +void printNetDevSentBytes(const char* cmd); +void printNetDevSentBytesInfo(const char* cmd); + +#endif -- cgit v1.2.3