diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-10-27 14:53:50 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-10-27 14:53:50 +0000 |
| commit | 6428289e52e3d49d04f46440334becdb4dd50eb7 (patch) | |
| tree | 76c5bd74e671b0951fac6850cebbd67da6866e6c /src/libs/zbxsysinfo/linux/cpu.c | |
| parent | bf1417f0196f1ada1616e1e53e04a55117dc06d4 (diff) | |
| download | zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.tar.gz zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.tar.xz zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.zip | |
- developed new interface for test functions. Result returns with srtuct. (Eugene)
- recreated process() function. (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2227 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo/linux/cpu.c')
| -rw-r--r-- | src/libs/zbxsysinfo/linux/cpu.c | 276 |
1 files changed, 117 insertions, 159 deletions
diff --git a/src/libs/zbxsysinfo/linux/cpu.c b/src/libs/zbxsysinfo/linux/cpu.c index f8e94125..b914fdb6 100644 --- a/src/libs/zbxsysinfo/linux/cpu.c +++ b/src/libs/zbxsysinfo/linux/cpu.c @@ -19,183 +19,71 @@ #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 - -/* AIX CPU */ -#ifdef HAVE_KNLIST_H - #include <knlist.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_CPU_IDLE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int OLD_CPU(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + return get_stat(cmd, flags, result); +} + +int SYSTEM_CPU_IDLE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[idle1]",value,msg,mlen_max); + return get_stat("cpu[idle1]", flags, result); } -int SYSTEM_CPU_IDLE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_IDLE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[idle5]",value,msg,mlen_max); + return get_stat("cpu[idle5]", flags, result); } -int SYSTEM_CPU_IDLE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_IDLE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[idle15]",value,msg,mlen_max); + return get_stat("cpu[idle15]", flags, result); } -int SYSTEM_CPU_NICE1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_NICE1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[nice1]",value,msg,mlen_max); + return get_stat("cpu[nice1]", flags, result); } -int SYSTEM_CPU_NICE5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[nice5]",value,msg,mlen_max); + return get_stat("cpu[nice5]", flags, result); } -int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[nice15]",value,msg,mlen_max); + return get_stat("cpu[nice15]", flags, result); } -int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[user1]",value,msg,mlen_max); + return get_stat("cpu[user1]", flags, result); } -int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[user5]",value,msg,mlen_max); + return get_stat("cpu[user5]", flags, result); } -int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[user15]",value,msg,mlen_max); + return get_stat("cpu[user15]", flags, result); } -int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[system1]",value,msg,mlen_max); + return get_stat("cpu[system1]", flags, result); } -int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[system5]",value,msg,mlen_max); + return get_stat("cpu[system5]", flags, result); } -int SYSTEM_CPU_SYS15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { - return get_stat("cpu[system15]",value,msg,mlen_max); + return get_stat("cpu[system15]", flags, result); } /* AIX CPU info */ @@ -232,14 +120,19 @@ static int getloadavg_kmem(double loadavg[], int nelem) } #endif -int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_LOAD1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_GETLOADAVG double load[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg(load, 3)) { - *value=load[0]; + result->type |= AR_DOUBLE; + result->dbl = load[0]; return SYSINFO_RET_OK; } else @@ -250,24 +143,33 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons #ifdef HAVE_SYS_PSTAT_H struct pst_dynamic dyn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) { return SYSINFO_RET_FAIL; } else { - *value=(double)dyn.psd_avg_1_min; + result->type |= AR_DOUBLE; + result->dbl = (double)dyn.psd_avg_1_min; return SYSINFO_RET_OK; } #else #ifdef HAVE_PROC_LOADAVG - return getPROC("/proc/loadavg",1,1,value,msg,mlen_max); + return getPROC("/proc/loadavg",1,1, flags, result); #else #ifdef HAVE_KSTAT_H static kstat_ctl_t *kc = NULL; kstat_t *ks; kstat_named_t *kn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (!kc && !(kc = kstat_open())) { return SYSINFO_RET_FAIL; @@ -278,20 +180,29 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons { return SYSINFO_RET_FAIL; } - *value=(double)kn->value.ul/256.0; + result->type |= AR_DOUBLE; + result->dbl = (double)kn->value.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg_kmem(loadavg,3) == FAIL) { return SYSINFO_RET_FAIL; } - *value=loadavg[0]; + result->type |= AR_DOUBLE; + result->dbl = loadavg[0]; return SYSINFO_RET_OK; #else + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); return SYSINFO_RET_FAIL; #endif #endif @@ -300,14 +211,19 @@ int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value, cons #endif } -int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_LOAD5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_GETLOADAVG double load[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg(load, 3)) { - *value=load[1]; + result->type |= AR_DOUBLE; + result->dbl = load[1]; return SYSINFO_RET_OK; } else @@ -318,24 +234,33 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons #ifdef HAVE_SYS_PSTAT_H struct pst_dynamic dyn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) { return SYSINFO_RET_FAIL; } else { - *value=(double)dyn.psd_avg_5_min; + result->type |= AR_DOUBLE; + result->dbl = (double)dyn.psd_avg_5_min; return SYSINFO_RET_OK; } #else #ifdef HAVE_PROC_LOADAVG - return getPROC("/proc/loadavg",1,2,value,msg,mlen_max); + return getPROC("/proc/loadavg",1,2, flags, result); #else #ifdef HAVE_KSTAT_H static kstat_ctl_t *kc = NULL; kstat_t *ks; kstat_named_t *kn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (!kc && !(kc = kstat_open())) { return SYSINFO_RET_FAIL; @@ -346,20 +271,29 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons { return SYSINFO_RET_FAIL; } - *value=(double)kn->value.ul/256.0; + result->type |= AR_DOUBLE; + result->dbl = (double)kn->value.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg_kmem(loadavg,3) == FAIL) { return STSINFO_RET_FAIL; } - *value=loadavg[1]; + result->type |= AR_DOUBLE; + result->dbl = loadavg[1]; return SYSINFO_RET_OK; #else + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); return SYSINFO_RET_FAIL; #endif #endif @@ -368,14 +302,19 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value, cons #endif } -int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max) +int SYSTEM_CPU_LOAD15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #ifdef HAVE_GETLOADAVG double load[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg(load, 3)) { - *value=load[2]; + result->type |= AR_DOUBLE; + result->dbl = load[2]; return SYSINFO_RET_OK; } else @@ -386,24 +325,33 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con #ifdef HAVE_SYS_PSTAT_H struct pst_dynamic dyn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) { return SYSINFO_RET_FAIL; } else { - *value=(double)dyn.psd_avg_15_min; + result->type |= AR_DOUBLE; + result->dbl = (double)dyn.psd_avg_15_min; return SYSINFO_RET_OK; } #else #ifdef HAVE_PROC_LOADAVG - return getPROC("/proc/loadavg",1,3,value,msg,mlen_max); + return getPROC("/proc/loadavg",1,3, flags, result); #else #ifdef HAVE_KSTAT_H static kstat_ctl_t *kc = NULL; kstat_t *ks; kstat_named_t *kn; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if (!kc && !(kc = kstat_open())) { return SYSINFO_RET_FAIL; @@ -414,20 +362,29 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con { return SYSINFO_RET_FAIL; } - *value=(double)kn->value.ul/256.0; + result->type |= AR_DOUBLE; + result->dbl = (double)kn->value.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); + if(getloadavg_kmem(loadavg,3) == FAIL) { return STSINFO_RET_FAIL; } - *value=loadavg[2]; + result->type |= AR_DOUBLE; + result->dbl = loadavg[2]; return SYSINFO_RET_OK; #else + assert(result); + + memset(result, 0, sizeof(AGENT_RESULT)); return SYSINFO_RET_FAIL; #endif #endif @@ -435,3 +392,4 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con #endif #endif } + |
