diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-11-01 15:52:10 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-11-01 15:52:10 +0000 |
commit | 2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc (patch) | |
tree | fc0cf11a6f9aff4e59bcef0f20986dc08fed12f3 /src/libs/zbxsysinfo/osx/diskio.c | |
parent | 12b9d9858224301d1abb19f08956964c6fabd9a0 (diff) | |
download | zabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.tar.gz zabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.tar.xz zabbix-2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc.zip |
- added new interface of sysinfo function for others platforms (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2237 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo/osx/diskio.c')
-rw-r--r-- | src/libs/zbxsysinfo/osx/diskio.c | 405 |
1 files changed, 246 insertions, 159 deletions
diff --git a/src/libs/zbxsysinfo/osx/diskio.c b/src/libs/zbxsysinfo/osx/diskio.c index 11da801b..23d0c450 100644 --- a/src/libs/zbxsysinfo/osx/diskio.c +++ b/src/libs/zbxsysinfo/osx/diskio.c @@ -19,271 +19,358 @@ #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 DISKREADOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_ops1[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKREADOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_ops5[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKREADOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_ops15[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKREADBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_blks1[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKREADBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_blks5[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKREADBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKREADBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",device); + snprintf(key,sizeof(key)-1,"disk_read_blks15[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEOPS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEOPS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_ops1[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEOPS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEOPS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_ops5[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEOPS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEOPS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_ops15[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEBLKS1(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEBLKS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_blks1[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEBLKS5(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEBLKS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_blks5[%s]",param); - return get_stat(key,value,msg,mlen_max); + return get_stat(key, flags, result); } -int DISKWRITEBLKS15(const char *cmd, const char *device,double *value, const char *msg, int mlen_max) +static int DISKWRITEBLKS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; - snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",device); + snprintf(key,sizeof(key)-1,"disk_write_blks15[%s]",param); + + return get_stat(key, flags, result); +} + +int VFS_DEV_WRITE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ - return get_stat(key,value,msg,mlen_max); +#define DEV_FNCLIST struct dev_fnclist_s +DEV_FNCLIST +{ + char *type; + char *mode; + int (*function)(); +}; + + DEV_FNCLIST fl[] = + { + {"ops", "avg1" , DISKWRITEOPS1}, + {"ops", "avg5" , DISKWRITEOPS5}, + {"ops", "avg15", DISKWRITEOPS15}, + {"bps", "avg1" , DISKWRITEBLKS1}, + {"bps", "avg5" , DISKWRITEBLKS5}, + {"bps", "avg15", DISKWRITEBLKS15}, + {0, 0, 0} + }; + + char devname[MAX_STRING_LEN]; + char type[MAX_STRING_LEN]; + char mode[MAX_STRING_LEN]; + int i; + + assert(result); + + clean_result(result); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, devname, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 2, type, MAX_STRING_LEN) != 0) + { + type[0] = '\0'; + } + if(type[0] == '\0') + { + /* default parameter */ + sprintf(type, "bps"); + } + + if(get_param(param, 3, mode, MAX_STRING_LEN) != 0) + { + mode[0] = '\0'; + } + + if(mode[0] == '\0') + { + /* default parameter */ + sprintf(mode, "avg1"); + } + + for(i=0; fl[i].type!=0; i++) + { + if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0) + { + if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0) + { + return (fl[i].function)(cmd, devname, flags, result); + } + } + } + + return SYSINFO_RET_FAIL; } -int DISK_IO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +int VFS_DEV_READ(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + +#define DEV_FNCLIST struct dev_fnclist_s +DEV_FNCLIST +{ + char *type; + char *mode; + int (*function)(); +}; + + DEV_FNCLIST fl[] = + { + {"ops", "avg1" , DISKREADOPS1}, + {"ops", "avg5" , DISKREADOPS5}, + {"ops", "avg15", DISKREADOPS15}, + {"bps", "avg1" , DISKREADBLKS1}, + {"bps", "avg5" , DISKREADBLKS5}, + {"bps", "avg15", DISKREADBLKS15}, + {0, 0, 0} + }; + + char devname[MAX_STRING_LEN]; + char type[MAX_STRING_LEN]; + char mode[MAX_STRING_LEN]; + int i; + + assert(result); + + clean_result(result); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, devname, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 2, type, MAX_STRING_LEN) != 0) + { + type[0] = '\0'; + } + if(type[0] == '\0') + { + /* default parameter */ + sprintf(type, "bps"); + } + + if(get_param(param, 3, mode, MAX_STRING_LEN) != 0) + { + mode[0] = '\0'; + } + + if(mode[0] == '\0') + { + /* default parameter */ + sprintf(mode, "avg1"); + } + + for(i=0; fl[i].type!=0; i++) + { + if(strncmp(type, fl[i].type, MAX_STRING_LEN)==0) + { + if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0) + { + return (fl[i].function)(cmd, devname, flags, result); + } + } + } + + return SYSINFO_RET_FAIL; +} + +static int DISK_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_PROC - return getPROC("/proc/stat",2,2,value,msg,mlen_max); + return getPROC("/proc/stat",2,2, flags, result); #else return SYSINFO_RET_FAIL; #endif } -int DISK_RIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +static int DISK_RIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_PROC - return getPROC("/proc/stat",3,2,value,msg,mlen_max); + return getPROC("/proc/stat",3,2, flags, result); #else return SYSINFO_RET_FAIL; #endif } -int DISK_WIO(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +static int DISK_WIO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_PROC - return getPROC("/proc/stat",4,2,value,msg,mlen_max); + return getPROC("/proc/stat",4,2, flags, result); #else return SYSINFO_RET_FAIL; #endif } -int DISK_RBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +static int DISK_RBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_PROC - return getPROC("/proc/stat",5,2,value,msg,mlen_max); + return getPROC("/proc/stat",5,2, flags, result); #else return SYSINFO_RET_FAIL; #endif } -int DISK_WBLK(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +static int DISK_WBLK(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_PROC - return getPROC("/proc/stat",6,2,value,msg,mlen_max); + return getPROC("/proc/stat",6,2, flags, result); #else return SYSINFO_RET_FAIL; #endif } + +int OLD_IO(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + char key[MAX_STRING_LEN]; + int ret; + + assert(result); + + clean_result(result); + + if(num_param(param) > 1) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, key, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(strcmp(key,"disk_io") == 0) + { + ret = DISK_IO(cmd, param, flags, result); + } + else if(strcmp(key,"disk_rio") == 0) + { + ret = DISK_RIO(cmd, param, flags, result); + } + else if(strcmp(key,"disk_wio") == 0) + { + ret = DISK_WIO(cmd, param, flags, result); + } + else if(strcmp(key,"disk_rblk") == 0) + { + ret = DISK_RBLK(cmd, param, flags, result); + } + else if(strcmp(key,"disk_wblk") == 0) + { + ret = DISK_WBLK(cmd, param, flags, result); + } + else + { + ret = SYSINFO_RET_FAIL; + } + + return ret; +} + |