summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--src/libs/zbxsysinfo/win32/pdhmon.c107
-rw-r--r--src/libs/zbxsysinfo/win32/uptime.c4
-rw-r--r--src/zabbix_agent/active.c2
-rw-r--r--src/zabbix_agent/cpustat.c76
5 files changed, 116 insertions, 74 deletions
diff --git a/ChangeLog b/ChangeLog
index d5d5db54..7026a500 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
Changes for 1.5.1:
+ - [DEV-143] improved support of numeric performance counters for Windows agents (Sasha)
- [DEV-141] improved performance of ZABBIX Proxy module (Sasha)
- [DEV-140] added support of zabbix[proxy,<proxyname>,lastaccess] (Sasha)
- [DEV-124] screen actions moved to Audit, added filter for Audit (Artem)
diff --git a/src/libs/zbxsysinfo/win32/pdhmon.c b/src/libs/zbxsysinfo/win32/pdhmon.c
index f00d58b3..d73cfb40 100644
--- a/src/libs/zbxsysinfo/win32/pdhmon.c
+++ b/src/libs/zbxsysinfo/win32/pdhmon.c
@@ -53,34 +53,62 @@ int USER_PERFCOUNTER(const char *cmd, const char *param, unsigned flags, AGENT_R
int PERF_MONITOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- HQUERY query;
- HCOUNTER counter;
- PDH_STATUS status;
+ HQUERY query;
+ HCOUNTER counter;
+ 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;
+
+ if (num_param(param) > 1)
+ return SYSINFO_RET_FAIL;
- PDH_RAW_COUNTER rawData, rawData2;
- PDH_FMT_COUNTERVALUE counterValue;
+ if (get_param(param, 1, counter_path, sizeof(counter_path)) != 0)
+ *counter_path = '\0';
- char counter_name[MAX_STRING_LEN];
+ if (*counter_path == '\0')
+ return SYSINFO_RET_FAIL;
- int ret = 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(num_param(param) > 1)
- {
+ zbx_free(cpe);
return SYSINFO_RET_FAIL;
}
- if(get_param(param, 1, counter_name, sizeof(counter_name)) != 0)
- {
- counter_name[0] = '\0';
- }
- if(counter_name[0] == '\0')
- {
- 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;
+ }
+ zabbix_log(LOG_LEVEL_DEBUG, "Counter path converted to \"%s\"",
+ counter_path);
}
+ zbx_free(cpe);
- if (ERROR_SUCCESS == PdhOpenQuery(NULL,0,&query))
+ if (ERROR_SUCCESS == (status = PdhOpenQuery(NULL, 0, &query)))
{
- if (ERROR_SUCCESS == (status = PdhAddCounter(query,counter_name,0,&counter)))
+ if (ERROR_SUCCESS == (status = PdhAddCounter(query,counter_path,0,&counter)))
{
if (ERROR_SUCCESS == (status = PdhCollectQueryData(query)))
{
@@ -107,37 +135,32 @@ int PERF_MONITOR(const char *cmd, const char *param, unsigned flags, AGENT_RESUL
}
- if(ERROR_SUCCESS == status)
- {
+ if(ERROR_SUCCESS == status) {
SET_DBL_RESULT(result, counterValue.doubleValue);
ret = SYSINFO_RET_OK;
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Can't format counter value [%s] [%s]", counter_name, strerror_from_module(status,"PDH.DLL"));
- }
+ } else
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't format counter value \"%s\": %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
+ } else {
+ if (ERROR_SUCCESS == status)
+ status = rawData.CStatus;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't get counter value \"%s\": %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
}
- else
- {
- if(ERROR_SUCCESS == status) status = rawData.CStatus;
+ } else
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't collect data \"%s\": %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
- zabbix_log(LOG_LEVEL_DEBUG, "Can't get counter value [%s] [%s]", counter_name, strerror_from_module(status,"PDH.DLL"));
- }
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Can't collect data [%s] [%s]", counter_name, strerror_from_module(status,"PDH.DLL"));
- }
PdhRemoveCounter(&counter);
- }
- else
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Can't add counter [%s] [%s]", counter_name, strerror_from_module(status,"PDH.DLL"));
- }
-
+ } else
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't add counter \"%s\": %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
PdhCloseQuery(query);
- }
+ } else
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't initialize performance counters \"%s\": %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
return ret;
}
diff --git a/src/libs/zbxsysinfo/win32/uptime.c b/src/libs/zbxsysinfo/win32/uptime.c
index 247caf94..ce56e5c8 100644
--- a/src/libs/zbxsysinfo/win32/uptime.c
+++ b/src/libs/zbxsysinfo/win32/uptime.c
@@ -24,9 +24,9 @@
int SYSTEM_UPTIME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
- char counter_path[MAX_COUNTER_PATH];
+ char counter_path[64];
- zbx_snprintf(counter_path, sizeof(counter_path), "\\%s\\%s",GetCounterName(PCI_SYSTEM),GetCounterName(PCI_SYSTEM_UP_TIME));
+ zbx_snprintf(counter_path, sizeof(counter_path), "\\%d\\%d", PCI_SYSTEM, PCI_SYSTEM_UP_TIME);
return PERF_MONITOR(cmd, counter_path, flags, result);
}
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c
index a1a1f209..34859ec3 100644
--- a/src/zabbix_agent/active.c
+++ b/src/zabbix_agent/active.c
@@ -426,7 +426,7 @@ static int send_buffer(
buffer.count,
CONFIG_BUFFER_SIZE);
- now = time(NULL);
+ now = (int)time(NULL);
if(buffer.count < CONFIG_BUFFER_SIZE && now-lastsent < CONFIG_BUFFER_SEND)
{
zabbix_log( LOG_LEVEL_DEBUG, "Will not send now. Now %d lastsent %d < %d",
diff --git a/src/zabbix_agent/cpustat.c b/src/zabbix_agent/cpustat.c
index 63157296..e32329e9 100644
--- a/src/zabbix_agent/cpustat.c
+++ b/src/zabbix_agent/cpustat.c
@@ -125,49 +125,56 @@ static int zbx_get_cpu_num(void)
int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
{
#ifdef _WINDOWS
-
- PDH_STATUS status;
- int i;
- char counter_path[MAX_COUNTER_PATH];
+ PDH_STATUS status;
+ char cpu[16], counter_path[PDH_MAX_COUNTER_PATH];
+ PDH_COUNTER_PATH_ELEMENTS cpe;
+ int i;
+ DWORD dwSize;
memset(pcpus, 0, sizeof(ZBX_CPUS_STAT_DATA));
pcpus->count = zbx_get_cpu_num();
- if (PdhOpenQuery(NULL,0,&pcpus->pdh_query)!=ERROR_SUCCESS)
- {
- zabbix_log( LOG_LEVEL_ERR, "Call to PdhOpenQuery() failed: %s", strerror_from_system(GetLastError()));
+ if (ERROR_SUCCESS != (status = PdhOpenQuery(NULL, 0, &pcpus->pdh_query))) {
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhOpenQuery() failed: %s",
+ strerror_from_module(status, "PDH.DLL"));
return 1;
}
- zbx_snprintf(counter_path, sizeof(counter_path), "\\%s(_Total)\\%s",GetCounterName(PCI_PROCESSOR),GetCounterName(PCI_PROCESSOR_TIME));
-
- if (ERROR_SUCCESS != (status = PdhAddCounter(
- pcpus->pdh_query,
- counter_path, 0,
- &pcpus->cpu[0].usage_couter)))
- {
- zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", counter_path, strerror_from_module(status,"PDH.DLL"));
- return 2;
- }
-
- for(i=1 /* 0 - is Total cpus */; i <= pcpus->count /* "<=" instead of "+ 1" */; i++)
- {
- zbx_snprintf(counter_path, sizeof(counter_path),"\\%s(%d)\\%s", GetCounterName(PCI_PROCESSOR), i-1, GetCounterName(PCI_PROCESSOR_TIME));
+ cpe.szMachineName = NULL;
+ cpe.szObjectName = GetCounterName(PCI_PROCESSOR);
+ cpe.szInstanceName = cpu;
+ cpe.szParentInstance = NULL;
+ cpe.dwInstanceIndex = -1;
+ cpe.szCounterName = GetCounterName(PCI_PROCESSOR_TIME);
+
+ for(i = 0 /* 0 : _Total; >0 : cpu */; i <= pcpus->count; i++) {
+ if (i == 0)
+ zbx_strlcpy(cpu, "_Total", sizeof(cpu));
+ else
+ _itoa_s(i, cpu, sizeof(cpu), 10);
+
+ dwSize = sizeof(counter_path);
+ if (ERROR_SUCCESS != (status = PdhMakeCounterPath(&cpe, counter_path, &dwSize, 0)))
+ {
+ zabbix_log(LOG_LEVEL_ERR, "Call to PdhMakeCounterPath() failed: %s",
+ strerror_from_module(status, "PDH.DLL"));
+ return 1;
+ }
- if (ERROR_SUCCESS != (status = PdhAddCounter(
- pcpus->pdh_query,
- counter_path,0,
- &pcpus->cpu[i].usage_couter)))
+ if (ERROR_SUCCESS != (status = PdhAddCounter(pcpus->pdh_query, counter_path, 0,
+ &pcpus->cpu[i].usage_couter)))
{
- zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", counter_path, strerror_from_module(status,"PDH.DLL"));
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
return 2;
}
}
if (ERROR_SUCCESS != (status = PdhCollectQueryData(pcpus->pdh_query)))
{
- zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s", strerror_from_module(status,"PDH.DLL"));
+ zabbix_log( LOG_LEVEL_ERR, "Call to PdhCollectQueryData() failed: %s",
+ strerror_from_module(status, "PDH.DLL"));
return 3;
}
@@ -176,12 +183,23 @@ int init_cpu_collector(ZBX_CPUS_STAT_DATA *pcpus)
PdhGetRawCounterValue(pcpus->cpu[i].usage_couter, NULL, &pcpus->cpu[i].usage_old);
}
- zbx_snprintf(counter_path, sizeof(counter_path), "\\%s\\%s", GetCounterName(PCI_SYSTEM), GetCounterName(PCI_PROCESSOR_QUEUE_LENGTH));
+ cpe.szObjectName = GetCounterName(PCI_SYSTEM);
+ cpe.szInstanceName = NULL;
+ cpe.szCounterName = GetCounterName(PCI_PROCESSOR_QUEUE_LENGTH);
+
+ dwSize = sizeof(counter_path);
+ if (ERROR_SUCCESS != (status = PdhMakeCounterPath(&cpe, counter_path, &dwSize, 0)))
+ {
+ zabbix_log(LOG_LEVEL_ERR, "Call to PdhMakeCounterPath() failed: %s",
+ strerror_from_module(status, "PDH.DLL"));
+ return 1;
+ }
/* Prepare for CPU execution queue usage collection */
if (ERROR_SUCCESS != (status = PdhAddCounter(pcpus->pdh_query, counter_path, 0, &pcpus->queue_counter)))
{
- zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s", counter_path, strerror_from_module(status,"PDH.DLL"));
+ zabbix_log( LOG_LEVEL_ERR, "Unable to add performance counter \"%s\" to query: %s",
+ counter_path, strerror_from_module(status, "PDH.DLL"));
return 2;
}