summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-10 06:07:17 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-10 06:07:17 +0000
commitcfac7fe7b88441d79b2527394a48763dea5fa588 (patch)
tree4302bfe3000e7b5a0d3fcdf1daf77d9640cd6c48 /src
parentccfc9ac80f6d32806d0fe192740e77f177ee53f1 (diff)
downloadzabbix-cfac7fe7b88441d79b2527394a48763dea5fa588.tar.gz
zabbix-cfac7fe7b88441d79b2527394a48763dea5fa588.tar.xz
zabbix-cfac7fe7b88441d79b2527394a48763dea5fa588.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@1853 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxsysinfo/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/inodes.c153
-rw-r--r--src/libs/zbxsysinfo/swap.c270
-rw-r--r--src/libs/zbxsysinfo/sysinfo.c111
4 files changed, 424 insertions, 112 deletions
diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am
index ad4c174d..956d6e4a 100644
--- a/src/libs/zbxsysinfo/Makefile.am
+++ b/src/libs/zbxsysinfo/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS=.
lib_LIBRARIES=libzbxsysinfo.a
-libzbxsysinfo_a_SOURCES=sysinfo.c
+libzbxsysinfo_a_SOURCES=inodes.c sysinfo.c
libzbxsysinfo_a_LIBADD = ../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/inodes.c b/src/libs/zbxsysinfo/inodes.c
new file mode 100644
index 00000000..b97be09b
--- /dev/null
+++ b/src/libs/zbxsysinfo/inodes.c
@@ -0,0 +1,153 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#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>
+
+/* Linux */
+#ifdef HAVE_SYS_VFS_H
+ #include <sys/vfs.h>
+#endif
+/* Solaris */
+#ifdef HAVE_SYS_STATVFS_H
+ #include <sys/statvfs.h>
+#endif
+
+#include "common.h"
+#include "sysinfo.h"
+
+#include "md5.h"
+
+int INODEFREE(const char *cmd, const char *mountPoint,double *value)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+
+ if ( statvfs( (char *)mountPoint, &s) != 0 )
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ *value=s.f_favail;
+ return SYSINFO_RET_OK;
+#else
+ struct statfs s;
+ long blocks_used;
+ long blocks_percent_used;
+
+ if ( statfs( (char *)mountPoint, &s) != 0 )
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if ( s.f_blocks > 0 ) {
+ blocks_used = s.f_blocks - s.f_bfree;
+ blocks_percent_used = (long)
+ (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
+
+/* printf(
+ "%7.0f %7.0f %7.0f %5ld%% %s\n"
+ ,s.f_blocks * (s.f_bsize / 1024.0)
+ ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
+ ,s.f_bavail * (s.f_bsize / 1024.0)
+ ,blocks_percent_used
+ ,mountPoint);
+*/
+ *value=s.f_ffree;
+ return SYSINFO_RET_OK;
+
+ }
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int INODETOTAL(const char *cmd, const char *mountPoint,double *value)
+{
+#ifdef HAVE_SYS_STATVFS_H
+ struct statvfs s;
+
+ if ( statvfs( (char *)mountPoint, &s) != 0 )
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ *value=s.f_files;
+ return SYSINFO_RET_OK;
+#else
+ struct statfs s;
+ long blocks_used;
+ long blocks_percent_used;
+
+ if ( statfs( (char *)mountPoint, &s) != 0 )
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if ( s.f_blocks > 0 ) {
+ blocks_used = s.f_blocks - s.f_bfree;
+ blocks_percent_used = (long)
+ (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
+
+/* printf(
+ "%7.0f %7.0f %7.0f %5ld%% %s\n"
+ ,s.f_blocks * (s.f_bsize / 1024.0)
+ ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
+ ,s.f_bavail * (s.f_bsize / 1024.0)
+ ,blocks_percent_used
+ ,mountPoint);
+*/
+ *value=s.f_files;
+ return SYSINFO_RET_OK;
+
+ }
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int INODEFREE_PERC(const char *cmd, const char *mountPoint,double *value)
+{
+ double total;
+ double free;
+
+ if(SYSINFO_RET_OK != INODETOTAL(cmd, mountPoint, &total))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(SYSINFO_RET_OK != INODEFREE(cmd, mountPoint, &free))
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(total == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ *value = 100*free/total;
+ return SYSINFO_RET_OK;
+}
diff --git a/src/libs/zbxsysinfo/swap.c b/src/libs/zbxsysinfo/swap.c
new file mode 100644
index 00000000..f0b526a7
--- /dev/null
+++ b/src/libs/zbxsysinfo/swap.c
@@ -0,0 +1,270 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#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"
+
+#include "md5.h"
+
+/* Solaris. */
+#ifndef HAVE_SYSINFO_FREESWAP
+#ifdef HAVE_SYS_SWAP_SWAPTABLE
+void get_swapinfo(double *total, double *fr)
+{
+ register int cnt, i, page_size;
+/* Support for >2Gb */
+/* register int t, f;*/
+ double t, f;
+ struct swaptable *swt;
+ struct swapent *ste;
+ static char path[256];
+
+ /* get total number of swap entries */
+ cnt = swapctl(SC_GETNSWP, 0);
+
+ /* allocate enough space to hold count + n swapents */
+ swt = (struct swaptable *)malloc(sizeof(int) +
+ cnt * sizeof(struct swapent));
+
+ if (swt == NULL)
+ {
+ *total = 0;
+ *fr = 0;
+ return;
+ }
+ swt->swt_n = cnt;
+
+/* fill in ste_path pointers: we don't care about the paths, so we
+point them all to the same buffer */
+ ste = &(swt->swt_ent[0]);
+ i = cnt;
+ while (--i >= 0)
+ {
+ ste++->ste_path = path;
+ }
+
+ /* grab all swap info */
+ swapctl(SC_LIST, swt);
+
+ /* walk thru the structs and sum up the fields */
+ t = f = 0;
+ ste = &(swt->swt_ent[0]);
+ i = cnt;
+ while (--i >= 0)
+ {
+ /* dont count slots being deleted */
+ if (!(ste->ste_flags & ST_INDEL) &&
+ !(ste->ste_flags & ST_DOINGDEL))
+ {
+ t += ste->ste_pages;
+ f += ste->ste_free;
+ }
+ ste++;
+ }
+
+ page_size=getpagesize();
+
+ /* fill in the results */
+ *total = page_size*t;
+ *fr = page_size*f;
+ free(swt);
+}
+#endif
+#endif
+
+int SWAPFREE(const char *cmd, const char *parameter,double *value)
+{
+#ifdef HAVE_SYSINFO_FREESWAP
+ struct sysinfo info;
+
+ if( 0 == sysinfo(&info))
+ {
+#ifdef HAVE_SYSINFO_MEM_UNIT
+ *value=(double)info.freeswap * (double)info.mem_unit;
+#else
+ *value=(double)info.freeswap;
+#endif
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+/* Solaris */
+#else
+#ifdef HAVE_SYS_SWAP_SWAPTABLE
+ double swaptotal,swapfree;
+
+ get_swapinfo(&swaptotal,&swapfree);
+
+ *value=swapfree;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+#endif
+}
+
+int SWAPTOTAL(const char *cmd, const char *parameter,double *value)
+{
+#ifdef HAVE_SYSINFO_TOTALSWAP
+ struct sysinfo info;
+
+ if( 0 == sysinfo(&info))
+ {
+#ifdef HAVE_SYSINFO_MEM_UNIT
+ *value=(double)info.totalswap * (double)info.mem_unit;
+#else
+ *value=(double)info.totalswap;
+#endif
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+/* Solaris */
+#else
+#ifdef HAVE_SYS_SWAP_SWAPTABLE
+ double swaptotal,swapfree;
+
+ get_swapinfo(&swaptotal,&swapfree);
+
+ *value=(double)swaptotal;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+#endif
+}
diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c
index a472138e..9139733a 100644
--- a/src/libs/zbxsysinfo/sysinfo.c
+++ b/src/libs/zbxsysinfo/sysinfo.c
@@ -1358,117 +1358,6 @@ int NETLOADOUT15(const char *cmd, const char *parameter,double *value)
return get_stat(key,value);
}
-
-int INODEFREE(const char *cmd, const char *mountPoint,double *value)
-{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_favail;
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_ffree;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
-#endif
-}
-
-int INODETOTAL(const char *cmd, const char *mountPoint,double *value)
-{
-#ifdef HAVE_SYS_STATVFS_H
- struct statvfs s;
-
- if ( statvfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value=s.f_files;
- return SYSINFO_RET_OK;
-#else
- struct statfs s;
- long blocks_used;
- long blocks_percent_used;
-
- if ( statfs( (char *)mountPoint, &s) != 0 )
- {
- return SYSINFO_RET_FAIL;
- }
-
- if ( s.f_blocks > 0 ) {
- blocks_used = s.f_blocks - s.f_bfree;
- blocks_percent_used = (long)
- (blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
-
-/* printf(
- "%7.0f %7.0f %7.0f %5ld%% %s\n"
- ,s.f_blocks * (s.f_bsize / 1024.0)
- ,(s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)
- ,s.f_bavail * (s.f_bsize / 1024.0)
- ,blocks_percent_used
- ,mountPoint);
-*/
- *value=s.f_files;
- return SYSINFO_RET_OK;
-
- }
- return SYSINFO_RET_FAIL;
-#endif
-}
-
-int INODEFREE_PERC(const char *cmd, const char *mountPoint,double *value)
-{
- double total;
- double free;
-
- if(SYSINFO_RET_OK != INODETOTAL(cmd, mountPoint, &total))
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(SYSINFO_RET_OK != INODEFREE(cmd, mountPoint, &free))
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(total == 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- *value = 100*free/total;
- return SYSINFO_RET_OK;
-}
-
int DISKUSED_PERC(const char *cmd, const char *mountPoint,double *value)
{
double total;