summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-21 07:18:04 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-04-21 07:18:04 +0000
commit2e5c4059e861c044ecdc97c71bf2aa324ce6670e (patch)
treef5131fa7e0592f79a554ebc05b629c5e87956067 /src/libs/zbxsysinfo
parentdcea1d6edb1de5434d1453303d2435296e03444f (diff)
downloadzabbix-2e5c4059e861c044ecdc97c71bf2aa324ce6670e.tar.gz
zabbix-2e5c4059e861c044ecdc97c71bf2aa324ce6670e.tar.xz
zabbix-2e5c4059e861c044ecdc97c71bf2aa324ce6670e.zip
- [DEV-143] improved support of numeric performance counters for Windows agents
git-svn-id: svn://svn.zabbix.com/trunk@5639 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs/zbxsysinfo')
-rw-r--r--src/libs/zbxsysinfo/win32/pdhmon.c107
-rw-r--r--src/libs/zbxsysinfo/win32/uptime.c4
2 files changed, 67 insertions, 44 deletions
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);
}