diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/zbxsysinfo/Makefile.am | 2 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/linux/cpu.c (renamed from src/libs/zbxsysinfo/cpu.c) | 0 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/linux/file.c (renamed from src/libs/zbxsysinfo/file.c) | 0 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/linux/inodes.c (renamed from src/libs/zbxsysinfo/inodes.c) | 0 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/memory.c | 430 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/swap.c | 270 | ||||
-rw-r--r-- | src/libs/zbxsysinfo/uptime.c | 217 |
7 files changed, 1 insertions, 918 deletions
diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am index 558d7c8e..d7547241 100644 --- a/src/libs/zbxsysinfo/Makefile.am +++ b/src/libs/zbxsysinfo/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS= lib_LIBRARIES=libzbxsysinfo.a -libzbxsysinfo_a_SOURCES=cpu.c diskio.c diskspace.c file.c inodes.c memory.c sensors.c swap.c uptime.c sysinfo.c system.c +libzbxsysinfo_a_SOURCES=@ZBX_OS@/cpu.c diskio.c diskspace.c @ZBX_OS@/file.c @ZBX_OS@/inodes.c memory.c sensors.c swap.c uptime.c sysinfo.c system.c libzbxsysinfo_a_LIBADD = ../zbxcrypto/libzbxcrypto.a diff --git a/src/libs/zbxsysinfo/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c index da971b3a..da971b3a 100644 --- a/src/libs/zbxsysinfo/cpu.c +++ b/src/libs/zbxsysinfo/linux/cpu.c diff --git a/src/libs/zbxsysinfo/file.c b/src/libs/zbxsysinfo/linux/file.c index 00d0be55..00d0be55 100644 --- a/src/libs/zbxsysinfo/file.c +++ b/src/libs/zbxsysinfo/linux/file.c diff --git a/src/libs/zbxsysinfo/inodes.c b/src/libs/zbxsysinfo/linux/inodes.c index 0ea41a7c..0ea41a7c 100644 --- a/src/libs/zbxsysinfo/inodes.c +++ b/src/libs/zbxsysinfo/linux/inodes.c diff --git a/src/libs/zbxsysinfo/memory.c b/src/libs/zbxsysinfo/memory.c deleted file mode 100644 index 21461a80..00000000 --- a/src/libs/zbxsysinfo/memory.c +++ /dev/null @@ -1,430 +0,0 @@ -/* -** ZABBIX -** Copyright (C) 2000-2005 SIA Zabbix -** -** 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., 675 Mass Ave, Cambridge, MA 02139, USA. -**/ - -#include "config.h" - -#include <errno.h> - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> - -/* Definitions of uint32_t under OS/X */ -#ifdef HAVE_STDINT_H - #include <stdint.h> -#endif -#ifdef HAVE_STRINGS_H - #include <strings.h> -#endif -#ifdef HAVE_FCNTL_H - #include <fcntl.h> -#endif -#ifdef HAVE_DIRENT_H - #include <dirent.h> -#endif -/* Linux */ -#ifdef HAVE_SYS_VFS_H - #include <sys/vfs.h> -#endif -#ifdef HAVE_SYS_SYSINFO_H - #include <sys/sysinfo.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_STATVFS_H - #include <sys/statvfs.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_PROCFS_H -/* This is needed to access the correct procfs.h definitions */ - #define _STRUCTURED_PROC 1 - #include <sys/procfs.h> -#endif -#ifdef HAVE_SYS_LOADAVG_H - #include <sys/loadavg.h> -#endif -#ifdef HAVE_SYS_SOCKET_H - #include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H - #include <netinet/in.h> -#endif -#ifdef HAVE_ARPA_INET_H - #include <arpa/inet.h> -#endif -/* OpenBSD/Solaris */ -#ifdef HAVE_SYS_PARAM_H - #include <sys/param.h> -#endif - -#ifdef HAVE_SYS_MOUNT_H - #include <sys/mount.h> -#endif - -/* HP-UX */ -#ifdef HAVE_SYS_PSTAT_H - #include <sys/pstat.h> -#endif - -#ifdef HAVE_NETDB_H - #include <netdb.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SWAP_H - #include <sys/swap.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_SYS_SYSCTL_H - #include <sys/sysctl.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SYSCALL_H - #include <sys/syscall.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_VM_VM_PARAM_H - #include <vm/vm_param.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_VMMETER_H - #include <sys/vmmeter.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_TIME_H - #include <sys/time.h> -#endif - -#ifdef HAVE_MACH_HOST_INFO_H - #include <mach/host_info.h> -#endif -#ifdef HAVE_MACH_MACH_HOST_H - #include <mach/mach_host.h> -#endif - - -#ifdef HAVE_KSTAT_H - #include <kstat.h> -#endif - -#ifdef HAVE_LDAP - #include <ldap.h> -#endif - -#include "common.h" -#include "sysinfo.h" - -int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_PROC -/* Get CACHED memory in bytes */ -/* return getPROC("/proc/meminfo",8,2);*/ -/* It does not work for both 2.4 and 2.6 */ -/* return getPROC("/proc/meminfo",2,7);*/ - FILE *f; - char *t; - char c[MAX_STRING_LEN]; - double result = SYSINFO_RET_FAIL; - - f=fopen("/proc/meminfo","r"); - if(NULL == f) - { - return SYSINFO_RET_FAIL; - } - while(NULL!=fgets(c,MAX_STRING_LEN,f)) - { - if(strncmp(c,"Cached:",7) == 0) - { - t=(char *)strtok(c," "); - t=(char *)strtok(NULL," "); - sscanf(t, "%lf", &result ); - break; - } - } - fclose(f); - - *value=result; - return SYSINFO_RET_OK; -#else - return SYSINFO_RET_FAIL; -#endif -} - -int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_SYSINFO_BUFFERRAM - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.bufferram * (double)info.mem_unit; -#else - *value=(double)info.bufferram; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -#else - return SYSINFO_RET_FAIL; -#endif -} - -int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_SYSINFO_SHAREDRAM - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.sharedram * (double)info.mem_unit; -#else - *value=(double)info.sharedram; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -#else -#ifdef HAVE_SYS_VMMETER_VMTOTAL - int mib[2],len; - struct vmtotal v; - - len=sizeof(struct vmtotal); - mib[0]=CTL_VM; - mib[1]=VM_METER; - - sysctl(mib,2,&v,&len,NULL,0); - - *value=(double)(v.t_armshr<<2); - return SYSINFO_RET_OK; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -} - -int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value) -{ -/* Solaris */ -#ifdef HAVE_UNISTD_SYSCONF - *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE); - return SYSINFO_RET_OK; -#else -#ifdef HAVE_SYS_PSTAT_H - struct pst_static pst; - long page; - - if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) - { - return SYSINFO_RET_FAIL; - } - else - { - /* Get page size */ - page = pst.page_size; - /* Total physical memory in bytes */ - *value=(double)page*pst.physical_memory; - return SYSINFO_RET_OK; - } -#else -#ifdef HAVE_SYSINFO_TOTALRAM - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.totalram * (double)info.mem_unit; -#else - *value=(double)info.totalram; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -#else -#ifdef HAVE_SYS_VMMETER_VMTOTAL - int mib[2],len; - struct vmtotal v; - - len=sizeof(struct vmtotal); - mib[0]=CTL_VM; - mib[1]=VM_METER; - - sysctl(mib,2,&v,&len,NULL,0); - - *value=(double)(v.t_rm<<2); - return SYSINFO_RET_OK; -#else -#ifdef HAVE_SYS_SYSCTL_H - static int mib[] = { CTL_HW, HW_PHYSMEM }; - size_t len; - unsigned int memory; - int ret; - - len=sizeof(memory); - - if(0==sysctl(mib,2,&memory,&len,NULL,0)) - { - *value=(double)memory; - ret=SYSINFO_RET_OK; - } - else - { - ret=SYSINFO_RET_FAIL; - } - return ret; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -#endif -#endif -#endif -} - -int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value) -{ -/* Solaris */ -#ifdef HAVE_UNISTD_SYSCONF - *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE); - return SYSINFO_RET_OK; -#else -#ifdef HAVE_SYS_PSTAT_H - struct pst_static pst; - struct pst_dynamic dyn; - long page; - - if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1) - { - return SYSINFO_RET_FAIL; - } - else - { - /* Get page size */ - page = pst.page_size; -/* return pst.physical_memory;*/ - - if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) - { - return SYSINFO_RET_FAIL; - } - else - { -/* cout<<"total virtual memory allocated is " << dyn.psd_vm << " - pages, " << dyn.psd_vm * page << " bytes" << endl; - cout<<"active virtual memory is " << dyn.psd_avm <<" pages, " << - dyn.psd_avm * page << " bytes" << endl; - cout<<"total real memory is " << dyn.psd_rm << " pages, " << - dyn.psd_rm * page << " bytes" << endl; - cout<<"active real memory is " << dyn.psd_arm << " pages, " << - dyn.psd_arm * page << " bytes" << endl; - cout<<"free memory is " << dyn.psd_free << " pages, " << -*/ - /* Free memory in bytes */ - - *value=(double)dyn.psd_free * page; - return SYSINFO_RET_OK; - } - } -#else -#ifdef HAVE_SYSINFO_FREERAM - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.freeram * (double)info.mem_unit; -#else - *value=(double)info.freeram; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -#else -#ifdef HAVE_SYS_VMMETER_VMTOTAL - int mib[2],len; - struct vmtotal v; - - len=sizeof(struct vmtotal); - mib[0]=CTL_VM; - mib[1]=VM_METER; - - sysctl(mib,2,&v,&len,NULL,0); - - *value=(double)(v.t_free<<2); - return SYSINFO_RET_OK; -#else -/* OS/X */ -#ifdef HAVE_MACH_HOST_INFO_H - vm_statistics_data_t page_info; - vm_size_t pagesize; - mach_msg_type_number_t count; - kern_return_t kret; - int ret; - - pagesize = 0; - kret = host_page_size (mach_host_self(), &pagesize); - - count = HOST_VM_INFO_COUNT; - kret = host_statistics (mach_host_self(), HOST_VM_INFO, - (host_info_t)&page_info, &count); - if (kret == KERN_SUCCESS) - { - double pw, pa, pi, pf, pu; - - pw = (double)page_info.wire_count*pagesize; - pa = (double)page_info.active_count*pagesize; - pi = (double)page_info.inactive_count*pagesize; - pf = (double)page_info.free_count*pagesize; - - pu = pw+pa+pi; - - *value=(double)pf; - ret = SYSINFO_RET_OK; - } - else - { - ret = SYSINFO_RET_FAIL; - } - return ret; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -#endif -#endif -#endif -} diff --git a/src/libs/zbxsysinfo/swap.c b/src/libs/zbxsysinfo/swap.c deleted file mode 100644 index d4f13a53..00000000 --- a/src/libs/zbxsysinfo/swap.c +++ /dev/null @@ -1,270 +0,0 @@ -/* -** ZABBIX -** Copyright (C) 2000-2005 SIA Zabbix -** -** 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., 675 Mass Ave, Cambridge, MA 02139, USA. -**/ - -#include "config.h" - -#include <errno.h> - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> - -/* Definitions of uint32_t under OS/X */ -#ifdef HAVE_STDINT_H - #include <stdint.h> -#endif -#ifdef HAVE_STRINGS_H - #include <strings.h> -#endif -#ifdef HAVE_FCNTL_H - #include <fcntl.h> -#endif -#ifdef HAVE_DIRENT_H - #include <dirent.h> -#endif -/* Linux */ -#ifdef HAVE_SYS_VFS_H - #include <sys/vfs.h> -#endif -#ifdef HAVE_SYS_SYSINFO_H - #include <sys/sysinfo.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_STATVFS_H - #include <sys/statvfs.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_PROCFS_H -/* This is needed to access the correct procfs.h definitions */ - #define _STRUCTURED_PROC 1 - #include <sys/procfs.h> -#endif -#ifdef HAVE_SYS_LOADAVG_H - #include <sys/loadavg.h> -#endif -#ifdef HAVE_SYS_SOCKET_H - #include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H - #include <netinet/in.h> -#endif -#ifdef HAVE_ARPA_INET_H - #include <arpa/inet.h> -#endif -/* OpenBSD/Solaris */ -#ifdef HAVE_SYS_PARAM_H - #include <sys/param.h> -#endif - -#ifdef HAVE_SYS_MOUNT_H - #include <sys/mount.h> -#endif - -/* HP-UX */ -#ifdef HAVE_SYS_PSTAT_H - #include <sys/pstat.h> -#endif - -#ifdef HAVE_NETDB_H - #include <netdb.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SWAP_H - #include <sys/swap.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_SYS_SYSCTL_H - #include <sys/sysctl.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SYSCALL_H - #include <sys/syscall.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_VM_VM_PARAM_H - #include <vm/vm_param.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_VMMETER_H - #include <sys/vmmeter.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_TIME_H - #include <sys/time.h> -#endif - -#ifdef HAVE_MACH_HOST_INFO_H - #include <mach/host_info.h> -#endif -#ifdef HAVE_MACH_MACH_HOST_H - #include <mach/mach_host.h> -#endif - - -#ifdef HAVE_KSTAT_H - #include <kstat.h> -#endif - -#ifdef HAVE_LDAP - #include <ldap.h> -#endif - -#include "common.h" -#include "sysinfo.h" - -#include "md5.h" - -/* Solaris. */ -#ifndef HAVE_SYSINFO_FREESWAP -#ifdef HAVE_SYS_SWAP_SWAPTABLE -void get_swapinfo(double *total, double *fr) -{ - register int cnt, i, page_size; -/* Support for >2Gb */ -/* register int t, f;*/ - double t, f; - struct swaptable *swt; - struct swapent *ste; - static char path[256]; - - /* get total number of swap entries */ - cnt = swapctl(SC_GETNSWP, 0); - - /* allocate enough space to hold count + n swapents */ - swt = (struct swaptable *)malloc(sizeof(int) + - cnt * sizeof(struct swapent)); - - if (swt == NULL) - { - *total = 0; - *fr = 0; - return; - } - swt->swt_n = cnt; - -/* fill in ste_path pointers: we don't care about the paths, so we -point them all to the same buffer */ - ste = &(swt->swt_ent[0]); - i = cnt; - while (--i >= 0) - { - ste++->ste_path = path; - } - - /* grab all swap info */ - swapctl(SC_LIST, swt); - - /* walk thru the structs and sum up the fields */ - t = f = 0; - ste = &(swt->swt_ent[0]); - i = cnt; - while (--i >= 0) - { - /* dont count slots being deleted */ - if (!(ste->ste_flags & ST_INDEL) && - !(ste->ste_flags & ST_DOINGDEL)) - { - t += ste->ste_pages; - f += ste->ste_free; - } - ste++; - } - - page_size=getpagesize(); - - /* fill in the results */ - *total = page_size*t; - *fr = page_size*f; - free(swt); -} -#endif -#endif - -int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_SYSINFO_FREESWAP - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.freeswap * (double)info.mem_unit; -#else - *value=(double)info.freeswap; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -/* Solaris */ -#else -#ifdef HAVE_SYS_SWAP_SWAPTABLE - double swaptotal,swapfree; - - get_swapinfo(&swaptotal,&swapfree); - - *value=swapfree; - return SYSINFO_RET_OK; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -} - -int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_SYSINFO_TOTALSWAP - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { -#ifdef HAVE_SYSINFO_MEM_UNIT - *value=(double)info.totalswap * (double)info.mem_unit; -#else - *value=(double)info.totalswap; -#endif - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -/* Solaris */ -#else -#ifdef HAVE_SYS_SWAP_SWAPTABLE - double swaptotal,swapfree; - - get_swapinfo(&swaptotal,&swapfree); - - *value=(double)swaptotal; - return SYSINFO_RET_OK; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -} diff --git a/src/libs/zbxsysinfo/uptime.c b/src/libs/zbxsysinfo/uptime.c deleted file mode 100644 index 9455bef2..00000000 --- a/src/libs/zbxsysinfo/uptime.c +++ /dev/null @@ -1,217 +0,0 @@ -/* -** ZABBIX -** Copyright (C) 2000-2005 SIA Zabbix -** -** 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., 675 Mass Ave, Cambridge, MA 02139, USA. -**/ - -#include "config.h" - -#include <errno.h> - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> - -/* Definitions of uint32_t under OS/X */ -#ifdef HAVE_STDINT_H - #include <stdint.h> -#endif -#ifdef HAVE_STRINGS_H - #include <strings.h> -#endif -#ifdef HAVE_FCNTL_H - #include <fcntl.h> -#endif -#ifdef HAVE_DIRENT_H - #include <dirent.h> -#endif -/* Linux */ -#ifdef HAVE_SYS_VFS_H - #include <sys/vfs.h> -#endif -#ifdef HAVE_SYS_SYSINFO_H - #include <sys/sysinfo.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_STATVFS_H - #include <sys/statvfs.h> -#endif -/* Solaris */ -#ifdef HAVE_SYS_PROCFS_H -/* This is needed to access the correct procfs.h definitions */ - #define _STRUCTURED_PROC 1 - #include <sys/procfs.h> -#endif -#ifdef HAVE_SYS_LOADAVG_H - #include <sys/loadavg.h> -#endif -#ifdef HAVE_SYS_SOCKET_H - #include <sys/socket.h> -#endif -#ifdef HAVE_NETINET_IN_H - #include <netinet/in.h> -#endif -#ifdef HAVE_ARPA_INET_H - #include <arpa/inet.h> -#endif -/* OpenBSD/Solaris */ -#ifdef HAVE_SYS_PARAM_H - #include <sys/param.h> -#endif - -#ifdef HAVE_SYS_MOUNT_H - #include <sys/mount.h> -#endif - -/* HP-UX */ -#ifdef HAVE_SYS_PSTAT_H - #include <sys/pstat.h> -#endif - -#ifdef HAVE_NETDB_H - #include <netdb.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SWAP_H - #include <sys/swap.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_SYS_SYSCTL_H - #include <sys/sysctl.h> -#endif - -/* Solaris */ -#ifdef HAVE_SYS_SYSCALL_H - #include <sys/syscall.h> -#endif - -/* FreeBSD */ -#ifdef HAVE_VM_VM_PARAM_H - #include <vm/vm_param.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_VMMETER_H - #include <sys/vmmeter.h> -#endif -/* FreeBSD */ -#ifdef HAVE_SYS_TIME_H - #include <sys/time.h> -#endif - -#ifdef HAVE_MACH_HOST_INFO_H - #include <mach/host_info.h> -#endif -#ifdef HAVE_MACH_MACH_HOST_H - #include <mach/mach_host.h> -#endif - - -#ifdef HAVE_KSTAT_H - #include <kstat.h> -#endif - -#ifdef HAVE_LDAP - #include <ldap.h> -#endif - -#include "common.h" -#include "sysinfo.h" - -int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value) -{ -#ifdef HAVE_SYSINFO_UPTIME - struct sysinfo info; - - if( 0 == sysinfo(&info)) - { - *value=(double)info.uptime; - return SYSINFO_RET_OK; - } - else - { - return SYSINFO_RET_FAIL; - } -#else -#ifdef HAVE_FUNCTION_SYSCTL_KERN_BOOTTIME - int mib[2],len; - struct timeval uptime; - int now; - - mib[0]=CTL_KERN; - mib[1]=KERN_BOOTTIME; - - len=sizeof(uptime); - - if(sysctl(mib,2,&uptime,(size_t *)&len,NULL,0) != 0) - { - return SYSINFO_RET_FAIL; -/* printf("Errno [%m]\n");*/ - } - - now=time(NULL); - - *value=(double)(now-uptime.tv_sec); - return SYSINFO_RET_OK; -#else -/* Solaris */ -#ifdef HAVE_KSTAT_H - kstat_ctl_t *kc; - kstat_t *kp; - kstat_named_t *kn; - - long hz; - long secs; - - hz = sysconf(_SC_CLK_TCK); - - /* open kstat */ - kc = kstat_open(); - if (0 == kc) - { - return SYSINFO_RET_FAIL; - } - - /* read uptime counter */ - kp = kstat_lookup(kc, "unix", 0, "system_misc"); - if (0 == kp) - { - kstat_close(kc); - return SYSINFO_RET_FAIL; - } - - if(-1 == kstat_read(kc, kp, 0)) - { - kstat_close(kc); - return SYSINFO_RET_FAIL; - } - kn = (kstat_named_t*)kstat_data_lookup(kp, "clk_intr"); - secs = kn->value.ul / hz; - - /* close kstat */ - kstat_close(kc); - *value=(double)secs; - return SYSINFO_RET_OK; -#else - return SYSINFO_RET_FAIL; -#endif -#endif -#endif -} |