summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-05-14 07:55:56 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-05-14 07:55:56 +0000
commit2a12f2bb704fd9b5777e0c06499874f2cfddbcb7 (patch)
tree680907c746f1527df97951adb1c67ea68f55e330
parent6b4eabad631afa94d90ae9082438c1077b9c919e (diff)
downloadzabbix-2a12f2bb704fd9b5777e0c06499874f2cfddbcb7.tar.gz
zabbix-2a12f2bb704fd9b5777e0c06499874f2cfddbcb7.tar.xz
zabbix-2a12f2bb704fd9b5777e0c06499874f2cfddbcb7.zip
- [DEV-163] added support of perf_counter[path<,period>]
git-svn-id: svn://svn.zabbix.com/trunk@5700 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog1
-rw-r--r--include/perfmon.h1
-rw-r--r--src/libs/zbxjson/json.c4
-rw-r--r--src/libs/zbxsysinfo/win32/pdhmon.c62
-rw-r--r--src/libs/zbxwin32/perfmon.c50
-rw-r--r--src/zabbix_agent/perfstat.c354
-rw-r--r--src/zabbix_agent/perfstat.h18
-rw-r--r--src/zabbix_agent/stats.c15
-rw-r--r--src/zabbix_agent/stats.h2
-rw-r--r--src/zabbix_agent/zabbix_agentd.c5
10 files changed, 253 insertions, 259 deletions
diff --git a/ChangeLog b/ChangeLog
index 22840d2d..5c3eb5f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
Changes for 1.5.3
+ - [DEV-163] added support of perf_counter[path<,period>] (Sasha)
- [DEV-169] improved msg functionality in GUI (Artem)
- [DEV-149] added hosts masss update functionality (Artem)
- [DEV-167] added support of Host Template=<template> in actions (Sasha)
diff --git a/include/perfmon.h b/include/perfmon.h
index 77b15f08..8aa81dfa 100644
--- a/include/perfmon.h
+++ b/include/perfmon.h
@@ -55,5 +55,6 @@ typedef struct perfcounter PERFCOUNTER;
extern PERFCOUNTER *PerfCounterList;
char *GetCounterName(unsigned long index);
+int check_counter_path(char *counterPath);
#endif /* ZABBIX_PERFMON_H */
diff --git a/src/libs/zbxjson/json.c b/src/libs/zbxjson/json.c
index 3ef440ca..505d12d5 100644
--- a/src/libs/zbxjson/json.c
+++ b/src/libs/zbxjson/json.c
@@ -549,7 +549,7 @@ static const char *zbx_json_decodestring(const char *p, char *string, size_t len
return ++p;
}
state = 1;
- } else if (state == 1 && o - string < len - 1/*'\0'*/) {
+ } else if (state == 1 && (size_t)(o - string) < len - 1/*'\0'*/) {
if (*p == '\\') {
switch (*++p) {
case '"':
@@ -585,7 +585,7 @@ static const char *zbx_json_decodeint(const char *p, char *string, size_t len)
if ((*p < '0' || *p > '9') && *p != '-') {
*o = '\0';
return p;
- } else if (o - string < len - 1/*'\0'*/)
+ } else if ((size_t)(o - string) < len - 1/*'\0'*/)
*o++ = *p;
p++;
}
diff --git a/src/libs/zbxsysinfo/win32/pdhmon.c b/src/libs/zbxsysinfo/win32/pdhmon.c
index d73cfb40..9428ed61 100644
--- a/src/libs/zbxsysinfo/win32/pdhmon.c
+++ b/src/libs/zbxsysinfo/win32/pdhmon.c
@@ -58,53 +58,47 @@ int PERF_MONITOR(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
PDH_STATUS status;
PDH_RAW_COUNTER rawData, rawData2;
PDH_FMT_COUNTERVALUE counterValue;
- char counter_path[PDH_MAX_COUNTER_PATH];
- PDH_COUNTER_PATH_ELEMENTS *cpe = NULL;
- int ret = SYSINFO_RET_FAIL, is_numeric;
- DWORD dwSize;
+ char counter_path[PDH_MAX_COUNTER_PATH],
+ tmp[MAX_STRING_LEN];
+ int ret = SYSINFO_RET_FAIL, interval;
+ PERF_COUNTERS *perfs;
- if (num_param(param) > 1)
+ if (num_param(param) > 2)
return SYSINFO_RET_FAIL;
- if (get_param(param, 1, counter_path, sizeof(counter_path)) != 0)
+ if (0 != get_param(param, 1, counter_path, sizeof(counter_path)))
*counter_path = '\0';
if (*counter_path == '\0')
return SYSINFO_RET_FAIL;
- dwSize = 0;
-retry:
- if (ERROR_SUCCESS != (status = PdhParseCounterPath(counter_path, cpe, &dwSize, 0))) {
- if (status == PDH_MORE_DATA) {
- cpe = (PDH_COUNTER_PATH_ELEMENTS *)zbx_malloc(cpe, dwSize);
- goto retry;
- }
- zabbix_log(LOG_LEVEL_DEBUG, "Can't parse counter path \"%s\": %s",
- counter_path, strerror_from_module(status, "PDH.DLL"));
+ if (0 != get_param(param, 2, tmp, sizeof(tmp)))
+ *tmp = '\0';
- zbx_free(cpe);
+ if (*tmp != '\0' && FAIL == is_uint(tmp))
return SYSINFO_RET_FAIL;
- }
- is_numeric = (SUCCEED == is_uint(cpe->szObjectName)) ? 0x01 : 0;
- is_numeric |= (SUCCEED == is_uint(cpe->szCounterName)) ? 0x02 : 0;
- if (0 != is_numeric) {
- if (0x01 & is_numeric)
- cpe->szObjectName = GetCounterName(atoi(cpe->szObjectName));
- if (0x02 & is_numeric)
- cpe->szCounterName = GetCounterName(atoi(cpe->szCounterName));
-
- dwSize = sizeof(counter_path);
- if (ERROR_SUCCESS != (status = PdhMakeCounterPath(cpe, counter_path, &dwSize, 0))) {
- zabbix_log(LOG_LEVEL_ERR, "Can't make counter path: %s",
- strerror_from_module(status, "PDH.DLL"));
- zbx_free(cpe);
- return SYSINFO_RET_FAIL;
+ interval = *tmp == '\0' ? 1 : atoi(tmp);
+
+ if (FAIL == check_counter_path(counter_path))
+ return SYSINFO_RET_FAIL;
+
+ if (interval > 1) {
+ if ( !PERF_COLLECTOR_STARTED(collector) ) {
+ SET_MSG_RESULT(result, strdup("Collector is not started!"));
+ return SYSINFO_RET_OK;
+ }
+
+ for (perfs = collector->perfs.pPerfCounterList; perfs != NULL; perfs = perfs->next) {
+ if (0 == strcmp(perfs->counter_path, counter_path) && perfs->interval == interval) {
+ SET_DBL_RESULT(result, perfs->lastValue);
+ return SYSINFO_RET_OK;
+ }
}
- zabbix_log(LOG_LEVEL_DEBUG, "Counter path converted to \"%s\"",
- counter_path);
+
+ if (FAIL == add_perf_counter("", counter_path, interval))
+ return SYSINFO_RET_FAIL;
}
- zbx_free(cpe);
if (ERROR_SUCCESS == (status = PdhOpenQuery(NULL, 0, &query)))
{
diff --git a/src/libs/zbxwin32/perfmon.c b/src/libs/zbxwin32/perfmon.c
index 9f33e4a0..bb13f59e 100644
--- a/src/libs/zbxwin32/perfmon.c
+++ b/src/libs/zbxwin32/perfmon.c
@@ -68,3 +68,53 @@ char *GetCounterName(DWORD index)
return counterName->name;
}
+
+/*
+ * Check performance counter path and convert from numeric format
+ *
+ * counterPath[PDH_MAX_COUNTER_PATH]
+ */
+
+int check_counter_path(char *counterPath)
+{
+ DWORD dwSize;
+ PDH_COUNTER_PATH_ELEMENTS *cpe = NULL;
+ PDH_STATUS status;
+ int is_numeric;
+
+ dwSize = 0;
+retry:
+ if (ERROR_SUCCESS != (status = PdhParseCounterPath(counterPath, cpe, &dwSize, 0))) {
+ if (status == PDH_MORE_DATA) {
+ cpe = (PDH_COUNTER_PATH_ELEMENTS *)zbx_malloc(cpe, dwSize);
+ goto retry;
+ }
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't parse counter path \"%s\": %s",
+ counterPath, strerror_from_module(status, "PDH.DLL"));
+
+ zbx_free(cpe);
+ return FAIL;
+ }
+
+ is_numeric = (SUCCEED == is_uint(cpe->szObjectName)) ? 0x01 : 0;
+ is_numeric |= (SUCCEED == is_uint(cpe->szCounterName)) ? 0x02 : 0;
+ if (0 != is_numeric) {
+ if (0x01 & is_numeric)
+ cpe->szObjectName = GetCounterName(atoi(cpe->szObjectName));
+ if (0x02 & is_numeric)
+ cpe->szCounterName = GetCounterName(atoi(cpe->szCounterName));
+
+ dwSize = PDH_MAX_COUNTER_PATH;
+ if (ERROR_SUCCESS != (status = PdhMakeCounterPath(cpe, counterPath, &dwSize, 0))) {
+ zabbix_log(LOG_LEVEL_ERR, "Can't make counter path: %s",
+ strerror_from_module(status, "PDH.DLL"));
+ zbx_free(cpe);
+ return FAIL;
+ }
+ zabbix_log(LOG_LEVEL_DEBUG, "Counter path converted to \"%s\"",
+ counterPath);
+ }
+ zbx_free(cpe);
+
+ return SUCCEED;
+} \ No newline at end of file
diff --git a/src/zabbix_agent/perfstat.c b/src/zabbix_agent/perfstat.c
index d27da20d..30eeaa38 100644
--- a/src/zabbix_agent/perfstat.c
+++ b/src/zabbix_agent/perfstat.c
@@ -25,11 +25,9 @@
#ifdef _WINDOWS
#include "perfmon.h"
-#endif /* _WINDOWS */
/* Static data */
-
-static PERF_COUNTERS *statPerfCounterList=NULL;
+static ZBX_PERF_STAT_DATA *ppsd = NULL;
/******************************************************************************
* *
@@ -48,84 +46,80 @@ static PERF_COUNTERS *statPerfCounterList=NULL;
* Comments: *
* *
******************************************************************************/
-static int add_perf_counter(const char *name, const char *counterPath, int interval)
+int add_perf_counter(const char *name, const char *counterPath, int interval)
{
- PERF_COUNTERS *perfs = NULL;
- int result = FAIL;
- char *alias_name = NULL;
+ PERF_COUNTERS *cptr;
+ PDH_STATUS status;
+ char *alias_name;
+ int result = FAIL;
assert(name);
assert(counterPath);
- if( interval < 1 || interval > 1800 )
- {
- zabbix_log( LOG_LEVEL_WARNING, "PerfCounter FAILED. [%s] (Interval value out of range)", name);
+ zabbix_log(LOG_LEVEL_DEBUG, "In add_perf_counter() [name:%s] [counter:%s] [interval:%d]",
+ name, counterPath, interval);
+
+ if (NULL == ppsd->pdh_query) {
+ zabbix_log(LOG_LEVEL_WARNING, "PerfCounter %s: \"%s\" FAILED: Collector is not started!",
+ name, counterPath);
return FAIL;
}
- for(perfs = statPerfCounterList; ; perfs=perfs->next)
- {
- /* Add new parameters */
- if(perfs == NULL)
- {
- perfs = (PERF_COUNTERS *)zbx_malloc(perfs, sizeof(PERF_COUNTERS));
- if (NULL != perfs)
- {
- memset(perfs,0,sizeof(PERF_COUNTERS));
- perfs->name = strdup(name);
- perfs->counterPath = strdup(counterPath);
- perfs->interval = interval;
- perfs->rawValueArray = (PDH_RAW_COUNTER *)zbx_malloc(perfs->rawValueArray,
- sizeof(PDH_RAW_COUNTER) * interval);
- perfs->CurrentCounter = 0;
- perfs->CurrentNum = 1;
-
- perfs->next = statPerfCounterList;
- statPerfCounterList = perfs;
-
- zabbix_log( LOG_LEVEL_DEBUG, "PerfCounter added. [%s] [%s] [%i]", name, counterPath, interval);
- result = SUCCEED;
- }
- break;
- }
+ if (interval < 1 || interval > 900) {
+ zabbix_log(LOG_LEVEL_WARNING, "PerfCounter %s: \"%s\" FAILED: Interval value out of range",
+ name, counterPath);
+ return FAIL;
+ }
- /* Replace existing parameters */
- if (strcmp(perfs->name, name) == 0)
- {
- zbx_free(perfs->name);
- zbx_free(perfs->counterPath);
- zbx_free(perfs->rawValueArray);
-
- memset(perfs,0,sizeof(PERF_COUNTERS));
- perfs->name = strdup(name);
- perfs->counterPath = strdup(counterPath);
- perfs->interval = interval;
- perfs->rawValueArray = (PDH_RAW_COUNTER *)zbx_malloc(perfs->rawValueArray,
+ for (cptr = ppsd->pPerfCounterList; ; cptr = cptr->next) {
+ /* Add new parameters */
+ if (NULL == cptr) {
+ cptr = (PERF_COUNTERS *)zbx_malloc(cptr, sizeof(PERF_COUNTERS));
+
+ memset(cptr, 0, sizeof(PERF_COUNTERS));
+ cptr->next = ppsd->pPerfCounterList;
+ cptr->name = strdup(name);
+ cptr->counterPath = strdup(counterPath);
+ cptr->interval = interval;
+ cptr->rawValueArray = (PDH_RAW_COUNTER *)zbx_malloc(cptr->rawValueArray,
sizeof(PDH_RAW_COUNTER) * interval);
- perfs->CurrentCounter = 0;
- perfs->CurrentNum = 1;
+ cptr->CurrentNum = 1;
- perfs->next = statPerfCounterList;
- statPerfCounterList = perfs;
+ /* Add user counters to query */
+ if (ERROR_SUCCESS != (status = PdhAddCounter(ppsd->pdh_query, cptr->counterPath, 0, &cptr->handle))) {
+ cptr->interval = -1; /* Flag for unsupported counters */
+ cptr->lastValue = NOTSUPPORTED;
+
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s",
+ cptr->counterPath,
+ strerror_from_module(status, "PDH.DLL"));
+ } else
+ zabbix_log(LOG_LEVEL_DEBUG, "PerfCounter %s: \"%s\" successfully added. Interval %d seconds",
+ name, cptr->counterPath, interval);
+
+ ppsd->pPerfCounterList = cptr;
- zabbix_log( LOG_LEVEL_DEBUG, "PerfCounter replaced. [%s] [%s] [%i]", name, counterPath, interval);
result = SUCCEED;
+ break;
+ }
+
+ if (*name != '\0' && 0 == strcmp(cptr->name, name)) {
+ zabbix_log(LOG_LEVEL_WARNING, "PerfCounter %s: \"%s\" FAILED: Counter already exists",
+ name, counterPath);
+ break;
}
}
- if( SUCCEED == result )
- {
+ if (SUCCEED == result && *name != '\0') {
alias_name = zbx_dsprintf(NULL, "__UserPerfCounter[%s]", name);
result = add_alias(name, alias_name);
zbx_free(alias_name);
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "PerfCounter FAILED. [%s] -> [%s]", name, counterPath);
- }
-
+ }/* else
+ zabbix_log(LOG_LEVEL_WARNING, "PerfCounter %s: \"%s\" FAILED",
+ name, counterPath);
+*/
return result;
}
@@ -144,43 +138,33 @@ static int add_perf_counter(const char *name, const char *counterPath, int inter
* Comments: format of input line is - name,"perfcounter name",interval *
* *
******************************************************************************/
-int add_perfs_from_config(char *line)
+int add_perfs_from_config(const char *line)
{
- char
- *name = NULL,
- *counterPath = NULL,
- *interval = NULL;
-
- name = line;
- counterPath = strchr(line,',');
- if(NULL == counterPath)
- goto lbl_syntax_error;
+ char name[MAX_STRING_LEN],
+ counterPath[PDH_MAX_COUNTER_PATH],
+ interval[MAX_STRING_LEN];
- *counterPath = '\0';
- counterPath++;
+ assert(line);
- if ( *counterPath != '"' )
+ if (num_param(line) != 3)
goto lbl_syntax_error;
- counterPath++;
-
- interval = strrchr(counterPath,',');
- if(NULL == interval)
+ if (0 != get_param(line, 1, name, sizeof(name)))
goto lbl_syntax_error;
- interval--;
- if ( *interval != '"' )
+ if (0 != get_param(line, 2, counterPath, sizeof(counterPath)))
goto lbl_syntax_error;
- *interval = '\0';
- interval++;
+ if (0 != get_param(line, 3, interval, sizeof(interval)))
+ goto lbl_syntax_error;
- *interval = '\0';
- interval++;
+ if (FAIL == check_counter_path(counterPath))
+ goto lbl_syntax_error;
return add_perf_counter(name, counterPath, atoi(interval));
-
lbl_syntax_error:
+ zabbix_log(LOG_LEVEL_WARNING, "PerfCounter \"%s\" FAILED: Invalid format.",
+ line);
return FAIL;
}
@@ -200,24 +184,18 @@ lbl_syntax_error:
******************************************************************************/
void perfs_list_free(void)
{
- PERF_COUNTERS *curr;
- PERF_COUNTERS *next;
-
- next = statPerfCounterList;
- while(next!=NULL)
- {
- curr = next;
- next = curr->next;
- zbx_free(curr->name);
- zbx_free(curr->counterPath);
- zbx_free(curr->rawValueArray);
- zbx_free(curr);
- }
- statPerfCounterList = NULL;
-}
-
+ PERF_COUNTERS *cptr;
+ while (NULL != ppsd->pPerfCounterList) {
+ cptr = ppsd->pPerfCounterList;
+ ppsd->pPerfCounterList = cptr->next;
+ zbx_free(cptr->name);
+ zbx_free(cptr->counterPath);
+ zbx_free(cptr->rawValueArray);
+ zbx_free(cptr);
+ }
+}
/******************************************************************************
* *
@@ -229,60 +207,25 @@ void perfs_list_free(void)
* Parameters: pperf - pointer to the structure *
* of ZBX_PERF_STAT_DATA type *
* *
- * Return value: If the function succeeds, the return 0, *
- * great than 0 on an error *
+ * Return value: *
* *
* Author: Eugene Grigorjev *
* *
* Comments: *
* *
******************************************************************************/
-
int init_perf_collector(ZBX_PERF_STAT_DATA *pperf)
{
-#ifdef _WINDOWS
-
- PERF_COUNTERS *cptr = NULL;
- PDH_STATUS status;
- int is_empty = 1;
-
- memset(pperf, 0, sizeof(ZBX_PERF_STAT_DATA));
+ zabbix_log(LOG_LEVEL_DEBUG, "In init_perf_collector()");
- pperf->pPerfCounterList = statPerfCounterList;
-
- if (PdhOpenQuery(NULL,0,&pperf->pdh_query)!=ERROR_SUCCESS)
- {
- zabbix_log( LOG_LEVEL_ERR, "Call to PdhOpenQuery() failed: %s", strerror_from_system(GetLastError()));
- return 1;
- }
-
- /* Add user counters to query */
- for ( cptr = statPerfCounterList; cptr != NULL; cptr = cptr->next )
- {
- if (ERROR_SUCCESS != (status = PdhAddCounter(
- pperf->pdh_query,
- cptr->counterPath, 0,
- &cptr->handle)))
- {
- cptr->interval = -1; /* Flag for unsupported counters */
- cptr->lastValue = NOTSUPPORTED;
-
- zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", cptr->counterPath, strerror_from_module(status,"PDH.DLL"));
- }
- else
- {
- is_empty = 0;
- }
- }
+ ppsd = pperf;
- if ( is_empty )
- {
- close_perf_collector(pperf);
+ if (ERROR_SUCCESS != PdhOpenQuery(NULL, 0, &ppsd->pdh_query)) {
+ zabbix_log(LOG_LEVEL_ERR, "Call to PdhOpenQuery() failed: %s", strerror_from_system(GetLastError()));
+ return FAIL;
}
-#endif /* _WINDOWS */
-
- return 0;
+ return SUCCEED;
}
/******************************************************************************
@@ -291,8 +234,7 @@ int init_perf_collector(ZBX_PERF_STAT_DATA *pperf)
* *
* Purpose: Clear state of data calculation *
* *
- * Parameters: pperf - pointer to the structure *
- * of ZBX_PERF_STAT_DATA type *
+ * Parameters: *
* *
* Return value: *
* *
@@ -301,78 +243,84 @@ int init_perf_collector(ZBX_PERF_STAT_DATA *pperf)
* Comments: *
* *
******************************************************************************/
-
-void close_perf_collector(ZBX_PERF_STAT_DATA *pperf)
+void close_perf_collector()
{
-#ifdef _WINDOWS
- PERF_COUNTERS *cptr = NULL;
+ PERF_COUNTERS *cptr;
- for ( cptr = statPerfCounterList; cptr != NULL; cptr = cptr->next )
- {
- if(cptr->handle)
- {
+ if (NULL == ppsd->pdh_query)
+ return;
+
+ for (cptr = ppsd->pPerfCounterList; cptr != NULL; cptr = cptr->next)
+ if (NULL != cptr->handle) {
PdhRemoveCounter(cptr->handle);
cptr->handle = NULL;
}
- }
- if( pperf->pdh_query )
- {
- PdhCloseQuery(pperf->pdh_query);
- pperf->pdh_query = NULL;
- }
-
-#endif /* _WINDOWS */
+ PdhCloseQuery(ppsd->pdh_query);
+ ppsd->pdh_query = NULL;
+ perfs_list_free();
}
-void collect_perfstat(ZBX_PERF_STAT_DATA *pperf)
+/******************************************************************************
+ * *
+ * Function: collect_perfstat *
+ * *
+ * Purpose: *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Eugene Grigorjev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+void collect_perfstat()
{
-#ifdef _WINDOWS
- PERF_COUNTERS *cptr = NULL;
+ PERF_COUNTERS *cptr;
PDH_STATISTICS statData;
PDH_STATUS status;
- if ( pperf->pdh_query )
- {
- if ((status = PdhCollectQueryData(pperf->pdh_query)) != ERROR_SUCCESS)
- {
- zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s", strerror_from_module(status,"PDH.DLL"));
- return;
- }
-
- /* Process user-defined counters */
- for ( cptr = statPerfCounterList; cptr != NULL; cptr = cptr->next )
- {
- if ( cptr->handle && cptr->interval > 0 ) /* Active counter? */
- {
- PdhGetRawCounterValue(
- cptr->handle,
- NULL,
- &cptr->rawValueArray[cptr->CurrentCounter]
- );
-
- cptr->CurrentCounter++;
-
- if ( cptr->CurrentCounter >= cptr->interval )
- cptr->CurrentCounter = 0;
-
- PdhComputeCounterStatistics(
- cptr->handle,
- PDH_FMT_DOUBLE,
- (cptr->CurrentNum < cptr->interval) ? 0 : cptr->CurrentCounter,
- cptr->CurrentNum,
- cptr->rawValueArray,
- &statData
- );
-
- cptr->lastValue = statData.mean.doubleValue;
-
- if(cptr->CurrentNum < cptr->interval)
- cptr->CurrentNum++;
- }
- }
+ if (NULL == ppsd->pdh_query)
+ return;
+
+ if (ERROR_SUCCESS != (status = PdhCollectQueryData(ppsd->pdh_query))) {
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s", strerror_from_module(status,"PDH.DLL"));
+ return;
}
+
+ /* Process user-defined counters */
+ for ( cptr = ppsd->pPerfCounterList; cptr != NULL; cptr = cptr->next )
+ {
+ if (cptr->interval == -1) /* Inactive counter? */
+ continue;
-#endif /* _WINDOWS */
+ PdhGetRawCounterValue(
+ cptr->handle,
+ NULL,
+ &cptr->rawValueArray[cptr->CurrentCounter]
+ );
+
+ cptr->CurrentCounter++;
+
+ if ( cptr->CurrentCounter >= cptr->interval )
+ cptr->CurrentCounter = 0;
+
+ PdhComputeCounterStatistics(
+ cptr->handle,
+ PDH_FMT_DOUBLE,
+ (cptr->CurrentNum < cptr->interval) ? 0 : cptr->CurrentCounter,
+ cptr->CurrentNum,
+ cptr->rawValueArray,
+ &statData
+ );
+
+ cptr->lastValue = statData.mean.doubleValue;
+
+ if(cptr->CurrentNum < cptr->interval)
+ cptr->CurrentNum++;
+ }
}
+#endif /* _WINDOWS */
diff --git a/src/zabbix_agent/perfstat.h b/src/zabbix_agent/perfstat.h
index 08b15a4c..ab0f2098 100644
--- a/src/zabbix_agent/perfstat.h
+++ b/src/zabbix_agent/perfstat.h
@@ -20,20 +20,12 @@
#ifndef ZABBIX_PERFSTAT_H
#define ZABBIX_PERFSTAT_H
-#if defined (_WINDOWS)
+#ifdef _WINDOWS
# include "perfmon.h"
# define PERF_COLLECTOR_STARTED(collector) ((collector) && (collector)->perfs.pdh_query)
-#else /* not _WINDOWS */
-
-# define PDH_RAW_COUNTER void*
-# define HCOUNTER void*
-# define HQUERY void*
-
-#endif /* _WINDOWS */
-
struct zbx_perfs
{
struct zbx_perfs *next;
@@ -55,11 +47,13 @@ typedef struct s_perfs_stat_data
HQUERY pdh_query;
} ZBX_PERF_STAT_DATA;
-int add_perfs_from_config(char *line);
+int add_perf_counter(const char *name, const char *counterPath, int interval);
+int add_perfs_from_config(const char *line);
void perfs_list_free(void);
int init_perf_collector(ZBX_PERF_STAT_DATA *pperf);
-void collect_perfstat(ZBX_PERF_STAT_DATA *pcpus);
-void close_perf_collector(ZBX_PERF_STAT_DATA *pcpus);
+void collect_perfstat();
+void close_perf_collector();
+#endif /* _WINDOWS */
#endif /* ZABBIX_PERFSTAT_H */
diff --git a/src/zabbix_agent/stats.c b/src/zabbix_agent/stats.c
index 23804cf9..fa3a7432 100644
--- a/src/zabbix_agent/stats.c
+++ b/src/zabbix_agent/stats.c
@@ -74,6 +74,7 @@ void init_collector_data(void)
memset(collector, 0, sizeof(ZBX_COLLECTOR_DATA));
+ init_perf_collector(&collector->perfs);
#else /* not _WINDOWS */
#define ZBX_MAX_ATTEMPTS 10
@@ -190,18 +191,20 @@ void free_collector_data(void)
ZBX_THREAD_ENTRY(collector_thread, args)
{
+ double sec;
+
zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd collector started");
if ( init_cpu_collector(&(collector->cpus)) )
close_cpu_collector(&(collector->cpus));
- if( init_perf_collector(&(collector->perfs)) )
- close_perf_collector(&(collector->perfs));
-
while(ZBX_IS_RUNNING)
{
+ sec = zbx_time();
collect_cpustat(&(collector->cpus));
- collect_perfstat(&(collector->perfs));
+#ifdef _WINDOWS
+ collect_perfstat();
+#endif /* _WINDOWS */
collect_stats_interfaces(&(collector->interfaces)); /* TODO */
collect_stats_diskdevices(&(collector->diskdevices)); /* TODO */
@@ -209,7 +212,9 @@ ZBX_THREAD_ENTRY(collector_thread, args)
zbx_sleep(1);
}
- close_perf_collector(&(collector->perfs));
+#ifdef _WINDOWS
+ close_perf_collector();
+#endif /* _WINDOWS */
close_cpu_collector(&(collector->cpus));
zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd collector stopped");
diff --git a/src/zabbix_agent/stats.h b/src/zabbix_agent/stats.h
index e46730c9..b5727acb 100644
--- a/src/zabbix_agent/stats.h
+++ b/src/zabbix_agent/stats.h
@@ -38,7 +38,9 @@ typedef struct s_collector_data
ZBX_CPUS_STAT_DATA cpus;
ZBX_INTERFACES_DATA interfaces;
ZBX_DISKDEVICES_DATA diskdevices;
+#ifdef _WINDOWS
ZBX_PERF_STAT_DATA perfs;
+#endif /* _WINDOWS */
} ZBX_COLLECTOR_DATA;
extern ZBX_COLLECTOR_DATA *collector;
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index 82e80c1e..a8196ead 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -254,6 +254,8 @@ int MAIN_ZABBIX_ENTRY(void)
init_collector_data();
+ load_user_parameters();
+
/* --- START THREADS ---*/
if(1 == CONFIG_DISABLE_PASSIVE)
@@ -334,7 +336,6 @@ void zbx_on_exit()
free_metrics();
free_collector_data();
alias_list_free();
- perfs_list_free();
zbx_sleep(2); /* wait for all threads closing */
@@ -372,8 +373,6 @@ int main(int argc, char **argv)
}
#endif /* _WINDOWS */
- load_user_parameters();
-
switch (t.task) {
#if defined (_WINDOWS)
case ZBX_TASK_INSTALL_SERVICE: