diff options
| author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-05-14 07:55:56 +0000 |
|---|---|---|
| committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-05-14 07:55:56 +0000 |
| commit | 2a12f2bb704fd9b5777e0c06499874f2cfddbcb7 (patch) | |
| tree | 680907c746f1527df97951adb1c67ea68f55e330 /src/libs/zbxsysinfo | |
| parent | 6b4eabad631afa94d90ae9082438c1077b9c919e (diff) | |
| download | zabbix-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
Diffstat (limited to 'src/libs/zbxsysinfo')
| -rw-r--r-- | src/libs/zbxsysinfo/win32/pdhmon.c | 62 |
1 files changed, 28 insertions, 34 deletions
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))) { |
