summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo/osf/memory.c
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-01 15:52:10 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-01 15:52:10 +0000
commit2c9ca1001703a1ba0ae7b6d4cd238ebd44148fdc (patch)
treefc0cf11a6f9aff4e59bcef0f20986dc08fed12f3 /src/libs/zbxsysinfo/osf/memory.c
parent12b9d9858224301d1abb19f08956964c6fabd9a0 (diff)
downloadzabbix-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/osf/memory.c')
-rw-r--r--src/libs/zbxsysinfo/osf/memory.c412
1 files changed, 266 insertions, 146 deletions
diff --git a/src/libs/zbxsysinfo/osf/memory.c b/src/libs/zbxsysinfo/osf/memory.c
index d0c51bc9..7dc0fcbe 100644
--- a/src/libs/zbxsysinfo/osf/memory.c
+++ b/src/libs/zbxsysinfo/osf/memory.c
@@ -19,123 +19,10 @@
#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, const char *msg, int mlen_max)
+static int VM_MEMORY_CACHED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_PROC
/* Get CACHED memory in bytes */
@@ -145,8 +32,12 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
FILE *f;
char *t;
char c[MAX_STRING_LEN];
- double result = SYSINFO_RET_FAIL;
+ double res = 0;
+
+ assert(result);
+ clean_result(result);
+
f=fopen("/proc/meminfo","r");
if(NULL == f)
{
@@ -158,30 +49,40 @@ int VM_MEMORY_CACHED(const char *cmd, const char *parameter,double *value, cons
{
t=(char *)strtok(c," ");
t=(char *)strtok(NULL," ");
- sscanf(t, "%lf", &result );
+ sscanf(t, "%lf", &res );
break;
}
}
fclose(f);
- *value=result;
+ result->type |= AR_DOUBLE;
+ result->dbl=res;
return SYSINFO_RET_OK;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
}
-int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, const char *msg, int mlen_max)
+static int VM_MEMORY_BUFFERS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_BUFFERRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.bufferram * (double)info.mem_unit;
+ result->dbl=(double)info.bufferram * (double)info.mem_unit;
#else
- *value=(double)info.bufferram;
+ result->dbl=(double)info.bufferram;
#endif
return SYSINFO_RET_OK;
}
@@ -190,21 +91,30 @@ int VM_MEMORY_BUFFERS(const char *cmd, const char *parameter,double *value, con
return SYSINFO_RET_FAIL;
}
#else
+ assert(result);
+
+ clean_result(result);
+
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_SHARED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_SYSINFO_SHAREDRAM
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.sharedram * (double)info.mem_unit;
+ result->dbl=(double)info.sharedram * (double)info.mem_unit;
#else
- *value=(double)info.sharedram;
+ result->dbl=(double)info.sharedram;
#endif
return SYSINFO_RET_OK;
}
@@ -212,36 +122,47 @@ int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value, cons
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
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);
+ result->type |= AR_DOUBLE;
+ result->dbl=(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, const char *msg, int mlen_max)
+static int VM_MEMORY_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
/* Solaris */
#ifdef HAVE_UNISTD_SYSCONF
- *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_PSTAT_H
+#elif defined(HAVE_SYS_PSTAT_H)
struct pst_static pst;
long page;
+ assert(result);
+
+ clean_result(result);
+
if(pstat_getstatic(&pst, sizeof(pst), (size_t)1, 0) == -1)
{
return SYSINFO_RET_FAIL;
@@ -251,19 +172,24 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
/* Get page size */
page = pst.page_size;
/* Total physical memory in bytes */
- *value=(double)page*pst.physical_memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)page*pst.physical_memory;
return SYSINFO_RET_OK;
}
-#else
-#ifdef HAVE_SYSINFO_TOTALRAM
+#elif defined(HAVE_SYSINFO_TOTALRAM)
struct sysinfo info;
+ assert(result);
+
+ clean_result(result);
+
if( 0 == sysinfo(&info))
{
+ result->type |= AR_DOUBLE;
#ifdef HAVE_SYSINFO_MEM_UNIT
- *value=(double)info.totalram * (double)info.mem_unit;
+ result->dbl=(double)info.totalram * (double)info.mem_unit;
#else
- *value=(double)info.totalram;
+ result->dbl=(double)info.totalram;
#endif
return SYSINFO_RET_OK;
}
@@ -271,31 +197,39 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
{
return SYSINFO_RET_FAIL;
}
-#else
-#ifdef HAVE_SYS_VMMETER_VMTOTAL
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
int mib[2],len;
struct vmtotal v;
+ assert(result);
+
+ clean_result(result);
+
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);
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_rm<<2);
return SYSINFO_RET_OK;
-#else
-#ifdef HAVE_SYS_SYSCTL_H
+#elif defined(HAVE_SYS_SYSCTL_H)
static int mib[] = { CTL_HW, HW_PHYSMEM };
size_t len;
unsigned int memory;
int ret;
+ assert(result);
+
+ clean_result(result);
+
len=sizeof(memory);
if(0==sysctl(mib,2,&memory,&len,NULL,0))
{
- *value=(double)memory;
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)memory;
ret=SYSINFO_RET_OK;
}
else
@@ -304,15 +238,201 @@ int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value, const
}
return ret;
#else
+ assert(result);
+
+ clean_result(result);
+
return SYSINFO_RET_FAIL;
#endif
+}
+
+static int VM_MEMORY_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+/* Solaris */
+#ifdef HAVE_UNISTD_SYSCONF
+ assert(result);
+
+ clean_result(result);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
+ return SYSINFO_RET_OK;
+#elif defined(HAVE_SYS_PSTAT_H)
+ struct pst_static pst;
+ struct pst_dynamic dyn;
+ long page;
+
+ assert(result);
+
+ clean_result(result);
+
+ 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 */
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)dyn.psd_free * page;
+ return SYSINFO_RET_OK;
+ }
+ }
+#elif defined(HAVE_SYSINFO_FREERAM)
+ struct sysinfo info;
+
+ assert(result);
+
+ clean_result(result);
+
+ if( 0 == sysinfo(&info))
+ {
+ result->type |= AR_DOUBLE;
+#ifdef HAVE_SYSINFO_MEM_UNIT
+ result->dbl=(double)info.freeram * (double)info.mem_unit;
+#else
+ result->dbl=(double)info.freeram;
#endif
-#endif
-#endif
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+#elif defined(HAVE_SYS_VMMETER_VMTOTAL)
+ int mib[2],len;
+ struct vmtotal v;
+
+ assert(result);
+
+ clean_result(result);
+
+ len=sizeof(struct vmtotal);
+ mib[0]=CTL_VM;
+ mib[1]=VM_METER;
+
+ sysctl(mib,2,&v,&len,NULL,0);
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)(v.t_free<<2);
+ return SYSINFO_RET_OK;
+/* OS/X */
+#elif defined(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;
+
+ assert(result);
+
+ clean_result(result);
+
+ 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;
+
+ result->type |= AR_DOUBLE;
+ result->dbl=(double)pf;
+ ret = SYSINFO_RET_OK;
+ }
+ else
+ {
+ ret = SYSINFO_RET_FAIL;
+ }
+ return ret;
+#else
+ assert(result);
+
+ 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)
+int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- return SYSINFO_RET_FAIL;
+#define MEM_FNCLIST struct mem_fnclist_s
+MEM_FNCLIST
+{
+ char *mode;
+ int (*function)();
+};
+
+ MEM_FNCLIST fl[] =
+ {
+ {"free", VM_MEMORY_FREE},
+ {"shared", VM_MEMORY_SHARED},
+ {"total", VM_MEMORY_TOTAL},
+ {"buffers", VM_MEMORY_BUFFERS},
+ {"cached", VM_MEMORY_CACHED},
+ {0, 0}
+ };
+ char mode[MAX_STRING_LEN];
+ int i;
+
+ assert(result);
+
+ clean_result(result);
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, mode, MAX_STRING_LEN) != 0)
+ {
+ mode[0] = '\0';
+ }
+
+ if(mode[0] == '\0')
+ {
+ /* default parameter */
+ sprintf(mode, "total");
+ }
+
+ 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;
}
+