summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo/osf/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxsysinfo/osf/cpu.c')
-rw-r--r--src/libs/zbxsysinfo/osf/cpu.c431
1 files changed, 272 insertions, 159 deletions
diff --git a/src/libs/zbxsysinfo/osf/cpu.c b/src/libs/zbxsysinfo/osf/cpu.c
index f8e94125..4e7e1502 100644
--- a/src/libs/zbxsysinfo/osf/cpu.c
+++ b/src/libs/zbxsysinfo/osf/cpu.c
@@ -19,183 +19,161 @@
#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)
+static 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)
+static 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)
+static 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)
+static 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)
+static int SYSTEM_CPU_NICE5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ return get_stat("cpu[nice5]", flags, result);
+}
+static int SYSTEM_CPU_NICE15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice5]",value,msg,mlen_max);
+ return get_stat("cpu[nice15]", flags, result);
}
-int SYSTEM_CPU_NICE15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+
+static int SYSTEM_CPU_USER1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[nice15]",value,msg,mlen_max);
+ return get_stat("cpu[user1]", flags, result);
}
-int SYSTEM_CPU_USER1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user1]",value,msg,mlen_max);
+ return get_stat("cpu[user5]", flags, result);
}
-int SYSTEM_CPU_USER5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_USER15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user5]",value,msg,mlen_max);
+ return get_stat("cpu[user15]", flags, result);
}
-int SYSTEM_CPU_USER15(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS1(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[user15]",value,msg,mlen_max);
+ return get_stat("cpu[system1]", flags, result);
}
-int SYSTEM_CPU_SYS1(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS5(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system1]",value,msg,mlen_max);
+ return get_stat("cpu[system5]", flags, result);
}
-int SYSTEM_CPU_SYS5(const char *cmd, const char *param,double *value, const char *msg, int mlen_max)
+static int SYSTEM_CPU_SYS15(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return get_stat("cpu[system5]",value,msg,mlen_max);
+ return get_stat("cpu[system15]", flags, result);
}
-int SYSTEM_CPU_SYS15(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("cpu[system15]",value,msg,mlen_max);
+ return get_stat(cmd, flags, result);
+}
+
+int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *type;
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"idle", "avg1" , SYSTEM_CPU_IDLE1},
+ {"idle", "avg5" , SYSTEM_CPU_IDLE5},
+ {"idle", "avg15", SYSTEM_CPU_IDLE15},
+ {"nice", "avg1" , SYSTEM_CPU_NICE1},
+ {"nice", "avg5" , SYSTEM_CPU_NICE5},
+ {"nice", "avg15", SYSTEM_CPU_NICE15},
+ {"user", "avg1" , SYSTEM_CPU_USER1},
+ {"user", "avg5" , SYSTEM_CPU_USER5},
+ {"user", "avg15", SYSTEM_CPU_USER15},
+ {"system", "avg1" , SYSTEM_CPU_SYS1},
+ {"system", "avg5" , SYSTEM_CPU_SYS5},
+ {"system", "avg15", SYSTEM_CPU_SYS15},
+ {0, 0, 0}
+ };
+
+ char cpuname[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, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ 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, "user");
+ }
+
+ 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, param, flags, result);
+ }
+ }
+ }
+ return SYSINFO_RET_FAIL;
}
/* AIX CPU info */
@@ -232,14 +210,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);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[0];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[0];
return SYSINFO_RET_OK;
}
else
@@ -250,24 +233,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);
+
+ clean_result(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);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -278,20 +270,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);
+
+ clean_result(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);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -300,14 +301,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);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[1];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[1];
return SYSINFO_RET_OK;
}
else
@@ -318,24 +324,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);
+
+ clean_result(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);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -346,20 +361,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);
+
+ clean_result(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);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -368,14 +392,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);
+
+ clean_result(result);
+
if(getloadavg(load, 3))
{
- *value=load[2];
+ result->type |= AR_DOUBLE;
+ result->dbl = load[2];
return SYSINFO_RET_OK;
}
else
@@ -386,24 +415,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);
+
+ clean_result(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);
+
+ clean_result(result);
+
if (!kc && !(kc = kstat_open()))
{
return SYSINFO_RET_FAIL;
@@ -414,20 +452,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);
+
+ clean_result(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);
+
+ clean_result(result);
return SYSINFO_RET_FAIL;
#endif
#endif
@@ -435,3 +482,69 @@ int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value, con
#endif
#endif
}
+
+int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+
+#define CPU_FNCLIST struct cpu_fnclist_s
+CPU_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ CPU_FNCLIST fl[] =
+ {
+ {"avg1" , SYSTEM_CPU_LOAD1},
+ {"avg5" , SYSTEM_CPU_LOAD5},
+ {"avg15", SYSTEM_CPU_LOAD15},
+ {0, 0}
+ };
+
+ char cpuname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 2)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, cpuname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+ if(cpuname[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(cpuname, "all");
+ }
+ if(strncmp(cpuname, "all", MAX_STRING_LEN))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "avg1");
+ }
+ for(i=0; fl[i].mode!=0; i++)
+ {
+ if(strncmp(mode, fl[i].mode, MAX_STRING_LEN)==0)
+ {
+ return (fl[i].function)(cmd, param, flags, result);
+ }
+ }
+
+ return SYSINFO_RET_FAIL;
+}
+