/* ** 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 #include #include #include #include #include #include /* Definitions of uint32_t under OS/X */ #ifdef HAVE_STDINT_H #include #endif #ifdef HAVE_STRINGS_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_DIRENT_H #include #endif /* Linux */ #ifdef HAVE_SYS_VFS_H #include #endif #ifdef HAVE_SYS_SYSINFO_H #include #endif /* Solaris */ #ifdef HAVE_SYS_STATVFS_H #include #endif /* Solaris */ #ifdef HAVE_SYS_PROCFS_H /* This is needed to access the correct procfs.h definitions */ #define _STRUCTURED_PROC 1 #include #endif #ifdef HAVE_SYS_LOADAVG_H #include #endif #ifdef HAVE_SYS_SOCKET_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_ARPA_INET_H #include #endif /* OpenBSD/Solaris */ #ifdef HAVE_SYS_PARAM_H #include #endif #ifdef HAVE_SYS_MOUNT_H #include #endif /* HP-UX */ #ifdef HAVE_SYS_PSTAT_H #include #endif #ifdef HAVE_NETDB_H #include #endif /* Solaris */ #ifdef HAVE_SYS_SWAP_H #include #endif /* FreeBSD */ #ifdef HAVE_SYS_SYSCTL_H #include #endif /* Solaris */ #ifdef HAVE_SYS_SYSCALL_H #include #endif /* FreeBSD */ #ifdef HAVE_VM_VM_PARAM_H #include #endif /* FreeBSD */ #ifdef HAVE_SYS_VMMETER_H #include #endif /* FreeBSD */ #ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_MACH_HOST_INFO_H #include #endif #ifdef HAVE_MACH_MACH_HOST_H #include #endif /* AIX CPU */ #ifdef HAVE_KNLIST_H #include #endif #ifdef HAVE_KSTAT_H #include #endif #ifdef HAVE_LDAP #include #endif #include "common.h" #include "sysinfo.h" int CPUIDLE1(const char *cmd, const char *param,double *value) { return get_stat("cpu[idle1]",value); } int CPUIDLE5(const char *cmd, const char *param,double *value) { return get_stat("cpu[idle5]",value); } int CPUIDLE15(const char *cmd, const char *param,double *value) { return get_stat("cpu[idle15]",value); } int CPUNICE1(const char *cmd, const char *param,double *value) { return get_stat("cpu[nice1]",value); } int CPUNICE5(const char *cmd, const char *param,double *value) { return get_stat("cpu[nice5]",value); } int CPUNICE15(const char *cmd, const char *param,double *value) { return get_stat("cpu[nice15]",value); } int CPUUSER1(const char *cmd, const char *param,double *value) { return get_stat("cpu[user1]",value); } int CPUUSER5(const char *cmd, const char *param,double *value) { return get_stat("cpu[user5]",value); } int CPUUSER15(const char *cmd, const char *param,double *value) { return get_stat("cpu[user15]",value); } int CPUSYSTEM1(const char *cmd, const char *param,double *value) { return get_stat("cpu[system1]",value); } int CPUSYSTEM5(const char *cmd, const char *param,double *value) { return get_stat("cpu[system5]",value); } int CPUSYSTEM15(const char *cmd, const char *param,double *value) { return get_stat("cpu[system15]",value); } /* AIX CPU info */ #ifdef HAVE_KNLIST_H static int getloadavg_kmem(double loadavg[], int nelem) { struct nlist nl; int kmem, i; long avenrun[3]; nl.n_name = "avenrun"; nl.n_value = 0; if(knlist(&nl, 1, sizeof(nl))) { return FAIL; } if((kmem = open("/dev/kmem", 0, 0)) <= 0) { return FAIL; } if(pread(kmem, avenrun, sizeof(avenrun), nl.n_value) < sizeof(avenrun)) { return FAIL; } for(i=0;ivalue.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; if(getloadavg_kmem(loadavg,3) == FAIL) { return STSINFO_RET_FAIL; } *value=loadavg[0]; return SYSINFO_RET_OK; #else return SYSINFO_RET_FAIL; #endif #endif #endif #endif #endif } int PROCLOAD5(const char *cmd, const char *parameter,double *value) { #ifdef HAVE_GETLOADAVG double load[3]; if(getloadavg(load, 3)) { *value=load[1]; return SYSINFO_RET_OK; } else { return SYSINFO_RET_FAIL; } #else #ifdef HAVE_SYS_PSTAT_H struct pst_dynamic dyn; if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) { return SYSINFO_RET_FAIL; } else { *value=(double)dyn.psd_avg_5_min; return SYSINFO_RET_OK; } #else #ifdef HAVE_PROC_LOADAVG return getPROC("/proc/loadavg",1,2,value); #else #ifdef HAVE_KSTAT_H static kstat_ctl_t *kc = NULL; kstat_t *ks; kstat_named_t *kn; if (!kc && !(kc = kstat_open())) { return SYSINFO_RET_FAIL; } if (!(ks = kstat_lookup(kc, "unix", 0, "system_misc")) || kstat_read(kc, ks, 0) == -1 || !(kn = kstat_data_lookup(ks,"avenrun_5min"))) { return SYSINFO_RET_FAIL; } *value=(double)kn->value.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; if(getloadavg_kmem(loadavg,3) == FAIL) { return STSINFO_RET_FAIL; } *value=loadavg[1]; return SYSINFO_RET_OK; #else return SYSINFO_RET_FAIL; #endif #endif #endif #endif #endif } int PROCLOAD15(const char *cmd, const char *parameter,double *value) { #ifdef HAVE_GETLOADAVG double load[3]; if(getloadavg(load, 3)) { *value=load[2]; return SYSINFO_RET_OK; } else { return SYSINFO_RET_FAIL; } #else #ifdef HAVE_SYS_PSTAT_H struct pst_dynamic dyn; if (pstat_getdynamic(&dyn, sizeof(dyn), 1, 0) == -1) { return SYSINFO_RET_FAIL; } else { *value=(double)dyn.psd_avg_15_min; return SYSINFO_RET_OK; } #else #ifdef HAVE_PROC_LOADAVG return getPROC("/proc/loadavg",1,3,value); #else #ifdef HAVE_KSTAT_H static kstat_ctl_t *kc = NULL; kstat_t *ks; kstat_named_t *kn; if (!kc && !(kc = kstat_open())) { return SYSINFO_RET_FAIL; } if (!(ks = kstat_lookup(kc, "unix", 0, "system_misc")) || kstat_read(kc, ks, 0) == -1 || !(kn = kstat_data_lookup(ks,"avenrun_15min"))) { return SYSINFO_RET_FAIL; } *value=(double)kn->value.ul/256.0; return SYSINFO_RET_OK; #else #ifdef HAVE_KNLIST_H double loadavg[3]; if(getloadavg_kmem(loadavg,3) == FAIL) { return STSINFO_RET_FAIL; } *value=loadavg[2]; return SYSINFO_RET_OK; #else return SYSINFO_RET_FAIL; #endif #endif #endif #endif #endif }