summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.in3
-rw-r--r--src/libs/zbxsysinfo/aix/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/aix/aix.c6
-rw-r--r--src/libs/zbxsysinfo/aix/proc.c51
-rw-r--r--src/libs/zbxsysinfo/common/common.c234
-rw-r--r--src/libs/zbxsysinfo/freebsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/freebsd/freebsd.c6
-rw-r--r--src/libs/zbxsysinfo/freebsd/proc.c524
-rw-r--r--src/libs/zbxsysinfo/hpux/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/hpux/hpux.c6
-rw-r--r--src/libs/zbxsysinfo/hpux/proc.c50
-rw-r--r--src/libs/zbxsysinfo/linux/linux.c8
-rw-r--r--src/libs/zbxsysinfo/linux/proc.c629
-rw-r--r--src/libs/zbxsysinfo/netbsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/netbsd/netbsd.c6
-rw-r--r--src/libs/zbxsysinfo/netbsd/proc.c50
-rw-r--r--src/libs/zbxsysinfo/openbsd/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/openbsd/openbsd.c6
-rw-r--r--src/libs/zbxsysinfo/openbsd/proc.c50
-rw-r--r--src/libs/zbxsysinfo/osf/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/osf/osf.c6
-rw-r--r--src/libs/zbxsysinfo/osf/proc.c50
-rw-r--r--src/libs/zbxsysinfo/osx/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/osx/osx.c7
-rw-r--r--src/libs/zbxsysinfo/osx/proc.c50
-rw-r--r--src/libs/zbxsysinfo/solaris/Makefile.am2
-rwxr-xr-xsrc/libs/zbxsysinfo/solaris/SunOS5.9.c38
-rw-r--r--src/libs/zbxsysinfo/solaris/cpu.c155
-rw-r--r--src/libs/zbxsysinfo/solaris/kernel.c135
-rw-r--r--src/libs/zbxsysinfo/solaris/proc.c478
-rw-r--r--src/libs/zbxsysinfo/solaris/solaris.c41
-rw-r--r--src/libs/zbxsysinfo/solaris/swap.c117
-rw-r--r--src/libs/zbxsysinfo/unknown/Makefile.am2
-rw-r--r--src/libs/zbxsysinfo/unknown/proc.c523
-rw-r--r--src/libs/zbxsysinfo/unknown/unknown.c6
35 files changed, 2779 insertions, 474 deletions
diff --git a/configure.in b/configure.in
index 8985d92b..0b4d9638 100644
--- a/configure.in
+++ b/configure.in
@@ -54,7 +54,8 @@ AC_CHECK_HEADERS(stdio.h stdlib.h string.h unistd.h netdb.h signal.h \
sys/socket.h sys/loadavg.h netinet/in.h arpa/inet.h \
sys/swap.h sys/vmmeter.h strings.h sys/sysctl.h vm/vm_param.h \
sys/time.h kstat.h sys/syscall.h sys/sysmacros.h sys/procfs.h \
- stdint.h mach/host_info.h mach/mach_host.h knlist.h pwd.h)
+ stdint.h mach/host_info.h mach/mach_host.h knlist.h pwd.h sys/proc.h \
+ sys/var.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
diff --git a/src/libs/zbxsysinfo/aix/Makefile.am b/src/libs/zbxsysinfo/aix/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/aix/Makefile.am
+++ b/src/libs/zbxsysinfo/aix/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/aix/aix.c b/src/libs/zbxsysinfo/aix/aix.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/aix/aix.c
+++ b/src/libs/zbxsysinfo/aix/aix.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/aix/proc.c b/src/libs/zbxsysinfo/aix/proc.c
new file mode 100644
index 00000000..6c2e9a53
--- /dev/null
+++ b/src/libs/zbxsysinfo/aix/proc.c
@@ -0,0 +1,51 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index de20073e..c23695d0 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -56,6 +56,10 @@
#ifdef HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#endif
+
+#ifdef HAVE_SYS_PROC_H
+# include <sys/proc.h>
+#endif
/* Solaris */
#ifdef HAVE_SYS_PROCFS_H
/* This is needed to access the correct procfs.h definitions */
@@ -643,236 +647,6 @@ crc_buf2(p, clen, cval)
return (0);
}
-int PROC_NUM(const char *cmd, const char *param,double *value)
-{
-#if defined(HAVE_PROC_0_PSINFO)
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
-
- char filename[MAX_STRING_LEN];
- char procname[MAX_STRING_LEN];
-
- int fd;
-/* In the correct procfs.h, the structure name is psinfo_t */
- psinfo_t psinfo;
-
- int proccount=0;
-
- if(num_param(param) > 1)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- dir=opendir("/proc");
- if(NULL == dir)
- {
- return SYSINFO_RET_FAIL;
- }
-
- while((entries=readdir(dir))!=NULL)
- {
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/psinfo",MAX_STRING_LEN);
-
- if(stat(filename,&buf)==0)
- {
- fd = open (filename, O_RDONLY);
- if (fd != -1)
- {
- if (read (fd, &psinfo, sizeof(psinfo)) == -1)
- {
- close(fd);
- closedir(dir);
- return SYSINFO_RET_FAIL;
- }
- else
- {
- if(procname[0] != 0)
- {
- if(strcmp(procname, psinfo.pr_fname)==0)
- {
- proccount++;
- }
- }
- else
- {
- proccount++;
- }
- }
- close (fd);
- }
- else
- {
- continue;
- }
- }
- }
- closedir(dir);
- *value=(double)proccount;
- return SYSINFO_RET_OK;
-
-#elif defined(HAVE_PROC_1_STATUS)
-
-/*
-#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
-#define SDI(m) FSI("%s", m) // string info
-#define IDI(i) FSI("%i", i) // integer info
-*/
-
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
- char filename[MAX_STRING_LEN];
- char line[MAX_STRING_LEN];
-
- char name1[MAX_STRING_LEN];
- char name2[MAX_STRING_LEN];
-
- char procname[MAX_STRING_LEN];
- char usrname[MAX_STRING_LEN];
-
- int proc_ok = 0;
- int usr_ok = 0;
-
- struct passwd *usrinfo = NULL;
- int proc_uid = 0;
-
- FILE *f;
-
- int proccount=0;
-
- if(num_param(param) > 2)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
- {
- return SYSINFO_RET_FAIL;
- }
-
- if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
- {
- usrname[0] = 0;
- }
- else
- {
- if(usrname[0] != 0)
- {
- usrinfo = getpwnam(usrname);
- if(usrinfo == NULL)
- {
- /* incorrect user name */
- return SYSINFO_RET_FAIL;
- }
- }
- }
-
- dir=opendir("/proc");
- if(NULL == dir)
- {
- return SYSINFO_RET_FAIL;
- }
-
- while((entries=readdir(dir))!=NULL)
- {
- proc_ok = 0;
- usr_ok = 0;
-
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/status",MAX_STRING_LEN);
-
-/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
-/* Better approach: check if /proc/x/ is symbolic link */
- if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
- {
- continue;
- }
-
- if(stat(filename,&buf)==0)
- {
- f=fopen(filename,"r");
- if(f==NULL)
- {
- continue;
- }
-
- if(procname[0] != 0)
- {
- fgets(line,MAX_STRING_LEN,f);
- if(sscanf(line,"%s\t%s\n",name1,name2)==2)
- {
- if(strcmp(name1,"Name:") == 0)
- {
- if(strcmp(procname,name2)==0)
- {
- proc_ok = 1;
- }
- }
- }
-
- if(proc_ok == 0)
- {
- fclose(f);
- continue;
- }
- }
- else
- {
- proc_ok = 1;
- }
-
- if(usrinfo != NULL)
- {
- while(fgets(line, MAX_STRING_LEN, f) != NULL)
- {
- if(sscanf(line, "%s\t%i\n", name1, &proc_uid) != 2)
- {
- continue;
- }
-
- if(strcmp(name1,"Uid:") != 0)
- {
- continue;
- }
-
- if(usrinfo->pw_uid == proc_uid)
- {
- usr_ok = 1;
- break;
- }
- }
- }
- else
- {
- usr_ok = 1;
- }
-
- if(proc_ok && usr_ok)
- {
- proccount++;
- }
-
-
- fclose(f);
- }
- }
- closedir(dir);
- *value=(double)proccount;
- return SYSINFO_RET_OK;
-#else
- return SYSINFO_RET_FAIL;
-#endif
-}
-
int get_stat(const char *key, double *value)
{
FILE *f;
diff --git a/src/libs/zbxsysinfo/freebsd/Makefile.am b/src/libs/zbxsysinfo/freebsd/Makefile.am
index cae136ad..40d55d50 100644
--- a/src/libs/zbxsysinfo/freebsd/Makefile.am
+++ b/src/libs/zbxsysinfo/freebsd/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=freebsd.c cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=freebsd.c cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/freebsd/freebsd.c b/src/libs/zbxsysinfo/freebsd/freebsd.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/freebsd/freebsd.c
+++ b/src/libs/zbxsysinfo/freebsd/freebsd.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/freebsd/proc.c b/src/libs/zbxsysinfo/freebsd/proc.c
new file mode 100644
index 00000000..7063512f
--- /dev/null
+++ b/src/libs/zbxsysinfo/freebsd/proc.c
@@ -0,0 +1,524 @@
+/*
+ * ** 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>
+
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
+/* 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
+
+#ifdef HAVE_SYS_PROC_H
+# include <sys/proc.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"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+/* ??? */
+#if defined(HAVE_PROC_0_PSINFO)
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+
+ char filename[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ char pr_state = 0;
+
+ int fd;
+/* In the correct procfs.h, the structure name is psinfo_t */
+ psinfo_t psinfo;
+
+ int proccount=0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ /* running */
+ pr_state = SRUN;
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ /* awaiting an event */
+ pr_state = SSLEEP;
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ pr_state = SZOMB;
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+ stat_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/psinfo",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ fd = open (filename, O_RDONLY);
+ if (fd != -1)
+ {
+ if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ {
+ close(fd);
+ closedir(dir);
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+ if(procname[0] != 0)
+ {
+ if(strcmp(procname, psinfo.pr_fname) == 0)
+ {
+ proc_ok = 1;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ /* uid_t pr_uid; real user id */
+ if(usrinfo->pw_uid == psinfo.pr_uid)
+ {
+ usr_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ /* char pr_state; numeric lwp state */
+ if(psinfo.pr_lwp.pr_state == pr_state)
+ {
+ state_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok && state_ok)
+ {
+ proccount++;
+ }
+ }
+ close (fd);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ closedir(dir);
+ *value=(double)proccount;
+ return SYSINFO_RET_OK;
+
+#elif defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ *value = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
diff --git a/src/libs/zbxsysinfo/hpux/Makefile.am b/src/libs/zbxsysinfo/hpux/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/hpux/Makefile.am
+++ b/src/libs/zbxsysinfo/hpux/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/hpux/hpux.c b/src/libs/zbxsysinfo/hpux/hpux.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/hpux/hpux.c
+++ b/src/libs/zbxsysinfo/hpux/hpux.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/hpux/proc.c b/src/libs/zbxsysinfo/hpux/proc.c
new file mode 100644
index 00000000..11ffe263
--- /dev/null
+++ b/src/libs/zbxsysinfo/hpux/proc.c
@@ -0,0 +1,50 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/linux/linux.c b/src/libs/zbxsysinfo/linux/linux.c
index 6ccfffee..b187dbfe 100644
--- a/src/libs/zbxsysinfo/linux/linux.c
+++ b/src/libs/zbxsysinfo/linux/linux.c
@@ -90,8 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
-int PROC_MEMORY(const char *cmd, const char *param, double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -182,8 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
- {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd,root,sum"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/linux/proc.c b/src/libs/zbxsysinfo/linux/proc.c
index 62a809c5..65f00bbe 100644
--- a/src/libs/zbxsysinfo/linux/proc.c
+++ b/src/libs/zbxsysinfo/linux/proc.c
@@ -41,6 +41,12 @@
#include "common.h"
#include "sysinfo.h"
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+
#define MAX(a, b) ((a)>(b) ? (a) : (b))
#define MIN(a, b) ((a)<(b) ? (a) : (b))
@@ -53,37 +59,31 @@ int PROC_MEMORY(const char *cmd, const char *param, double *value)
{
#if defined(HAVE_PROC_1_STATUS)
-/*
- * #define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
- * #define SDI(m) FDI("'%s'", m) // string info
- * #define IDI(i) FDI("%i", i) // integer info
- */
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
- DIR *dir;
- struct dirent *entries;
- struct stat buf;
- char filename[MAX_STRING_LEN];
- char line[MAX_STRING_LEN];
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
- char name1[MAX_STRING_LEN];
- char name2[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
- char procname[MAX_STRING_LEN];
- char usrname[MAX_STRING_LEN];
- char mode[MAX_STRING_LEN];
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
- int proc_ok = 0;
- int usr_ok = 0;
- int do_task = DO_SUM;
-
- struct passwd *usrinfo = NULL;
- long int lvalue = 0;
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
- FILE *f;
+ FILE *f;
- double memsize = -1;
- int proccount = 0;
+ double memsize = -1;
+ int proccount = 0;
if(num_param(param) > 3)
{
@@ -94,207 +94,418 @@ int PROC_MEMORY(const char *cmd, const char *param, double *value)
{
return SYSINFO_RET_FAIL;
}
-
+
if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
{
usrname[0] = 0;
}
else
{
- if(usrname[0] != 0)
- {
- usrinfo = getpwnam(usrname);
- if(usrinfo == NULL)
- {
- /* incorrect user name */
- return SYSINFO_RET_FAIL;
- }
- }
- }
-
- if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
- {
- strscpy(mode, "sum");
- }
-
- if(strcmp(mode,"avg") == 0)
- {
- do_task = DO_AVG;
- }
- else if(strcmp(mode,"max") == 0)
- {
- do_task = DO_MAX;
- }
- else if(strcmp(mode,"min") == 0)
- {
- do_task = DO_MIN;
- }
- else if(strcmp(mode,"sum") == 0)
- {
- do_task = DO_SUM;
- }
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ /* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+ /* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"VmSize:") != 0)
+ {
+ continue;
+ }
+
+ proccount++;
+
+ if(strcasecmp(name2, "kB") == 0)
+ {
+ lvalue <<= 10;
+ }
+ else if(strcasecmp(name2, "mB") == 0)
+ {
+ lvalue <<= 20;
+ }
+ else if(strcasecmp(name2, "GB") == 0)
+ {
+ lvalue <<= 30;
+ }
+ else if(strcasecmp(name2, "TB") == 0)
+ {
+ lvalue <<= 40;
+ }
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+
+ break;
+ }
+ }
+
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ *value = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int PROC_NUM(const char *cmd, const char *param, double *value)
+{
+#if defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
dir=opendir("/proc");
if(NULL == dir)
{
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
}
while((entries=readdir(dir))!=NULL)
{
- proc_ok = 0;
- usr_ok = 0;
-
- strscpy(filename,"/proc/");
- strncat(filename,entries->d_name,MAX_STRING_LEN);
- strncat(filename,"/status",MAX_STRING_LEN);
-
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
/* Better approach: check if /proc/x/ is symbolic link */
- if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
- {
- continue;
- }
-
- if(stat(filename,&buf)==0)
- {
- f=fopen(filename,"r");
- if(f==NULL)
- {
- continue;
- }
-
- if(procname[0] != 0)
- {
- fgets(line,MAX_STRING_LEN,f);
- if(sscanf(line,"%s\t%s\n",name1,name2)==2)
- {
- if(strcmp(name1,"Name:") == 0)
- {
- if(strcmp(procname,name2)==0)
- {
- proc_ok = 1;
- }
- }
- }
-
- if(proc_ok == 0)
- {
- fclose(f);
- continue;
- }
- }
- else
- {
- proc_ok = 1;
- }
-
- if(usrinfo != NULL)
- {
- while(fgets(line, MAX_STRING_LEN, f) != NULL)
- {
-
- if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
- {
- continue;
- }
-
- if(strcmp(name1,"Uid:") != 0)
- {
- continue;
- }
-
- if(usrinfo->pw_uid == (uid_t)(lvalue))
- {
- usr_ok = 1;
- break;
- }
- }
- }
- else
- {
- usr_ok = 1;
- }
-
- if(proc_ok && usr_ok)
- {
- while(fgets(line, MAX_STRING_LEN, f) != NULL)
- {
-
- if(sscanf(line, "%s\t%li %s\n", name1, &lvalue, name2) != 3)
- {
- continue;
- }
-
- if(strcmp(name1,"VmSize:") != 0)
- {
- continue;
- }
-
- proccount++;
-
- if(strcasecmp(name2, "kB") == 0)
- {
- lvalue <<= 10;
- }
- else if(strcasecmp(name2, "mB") == 0)
- {
- lvalue <<= 20;
- }
- else if(strcasecmp(name2, "GB") == 0)
- {
- lvalue <<= 30;
- }
- else if(strcasecmp(name2, "TB") == 0)
- {
- lvalue <<= 40;
- }
-
- if(memsize < 0)
- {
- memsize = (double) lvalue;
- }
- else
- {
- if(do_task == DO_MAX)
- {
- memsize = MAX(memsize, (double) lvalue);
- }
- else if(do_task == DO_MIN)
- {
- memsize = MIN(memsize, (double) lvalue);
- }
- else
- {
- memsize += (double) lvalue;
- }
- }
-
- break;
- }
- }
-
-
- fclose(f);
- }
- }
- closedir(dir);
-
- if(memsize < 0)
- {
- /* incorrect process name */
- memsize = 0;
- }
-
- if(do_task == DO_AVG)
- {
- memsize /= (double)proccount;
- }
-
- *value = memsize;
- return SYSINFO_RET_OK;
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ *value = (double) proccount;
+ return SYSINFO_RET_OK;
#else
- return SYSINFO_RET_FAIL;
+ return SYSINFO_RET_FAIL;
#endif
}
-
diff --git a/src/libs/zbxsysinfo/netbsd/Makefile.am b/src/libs/zbxsysinfo/netbsd/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/netbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/netbsd/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/netbsd/netbsd.c b/src/libs/zbxsysinfo/netbsd/netbsd.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/netbsd/netbsd.c
+++ b/src/libs/zbxsysinfo/netbsd/netbsd.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/netbsd/proc.c b/src/libs/zbxsysinfo/netbsd/proc.c
new file mode 100644
index 00000000..11ffe263
--- /dev/null
+++ b/src/libs/zbxsysinfo/netbsd/proc.c
@@ -0,0 +1,50 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/openbsd/Makefile.am b/src/libs/zbxsysinfo/openbsd/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/openbsd/Makefile.am
+++ b/src/libs/zbxsysinfo/openbsd/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/openbsd/openbsd.c b/src/libs/zbxsysinfo/openbsd/openbsd.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/openbsd/openbsd.c
+++ b/src/libs/zbxsysinfo/openbsd/openbsd.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/openbsd/proc.c b/src/libs/zbxsysinfo/openbsd/proc.c
new file mode 100644
index 00000000..11ffe263
--- /dev/null
+++ b/src/libs/zbxsysinfo/openbsd/proc.c
@@ -0,0 +1,50 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/osf/Makefile.am b/src/libs/zbxsysinfo/osf/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/osf/Makefile.am
+++ b/src/libs/zbxsysinfo/osf/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/osf/osf.c b/src/libs/zbxsysinfo/osf/osf.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/osf/osf.c
+++ b/src/libs/zbxsysinfo/osf/osf.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/osf/proc.c b/src/libs/zbxsysinfo/osf/proc.c
new file mode 100644
index 00000000..11ffe263
--- /dev/null
+++ b/src/libs/zbxsysinfo/osf/proc.c
@@ -0,0 +1,50 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/osx/Makefile.am b/src/libs/zbxsysinfo/osx/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/osx/Makefile.am
+++ b/src/libs/zbxsysinfo/osx/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/osx/osx.c b/src/libs/zbxsysinfo/osx/osx.c
index 71da5581..edaacb03 100644
--- a/src/libs/zbxsysinfo/osx/osx.c
+++ b/src/libs/zbxsysinfo/osx/osx.c
@@ -90,7 +90,11 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +185,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
diff --git a/src/libs/zbxsysinfo/osx/proc.c b/src/libs/zbxsysinfo/osx/proc.c
new file mode 100644
index 00000000..11ffe263
--- /dev/null
+++ b/src/libs/zbxsysinfo/osx/proc.c
@@ -0,0 +1,50 @@
+/*
+ * ** 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>
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
diff --git a/src/libs/zbxsysinfo/solaris/Makefile.am b/src/libs/zbxsysinfo/solaris/Makefile.am
index 61445b63..17bd6d0c 100644
--- a/src/libs/zbxsysinfo/solaris/Makefile.am
+++ b/src/libs/zbxsysinfo/solaris/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/solaris/SunOS5.9.c b/src/libs/zbxsysinfo/solaris/SunOS5.9.c
index 8f208778..b966eb79 100755
--- a/src/libs/zbxsysinfo/solaris/SunOS5.9.c
+++ b/src/libs/zbxsysinfo/solaris/SunOS5.9.c
@@ -1044,6 +1044,9 @@ static int FREEMEM(const char *cmd, const char *parameter,double *value)
return SYSINFO_RET_OK;
}
+/*
+ * ADDED
+ *
static int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value)
{
int result = SYSINFO_RET_FAIL;
@@ -1075,6 +1078,7 @@ static int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value)
return result;
}
+*/
static int UPTIME(const char *cmd, const char *parameter,double *value)
{
@@ -1242,6 +1246,9 @@ int SWAPTOTAL(const char *cmd, const char *parameter,double *value)
return result;
}
+/*
+ * ADDED
+ *
static int SWAPIN(const char *cmd, const char *parameter,double *value)
{
kstat_ctl_t *kc;
@@ -1276,7 +1283,11 @@ static int SWAPIN(const char *cmd, const char *parameter,double *value)
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
}
+*/
+/*
+ * ADDED
+ *
static int SWAPOUT(const char *cmd, const char *parameter,double *value)
{
kstat_ctl_t *kc;
@@ -1311,7 +1322,7 @@ static int SWAPOUT(const char *cmd, const char *parameter,double *value)
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
}
-
+*/
static int PROCCOUNT(const char *cmd, const char *parameter,double *value)
{
@@ -1343,6 +1354,9 @@ static int PROCCOUNT(const char *cmd, const char *parameter,double *value)
return result;
}
+/*
+ * ADDED
+ *
static int PROCRUNNING(const char *cmd, const char *parameter,double *value)
{
DIR *dir;
@@ -1351,7 +1365,8 @@ static int PROCRUNNING(const char *cmd, const char *parameter,double *value)
char filename[MAX_STRING_LEN];
int fd;
-/* In the correct procfs.h, the structure name is psinfo_t */
+// In the correct procfs.h, the structure name is psinfo_t
+
psinfo_t psinfo;
int proccount=0;
@@ -1371,16 +1386,16 @@ static int PROCRUNNING(const char *cmd, const char *parameter,double *value)
if(stat(filename,&buf)==0)
{
fd = open (filename, O_RDONLY);
- if (fd != -1)
+ if(fd != -1)
{
- if (read (fd, &psinfo, sizeof(psinfo)) == -1)
+ if(read (fd, &psinfo, sizeof(psinfo)) == -1)
{
closedir(dir);
return SYSINFO_RET_FAIL;
}
else
{
- if (psinfo.pr_lwp.pr_state == SRUN)
+ if(psinfo.pr_lwp.pr_state == SRUN)
{
proccount++;
}
@@ -1397,7 +1412,11 @@ static int PROCRUNNING(const char *cmd, const char *parameter,double *value)
*value=(double)proccount;
return SYSINFO_RET_OK;
}
+*/
+/*
+ * ADDED
+ *
static int CSWITCHES(const char *cmd, const char *parameter,double *value)
{
kstat_ctl_t *kc;
@@ -1432,6 +1451,7 @@ static int CSWITCHES(const char *cmd, const char *parameter,double *value)
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
}
+*/
static int TCP_LISTEN(const char *cmd, const char *parameter,double *value)
{
@@ -1444,6 +1464,9 @@ static int TCP_LISTEN(const char *cmd, const char *parameter,double *value)
return EXECUTE(NULL, command, value);
}
+/*
+ * ADDED
+ *
static int INTERRUPTS(const char *cmd, const char *parameter,double *value)
{
kstat_ctl_t *kc;
@@ -1478,7 +1501,11 @@ static int INTERRUPTS(const char *cmd, const char *parameter,double *value)
return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
}
+*/
+/*
+ * ALREADY ADDED
+ *
#ifdef HAVE_LDAP
static int check_ldap(char *hostname, short port,int *value)
{
@@ -1536,6 +1563,7 @@ static int check_ldap(char *hostname, short port,int *value)
return SYSINFO_RET_OK;
}
#endif
+*/
COMMAND agent_commands[]=
/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
diff --git a/src/libs/zbxsysinfo/solaris/cpu.c b/src/libs/zbxsysinfo/solaris/cpu.c
index da971b3a..18f1f560 100644
--- a/src/libs/zbxsysinfo/solaris/cpu.c
+++ b/src/libs/zbxsysinfo/solaris/cpu.c
@@ -78,7 +78,6 @@
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
-
/* HP-UX */
#ifdef HAVE_SYS_PSTAT_H
#include <sys/pstat.h>
@@ -367,6 +366,160 @@ int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value)
#endif
#endif
}
+
+int SYSTEM_CPU_SWAPIN(const char *cmd, const char *parameter, double *value)
+{
+ kstat_ctl_t *kc;
+ kstat_t *k;
+ cpu_stat_t *cpu;
+
+ int cpu_count = 0;
+ double swapin= 0.0;
+
+ kc = kstat_open();
+
+ if(kc != NULL)
+ {
+ k = kc->kc_chain;
+ while (k != NULL)
+ {
+ if( (strncmp(k->ks_name, "cpu_stat", 8) == 0) &&
+ (kstat_read(kc, k, NULL) != -1) )
+ {
+ cpu = (cpu_stat_t*) k->ks_data;
+ /* uint_t swapin; // swapins */
+ swapin += (double) cpu->cpu_vminfo.swapin;
+ cpu_count += 1;
+ }
+ k = k->ks_next;
+ }
+ kstat_close(kc);
+ }
+
+ *value = swapin;
+
+ if(cpu_count == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
+
+int SYSTEM_CPU_SWAPOUT(const char *cmd, const char *parameter, double *value)
+{
+ kstat_ctl_t *kc;
+ kstat_t *k;
+ cpu_stat_t *cpu;
+
+ int cpu_count = 0;
+ double swapout = 0.0;
+
+ kc = kstat_open();
+
+ if(kc != NULL)
+ {
+ k = kc->kc_chain;
+ while (k != NULL)
+ {
+ if( (strncmp(k->ks_name, "cpu_stat", 8) == 0) &&
+ (kstat_read(kc, k, NULL) != -1) )
+ {
+ cpu = (cpu_stat_t*) k->ks_data;
+ /* uint_t swapout; // swapouts */
+ swapout += (double) cpu->cpu_vminfo.swapout;
+ cpu_count += 1;
+ }
+ k = k->ks_next;
+ }
+ kstat_close(kc);
+ }
+
+ *value = swapout;
+
+ if(cpu_count == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
+
+int SYSTEM_CPU_SWITCHES(const char *cmd, const char *parameter, double *value)
+{
+ kstat_ctl_t *kc;
+ kstat_t *k;
+ cpu_stat_t *cpu;
+
+ int cpu_count = 0;
+ double swt_count = 0.0;
+
+ kc = kstat_open();
+
+ if(kc != NULL)
+ {
+ k = kc->kc_chain;
+ while (k != NULL)
+ {
+ if( (strncmp(k->ks_name, "cpu_stat", 8) == 0) &&
+ (kstat_read(kc, k, NULL) != -1) )
+ {
+ cpu = (cpu_stat_t*) k->ks_data;
+ swt_count += (double) cpu->cpu_sysinfo.pswitch;
+ cpu_count += 1;
+ }
+ k = k->ks_next;
+ }
+ kstat_close(kc);
+ }
+
+ *value = swt_count;
+
+ if(cpu_count == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
+
+int SYSTEM_CPU_INTR(const char *cmd, const char *parameter, double *value)
+{
+ kstat_ctl_t *kc;
+ kstat_t *k;
+ cpu_stat_t *cpu;
+
+ int cpu_count = 0;
+ double intr_count = 0.0;
+
+ kc = kstat_open();
+
+ if(kc != NULL)
+ {
+ k = kc->kc_chain;
+ while (k != NULL)
+ {
+ if( (strncmp(k->ks_name, "cpu_stat", 8) == 0) &&
+ (kstat_read(kc, k, NULL) != -1) )
+ {
+ cpu = (cpu_stat_t*) k->ks_data;
+ intr_count += (double) cpu->cpu_sysinfo.intr;
+ cpu_count += 1;
+ }
+ k = k->ks_next;
+ }
+ kstat_close(kc);
+ }
+
+ *value = intr_count;
+
+ if(cpu_count == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value)
{
diff --git a/src/libs/zbxsysinfo/solaris/kernel.c b/src/libs/zbxsysinfo/solaris/kernel.c
new file mode 100644
index 00000000..75fb420f
--- /dev/null
+++ b/src/libs/zbxsysinfo/solaris/kernel.c
@@ -0,0 +1,135 @@
+/*
+** 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
+
+/* Solaris */
+#ifdef HAVE_SYS_SWAP_H
+ #include <sys/swap.h>
+#endif
+
+#ifdef HAVE_SYS_SYSCALL_H
+ #include <sys/syscall.h>
+#endif
+
+#ifdef HAVE_KSTAT_H
+ #include <kstat.h>
+#endif
+
+#ifdef HAVE_SYS_VAR_H
+# include <sys/var.h>
+#endif
+
+#include "common.h"
+#include "sysinfo.h"
+
+
+int SYSTEM_KERNEL_MAXPROC(const char *cmd, const char *parameter, double *value)
+{
+ int result = SYSINFO_RET_FAIL;
+ kstat_ctl_t *kc;
+ kstat_t *kt;
+ struct var *v;
+ int proc_count = 0;
+
+ kc = kstat_open();
+ if(kc)
+ {
+ kt = kstat_lookup(kc, "unix", 0, "var");
+ if(kt)
+ {
+ if( (kt->ks_type == KSTAT_TYPE_RAW) &&
+ (kstat_read(kc, kt, NULL) != -1)
+ )
+ {
+ v = (struct var *) kt->ks_data;
+
+ /* int v_proc; Max processes system wide */
+ proc_count = v->v_proc;
+ result = SYSINFO_RET_OK;
+ }
+ }
+ kstat_close(kc);
+ }
+
+ *value = (double) proc_count;
+
+ return result;
+}
+
diff --git a/src/libs/zbxsysinfo/solaris/proc.c b/src/libs/zbxsysinfo/solaris/proc.c
new file mode 100644
index 00000000..12c10619
--- /dev/null
+++ b/src/libs/zbxsysinfo/solaris/proc.c
@@ -0,0 +1,478 @@
+/*
+ * ** 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>
+
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
+/* 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
+
+#ifdef HAVE_SYS_PROC_H
+# include <sys/proc.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
+
+/* Solaris */
+#ifdef HAVE_SYS_SWAP_H
+ #include <sys/swap.h>
+#endif
+
+#ifdef HAVE_SYS_SYSCALL_H
+ #include <sys/syscall.h>
+#endif
+
+#ifdef HAVE_KSTAT_H
+ #include <kstat.h>
+#endif
+
+#ifdef HAVE_LDAP
+ #include <ldap.h>
+#endif
+
+#include "common.h"
+#include "sysinfo.h"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+
+#define MAX(a, b) ((a)>(b) ? (a) : (b))
+#define MIN(a, b) ((a)<(b) ? (a) : (b))
+
+#define DO_SUM 0
+#define DO_MAX 1
+#define DO_MIN 2
+#define DO_AVG 3
+
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+#if defined(HAVE_PROC_0_PSINFO)
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char mode[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int do_task = DO_SUM;
+
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ int fd;
+ psinfo_t psinfo;
+
+ double memsize = -1;
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, mode, MAX_STRING_LEN) != 0)
+ {
+ strscpy(mode, "sum");
+ }
+
+ if(strcmp(mode,"avg") == 0)
+ {
+ do_task = DO_AVG;
+ }
+ else if(strcmp(mode,"max") == 0)
+ {
+ do_task = DO_MAX;
+ }
+ else if(strcmp(mode,"min") == 0)
+ {
+ do_task = DO_MIN;
+ }
+ else if(strcmp(mode,"sum") == 0)
+ {
+ do_task = DO_SUM;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/psinfo",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ fd = open (filename, O_RDONLY);
+ if (fd != -1)
+ {
+ if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ {
+ close(fd);
+ closedir(dir);
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+ if(procname[0] != 0)
+ {
+ if(strcmp(procname, psinfo.pr_fname) == 0)
+ {
+ proc_ok = 1;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ /* uid_t pr_uid; real user id */
+ if(usrinfo->pw_uid == psinfo.pr_uid)
+ {
+ usr_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok)
+ {
+ lvalue = psinfo.pr_size;
+ lvalue <<= 10; /* kB to Byte */
+
+ if(memsize < 0)
+ {
+ memsize = (double) lvalue;
+ }
+ else
+ {
+ if(do_task == DO_MAX)
+ {
+ memsize = MAX(memsize, (double) lvalue);
+ }
+ else if(do_task == DO_MIN)
+ {
+ memsize = MIN(memsize, (double) lvalue);
+ }
+ else
+ {
+ memsize += (double) lvalue;
+ }
+ }
+ }
+ }
+ close (fd);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ closedir(dir);
+
+ if(memsize < 0)
+ {
+ /* incorrect process name */
+ memsize = 0;
+ }
+
+ if(do_task == DO_AVG)
+ {
+ memsize /= (double)proccount;
+ }
+
+ *value = memsize;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+#if defined(HAVE_PROC_0_PSINFO)
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+
+ char filename[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ char pr_state = 0;
+
+ int fd;
+/* In the correct procfs.h, the structure name is psinfo_t */
+ psinfo_t psinfo;
+
+ int proccount=0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ /* running */
+ pr_state = SRUN;
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ /* awaiting an event */
+ pr_state = SSLEEP;
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ pr_state = SZOMB;
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+ stat_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/psinfo",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ fd = open (filename, O_RDONLY);
+ if (fd != -1)
+ {
+ if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ {
+ close(fd);
+ closedir(dir);
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+ if(procname[0] != 0)
+ {
+ if(strcmp(procname, psinfo.pr_fname) == 0)
+ {
+ proc_ok = 1;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ /* uid_t pr_uid; real user id */
+ if(usrinfo->pw_uid == psinfo.pr_uid)
+ {
+ usr_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ /* char pr_state; numeric lwp state */
+ if(psinfo.pr_lwp.pr_state == pr_state)
+ {
+ stat_ok = 1;
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(proc_ok && usr_ok && stat_ok)
+ {
+ proccount++;
+ }
+ }
+ close (fd);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ closedir(dir);
+ *value=(double)proccount;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
diff --git a/src/libs/zbxsysinfo/solaris/solaris.c b/src/libs/zbxsysinfo/solaris/solaris.c
index 71da5581..cadd243f 100644
--- a/src/libs/zbxsysinfo/solaris/solaris.c
+++ b/src/libs/zbxsysinfo/solaris/solaris.c
@@ -66,6 +66,7 @@ int VFS_FS_INODE_TOTAL(const char *cmd, const char *mountPoint,double *value);
int KERNEL_MAXFILES(const char *cmd, const char *parameter,double *value);
int KERNEL_MAXPROC(const char *cmd, const char *parameter,double *value);
+int SYSTEM_KERNEL_MAXPROC(const char *cmd, const char *parameter, double *value);
int NET_IF_IBYTES1(const char *cmd, const char *parameter,double *value);
int NET_IF_IBYTES5(const char *cmd, const char *parameter,double *value);
@@ -90,17 +91,28 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD5(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD15(const char *cmd, const char *parameter,double *value);
+int SYSTEM_CPU_INTR(const char *cmd, const char *parameter, double *value);
+int SYSTEM_CPU_SWITCHES(const char *cmd, const char *parameter, double *value);
int SENSOR_TEMP1(const char *cmd, const char *parameter,double *value);
int SENSOR_TEMP2(const char *cmd, const char *parameter,double *value);
int SENSOR_TEMP3(const char *cmd, const char *parameter,double *value);
+
+int SYSTEM_SWAP_IN_NUM(const char *cmd, const char *param, double *value);
+int SYSTEM_SWAP_IN_PAGES(const char *cmd, const char *param, double *value);
+int SYSTEM_SWAP_OUT_NUM(const char *cmd, const char *param, double *value);
+int SYSTEM_SWAP_OUT_PAGES(const char *cmd, const char *param, double *value);
+
int SYSTEM_UPTIME(const char *cmd, const char *parameter,double *value);
int SYSTEM_SWAP_FREE(const char *cmd, const char *parameter,double *value);
@@ -148,7 +160,7 @@ COMMAND parameters_specific[]=
{"inodetotal[*]" ,VFS_FS_INODE_TOTAL, 0, "/"},
{"inodefree_perc[*]" ,VFS_FS_INODE_PFREE, 0, "/"},
{"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kern[maxproc]" ,KERNEL_MAXPROC, 0, 0},
+ {"kern[maxproc]" ,SYSTEM_KERNEL_MAXPROC, 0, 0},
{"md5sum[*]" ,0, VFS_FILE_MD5SUM, "/etc/services"},
{"memory[buffers]" ,VM_MEMORY_BUFFERS, 0, 0},
{"memory[cached]" ,VM_MEMORY_CACHED, 0, 0},
@@ -173,15 +185,18 @@ COMMAND parameters_specific[]=
{"system[uptime]" ,SYSTEM_UPTIME, 0, 0},
{"system[users]" ,EXECUTE, 0,"who|wc -l"},
{"version[zabbix_agent]", 0, AGENT_VERSION, 0},
+ {"system[interrupts]" ,SYSTEM_CPU_INTR, 0, 0},
+ {"system[switches]" ,SYSTEM_CPU_SWITCHES, 0, 0},
/* New naming */
{"agent.ping" ,AGENT_PING, 0, 0},
{"agent.version", 0, AGENT_VERSION, 0},
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
- {"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
+ {"kernel.maxproc" ,SYSTEM_KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},
@@ -258,6 +273,12 @@ COMMAND parameters_specific[]=
{"system.swap.free" ,SYSTEM_SWAP_FREE, 0, 0},
{"system.swap.total" ,SYSTEM_SWAP_TOTAL, 0, 0},
+ {"swap[in]" ,SYSTEM_SWAP_IN_NUM, 0, 0},
+ {"system.swap.in.num" ,SYSTEM_SWAP_IN_NUM, 0, 0},
+ {"system.swap.in.pages" ,SYSTEM_SWAP_IN_PAGES, 0, 0},
+ {"swap[out]" ,SYSTEM_SWAP_OUT_NUM, 0, 0},
+ {"system.swap.out.num" ,SYSTEM_SWAP_OUT_NUM, 0, 0},
+ {"system.swap.out.pages",SYSTEM_SWAP_OUT_PAGES, 0, 0},
{"system.uname" ,0, EXECUTE_STR, "uname -a"},
{"system.uptime" ,SYSTEM_UPTIME, 0, 0},
@@ -268,11 +289,13 @@ COMMAND parameters_specific[]=
{"swap[in]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b37-40"},
{"swap[out]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b41-44"},
-
- {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
+ {"system[interrupts]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b57-61"},
{"system[switches]" ,EXECUTE, 0, "vmstat -n 1 2|tail -1|cut -b62-67"},
***************************************/
+ {"system.cpu.switches" ,SYSTEM_CPU_SWITCHES, 0, 0},
+ {"system.cpu.intr" ,SYSTEM_CPU_INTR, 0, 0},
+
{"io[disk_io]" ,DISK_IO, 0, 0},
{"io[disk_rio]" ,DISK_RIO, 0, 0},
{"io[disk_wio]" ,DISK_WIO, 0, 0},
@@ -283,10 +306,12 @@ COMMAND parameters_specific[]=
{"system[proccount]" ,PROCCOUNT, 0, 0},
-#ifdef HAVE_PROC_LOADAVG
- {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
-#endif
+ #ifdef HAVE_PROC_LOADAVG
+ {"system[procrunning]" ,EXECUTE, 0, "cat /proc/loadavg|cut -f1 -d'/'|cut -f4 -d' '"},
+ #endif
+
+
/* {"tcp_count" ,EXECUTE, 0, "netstat -tn|grep EST|wc -l"}, */
{"net[listen_23]" ,TCP_LISTEN, 0, "0017"},
diff --git a/src/libs/zbxsysinfo/solaris/swap.c b/src/libs/zbxsysinfo/solaris/swap.c
index d4f13a53..52b209a8 100644
--- a/src/libs/zbxsysinfo/solaris/swap.c
+++ b/src/libs/zbxsysinfo/solaris/swap.c
@@ -268,3 +268,120 @@ int SYSTEM_SWAP_TOTAL(const char *cmd, const char *parameter,double *value)
#endif
#endif
}
+
+#define DO_SWP_IN 1
+#define DO_PG_IN 2
+#define DO_SWP_OUT 3
+#define DO_PG_OUT 4
+
+static int SYSTEM_SWAP(const char *cmd, const char *param, double *value)
+{
+ kstat_ctl_t *kc;
+ kstat_t *k;
+ cpu_stat_t *cpu;
+
+ int cpu_count = 0;
+ double swapin= 0.0;
+
+ int do_info;
+ char swp_info[MAX_STRING_LEN];
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, swp_info, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(strcmp(swp_info,"swapin") == 0)
+ {
+ do_info = DO_SWP_IN;
+ }
+ else if(strcmp(swp_info,"pgswapin") == 0)
+ {
+ do_info = DO_PG_IN;
+ }
+ else if(strcmp(swp_info,"swapout") == 0)
+ {
+ do_info = DO_SWP_OUT;
+ }
+ else if(strcmp(swp_info,"pgswapout") == 0)
+ {
+ do_info = DO_PG_OUT;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ kc = kstat_open();
+
+ if(kc != NULL)
+ {
+ k = kc->kc_chain;
+ while (k != NULL)
+ {
+ if( (strncmp(k->ks_name, "cpu_stat", 8) == 0) &&
+ (kstat_read(kc, k, NULL) != -1) )
+ {
+ cpu = (cpu_stat_t*) k->ks_data;
+ if(do_info == DO_SWP_IN)
+ {
+ /* uint_t swapin; // swapins */
+ swapin += (double) cpu->cpu_vminfo.swapin;
+ }
+ else if(do_info == DO_PG_IN)
+ {
+ /* uint_t pgswapin; // pages swapped in */
+ swapin += (double) cpu->cpu_vminfo.pgswapin;
+ }
+ else if(do_info == DO_SWP_OUT)
+ {
+ /* uint_t swapout; // swapout */
+ swapin += (double) cpu->cpu_vminfo.swapin;
+ }
+ else if(do_info == DO_PG_OUT)
+ {
+ /* uint_t pgswapout; // pages swapped out */
+ swapin += (double) cpu->cpu_vminfo.swapin;
+ }
+ cpu_count += 1;
+ }
+ k = k->ks_next;
+ }
+ kstat_close(kc);
+ }
+
+ *value = swapin;
+
+ if(cpu_count == 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ return SYSINFO_RET_OK;
+}
+
+int SYSTEM_SWAP_IN_NUM(const char *cmd, const char *param, double *value)
+{
+ return SYSTEM_SWAP(cmd, "swapin", value);
+}
+
+int SYSTEM_SWAP_IN_PAGES(const char *cmd, const char *param, double *value)
+{
+ return SYSTEM_SWAP(cmd, "pgswapin", value);
+}
+
+int SYSTEM_SWAP_OUT_NUM(const char *cmd, const char *param, double *value)
+{
+ return SYSTEM_SWAP(cmd, "swapout", value);
+}
+
+int SYSTEM_SWAP_OUT_PAGES(const char *cmd, const char *param, double *value)
+{
+ return SYSTEM_SWAP(cmd, "pgswapout", value);
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/Makefile.am b/src/libs/zbxsysinfo/unknown/Makefile.am
index 61445b63..4e57c84f 100644
--- a/src/libs/zbxsysinfo/unknown/Makefile.am
+++ b/src/libs/zbxsysinfo/unknown/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS=
-libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c sensors.c swap.c uptime.c
+libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c memory.c proc.c sensors.c swap.c uptime.c
lib_LIBRARIES=libzbxsysinfo2.a
libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a
diff --git a/src/libs/zbxsysinfo/unknown/proc.c b/src/libs/zbxsysinfo/unknown/proc.c
new file mode 100644
index 00000000..d76b05a7
--- /dev/null
+++ b/src/libs/zbxsysinfo/unknown/proc.c
@@ -0,0 +1,523 @@
+/*
+ * ** 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>
+
+#ifdef HAVE_PWD_H
+# include <pwd.h>
+#endif
+
+/* 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
+
+#ifdef HAVE_SYS_PROC_H
+# include <sys/proc.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"
+
+/*
+#define FDI(f, m) fprintf(stderr, "DEBUG INFO: " f "\n" , m) // show debug info to stderr
+#define SDI(m) FDI("%s", m) // string info
+#define IDI(i) FDI("%i", i) // integer info
+*/
+int PROC_MEMORY(const char *cmd, const char *param,double *value)
+{
+ /* in this moment this function for this platform unsupported */
+ return SYSINFO_RET_FAIL;
+}
+
+int PROC_NUM(const char *cmd, const char *param,double *value)
+{
+#if defined(HAVE_PROC_0_PSINFO)
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+
+ char filename[MAX_STRING_LEN];
+ char procname[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ char pr_state = 0;
+
+ int fd;
+/* In the correct procfs.h, the structure name is psinfo_t */
+ psinfo_t psinfo;
+
+ int proccount=0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ /* running */
+ pr_state = SRUN;
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ /* awaiting an event */
+ pr_state = SSLEEP;
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ pr_state = SZOMB;
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ usr_ok = 0;
+ stat_ok = 0;
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/psinfo",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ fd = open (filename, O_RDONLY);
+ if (fd != -1)
+ {
+ if(read(fd, &psinfo, sizeof(psinfo)) == -1)
+ {
+ close(fd);
+ closedir(dir);
+ return SYSINFO_RET_FAIL;
+ }
+ else
+ {
+ if(procname[0] != 0)
+ {
+ if(strcmp(procname, psinfo.pr_fname) == 0)
+ {
+ proc_ok = 1;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ /* uid_t pr_uid; real user id */
+ if(usrinfo->pw_uid == psinfo.pr_uid)
+ {
+ usr_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ /* char pr_state; numeric lwp state */
+ if(psinfo.pr_lwp.pr_state == pr_state)
+ {
+ state_ok = 1;
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && usr_ok && state_ok)
+ {
+ proccount++;
+ }
+ }
+ close (fd);
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ closedir(dir);
+ *value=(double)proccount;
+ return SYSINFO_RET_OK;
+
+#elif defined(HAVE_PROC_1_STATUS)
+
+ DIR *dir;
+ struct dirent *entries;
+ struct stat buf;
+ char filename[MAX_STRING_LEN];
+ char line[MAX_STRING_LEN];
+
+ char name1[MAX_STRING_LEN];
+ char name2[MAX_STRING_LEN];
+
+ char procname[MAX_STRING_LEN];
+ char usrname[MAX_STRING_LEN];
+ char procstat[MAX_STRING_LEN];
+
+ int proc_ok = 0;
+ int usr_ok = 0;
+ int stat_ok = 0;
+
+ struct passwd *usrinfo = NULL;
+ long int lvalue = 0;
+
+ FILE *f;
+
+ int proccount = 0;
+
+ if(num_param(param) > 3)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, procname, MAX_STRING_LEN) != 0)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 2, usrname, MAX_STRING_LEN) != 0)
+ {
+ usrname[0] = 0;
+ }
+ else
+ {
+ if(usrname[0] != 0)
+ {
+ usrinfo = getpwnam(usrname);
+ if(usrinfo == NULL)
+ {
+ /* incorrect user name */
+ return SYSINFO_RET_FAIL;
+ }
+ }
+ }
+
+ if(get_param(param, 3, procstat, MAX_STRING_LEN) != 0)
+ {
+ strscpy(procstat,"all");
+ }
+
+ if(strcmp(procstat,"run") == 0)
+ {
+ strscpy(procstat,"R");
+ }
+ else if(strcmp(procstat,"sleep") == 0)
+ {
+ strscpy(procstat,"S");
+ }
+ else if(strcmp(procstat,"zomb") == 0)
+ {
+ strscpy(procstat,"Z");
+ }
+ else if(strcmp(procstat,"all") == 0)
+ {
+ procstat[0] = 0;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ dir=opendir("/proc");
+ if(NULL == dir)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ while((entries=readdir(dir))!=NULL)
+ {
+ proc_ok = 0;
+ stat_ok = 0;
+ usr_ok = 0;
+
+/* Self is a symbolic link. It leads to incorrect results for proc_cnt[zabbix_agentd] */
+/* Better approach: check if /proc/x/ is symbolic link */
+ if(strncmp(entries->d_name,"self",MAX_STRING_LEN) == 0)
+ {
+ continue;
+ }
+
+ strscpy(filename,"/proc/");
+ strncat(filename,entries->d_name,MAX_STRING_LEN);
+ strncat(filename,"/status",MAX_STRING_LEN);
+
+ if(stat(filename,&buf)==0)
+ {
+ f=fopen(filename,"r");
+ if(f==NULL)
+ {
+ continue;
+ }
+
+ if(procname[0] != 0)
+ {
+ fgets(line,MAX_STRING_LEN,f);
+ if(sscanf(line,"%s\t%s\n",name1,name2)==2)
+ {
+ if(strcmp(name1,"Name:") == 0)
+ {
+ if(strcmp(procname,name2)==0)
+ {
+ proc_ok = 1;
+ }
+ }
+ }
+
+ if(proc_ok == 0)
+ {
+ fclose(f);
+ continue;
+ }
+ }
+ else
+ {
+ proc_ok = 1;
+ }
+
+ if(procstat[0] != 0)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%s\n", name1, name2) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"State:") != 0)
+ {
+ continue;
+ }
+
+ if(strcmp(name2, procstat))
+ {
+ stat_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ stat_ok = 1;
+ }
+
+ if(usrinfo != NULL)
+ {
+ while(fgets(line, MAX_STRING_LEN, f) != NULL)
+ {
+
+ if(sscanf(line, "%s\t%li\n", name1, &lvalue) != 2)
+ {
+ continue;
+ }
+
+ if(strcmp(name1,"Uid:") != 0)
+ {
+ continue;
+ }
+
+ if(usrinfo->pw_uid == (uid_t)(lvalue))
+ {
+ usr_ok = 1;
+ break;
+ }
+ }
+ }
+ else
+ {
+ usr_ok = 1;
+ }
+
+ if(proc_ok && stat_ok && usr_ok)
+ {
+ proccount++;
+ }
+
+ fclose(f);
+ }
+ }
+ closedir(dir);
+
+ *value = (double) proccount;
+ return SYSINFO_RET_OK;
+#else
+ return SYSINFO_RET_FAIL;
+#endif
+}
+
diff --git a/src/libs/zbxsysinfo/unknown/unknown.c b/src/libs/zbxsysinfo/unknown/unknown.c
index 71da5581..b187dbfe 100644
--- a/src/libs/zbxsysinfo/unknown/unknown.c
+++ b/src/libs/zbxsysinfo/unknown/unknown.c
@@ -90,7 +90,10 @@ int DISKWRITEBLKS15(const char *cmd, const char *parameter,double *value);
int AGENT_PING(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_SHARED(const char *cmd, const char *parameter,double *value);
int VM_MEMORY_TOTAL(const char *cmd, const char *parameter,double *value);
+
int PROC_NUM(const char *cmd, const char *parameter,double *value);
+int PROC_MEMORY(const char *cmd, const char *param, double *value);
+
int PROCCOUNT(const char *cmd, const char *parameter,double *value);
int SYSTEM_CPU_LOAD1(const char *cmd, const char *parameter,double *value);
@@ -181,7 +184,8 @@ COMMAND parameters_specific[]=
{"kernel.maxfiles]" ,KERNEL_MAXFILES, 0, 0},
{"kernel.maxproc" ,KERNEL_MAXPROC, 0, 0},
- {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.num[*]" ,PROC_NUM, 0, "inetd"},
+ {"proc.mem[*]" ,PROC_MEMORY, 0, "inetd"},
{"vm.memory.total" ,VM_MEMORY_TOTAL, 0, 0},
{"vm.memory.shared" ,VM_MEMORY_SHARED, 0, 0},