diff options
| author | guliver <guliver@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-02-01 15:06:08 +0000 |
|---|---|---|
| committer | guliver <guliver@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-02-01 15:06:08 +0000 |
| commit | bd1cb1231bdabecb7f96cfa3f51ad147bf07f2a1 (patch) | |
| tree | 8209f3655a40b64a5e07ba0e152ac82eda64c76d /src | |
| parent | c516c57fc707c8078edc2938b35e1bc5934637d3 (diff) | |
* added new metric: "system.boottime" to zabbix_agent
* added getPROC2() function (retrieve value from /proc file system by name)
git-svn-id: svn://svn.zabbix.com/trunk@3785 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
| -rw-r--r-- | src/libs/zbxsysinfo/common/common.c | 62 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/linux/Makefile.am | 2 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/linux/boottime.c | 32 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/linux/linux.c | 1 |
4 files changed, 96 insertions, 1 deletions
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c index 000ed873..f72a7fd0 100644 --- a/src/libs/zbxsysinfo/common/common.c +++ b/src/libs/zbxsysinfo/common/common.c @@ -925,6 +925,68 @@ int TCP_LISTEN(const char *cmd, const char *param, unsigned flags, AGENT_RESULT } #ifdef HAVE_PROC +int getPROC2(char *file, char *param, int fieldno, unsigned flags, int type, AGENT_RESULT *result) +{ + + FILE *f; + char *res; + char buf[MAX_STRING_LEN]; + int i; + int found; + unsigned long uValue; + double fValue; + + if (NULL == (f = fopen(file,"r"))) + { + return SYSINFO_RET_FAIL; + } + + // find line + found = 0; + while ( fgets(buf, MAX_STRING_LEN, f) != NULL ) + { + if (strncmp(buf, "btime", 5) == 0) + { + found = 1; + break; + } + } + + if (!found) return SYSINFO_RET_FAIL; + + // find field + res = (char *)strtok(buf, " "); // btime field1 field2 + for(i=1; i<=fieldno; i++) + { + res = (char *)strtok(NULL," "); + } + + zbx_fclose(f); + + if ( res == NULL ) + { + return SYSINFO_RET_FAIL; + } + + // convert field to right type + switch (type) + { + case AR_UINT64: + sscanf(res, "%lu", &uValue); + SET_UI64_RESULT(result, uValue); + break; + case AR_DOUBLE: + sscanf(res, "%lf", &fValue); + SET_DBL_RESULT(result, fValue); + break; + case AR_STRING: default: + SET_STR_RESULT(result, buf); + break; + } + + return SYSINFO_RET_OK; +} + int getPROC(char *file, int lineno, int fieldno, unsigned flags, AGENT_RESULT *result) { FILE *f; diff --git a/src/libs/zbxsysinfo/linux/Makefile.am b/src/libs/zbxsysinfo/linux/Makefile.am index 1905eecf..f261faf9 100644 --- a/src/libs/zbxsysinfo/linux/Makefile.am +++ b/src/libs/zbxsysinfo/linux/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS= -libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c +libzbxsysinfo2_a_SOURCES=cpu.c diskio.c diskspace.c inodes.c kernel.c memory.c net.c proc.c sensors.c swap.c uptime.c boottime.c lib_LIBRARIES=libzbxsysinfo2.a #libzbxsysinfo2_a_LIBADD = ../../zbxcommon/libzbxcommon.a ../../zbxcrypto/libzbxcrypto.a diff --git a/src/libs/zbxsysinfo/linux/boottime.c b/src/libs/zbxsysinfo/linux/boottime.c new file mode 100644 index 00000000..1f7cee0e --- /dev/null +++ b/src/libs/zbxsysinfo/linux/boottime.c @@ -0,0 +1,32 @@ +/* +** 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 "common.h" +#include "sysinfo.h" + +int SYSTEM_BOOTTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ + assert(result); + + init_result(result); + + return getPROC2("/proc/stat", "btime", 1, flags, AR_UINT64, result); +} diff --git a/src/libs/zbxsysinfo/linux/linux.c b/src/libs/zbxsysinfo/linux/linux.c index ca5b612c..484c37a3 100644 --- a/src/libs/zbxsysinfo/linux/linux.c +++ b/src/libs/zbxsysinfo/linux/linux.c @@ -76,6 +76,7 @@ ZBX_METRIC parameters_specific[]= {"system.uname", 0, SYSTEM_UNAME, 0, 0}, {"system.uptime", 0, SYSTEM_UPTIME, 0, 0}, + {"system.boottime", 0, SYSTEM_BOOTTIME, 0, 0}, {"system.users.num", 0, SYSTEM_UNUM, 0, 0}, {0} |
