diff options
Diffstat (limited to 'src/libs/zbxsysinfo/solaris/memory.c')
-rw-r--r-- | src/libs/zbxsysinfo/solaris/memory.c | 258 |
1 files changed, 60 insertions, 198 deletions
diff --git a/src/libs/zbxsysinfo/solaris/memory.c b/src/libs/zbxsysinfo/solaris/memory.c index 9fe64906..385ece4a 100644 --- a/src/libs/zbxsysinfo/solaris/memory.c +++ b/src/libs/zbxsysinfo/solaris/memory.c @@ -19,234 +19,96 @@ #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 +#include "common.h" +#include "sysinfo.h" -/* Solaris */ -#ifdef HAVE_SYS_SYSCALL_H - #include <sys/syscall.h> -#endif +static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result); +static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result); -/* 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 +int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ +#define MEM_FNCLIST struct mem_fnclist_s +MEM_FNCLIST +{ + char *mode; + int (*function)(); +}; -#ifdef HAVE_MACH_HOST_INFO_H - #include <mach/host_info.h> -#endif -#ifdef HAVE_MACH_MACH_HOST_H - #include <mach/mach_host.h> -#endif + MEM_FNCLIST fl[] = + { + {"total", VM_MEMORY_TOTAL}, + {"free", VM_MEMORY_FREE}, + {0, 0} + }; + char mode[MAX_STRING_LEN]; + int i; + assert(result); -#ifdef HAVE_KSTAT_H - #include <kstat.h> -#endif + clean_result(result); -#ifdef HAVE_LDAP - #include <ldap.h> -#endif + if(num_param(param) > 1) + { + return SYSINFO_RET_FAIL; + } -#include "common.h" -#include "sysinfo.h" + if(get_param(param, 1, mode, MAX_STRING_LEN) != 0) + { + mode[0] = '\0'; + } -int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) -{ -#ifdef HAVE_PROC -/* Get CACHED memory in bytes */ -/* return getPROC("/proc/meminfo",8,2,msg,mlen_max);*/ -/* It does not work for both 2.4 and 2.6 */ -/* return getPROC("/proc/meminfo",2,7,msg,mlen_max);*/ - FILE *f; - char *t; - char c[MAX_STRING_LEN]; - double result = SYSINFO_RET_FAIL; - - f=fopen("/proc/meminfo","r"); - if(NULL == f) + if(mode[0] == '\0') { - return SYSINFO_RET_FAIL; + /* default parameter */ + sprintf(mode, "total"); } - while(NULL!=fgets(c,MAX_STRING_LEN,f)) + + for(i=0; fl[i].mode!=0; i++) { - if(strncmp(c,"Cached:",7) == 0) + if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0) { - t=(char *)strtok(c," "); - t=(char *)strtok(NULL," "); - sscanf(t, "%lf", &result ); - break; + return (fl[i].function)(cmd, param, flags, result); } } - 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, const char *msg, int mlen_max) -{ -#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, const char *msg, int mlen_max) +static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { -#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); +#ifdef HAVE_UNISTD_SYSCONF + assert(result); - *value=(double)(v.t_armshr<<2); + clean_result(result); + + result->type |= AR_DOUBLE; + result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE); return SYSINFO_RET_OK; #else - return SYSINFO_RET_FAIL; -#endif -#endif -} + assert(result); -int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) -{ -#ifdef HAVE_UNISTD_SYSCONF - *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE); - return SYSINFO_RET_OK; -#else + clean_result(result); + return SYSINFO_RET_FAIL; #endif } -int VM_MEMORY_FREE(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_UNISTD_SYSCONF - *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE); + assert(result); + + clean_result(result); + + result->type |= AR_DOUBLE; + result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE); return SYSINFO_RET_OK; #else + assert(result); + + clean_result(result); + return SYSINFO_RET_FAIL; #endif } + |