Index: cpustat.c =================================================================== --- cpustat.c (revision 5332) +++ cpustat.c (working copy) @@ -127,6 +127,8 @@ #ifdef _WINDOWS PDH_STATUS status; + PDH_COUNTER_PATH_ELEMENTS cpe_proc_total = { NULL, "Processor", "_Total", NULL, -1, "% Processor Time" }; + PDH_COUNTER_PATH_ELEMENTS cpe_proc = { NULL, "Processor", NULL, NULL, -1, "% Processor Time" }; int i; char counter_path[MAX_COUNTER_PATH]; @@ -140,7 +142,11 @@ return 1; } - zbx_snprintf(counter_path, sizeof(counter_path), "\\%s(_Total)\\%s",GetCounterName(PCI_PROCESSOR),GetCounterName(PCI_PROCESSOR_TIME)); + if ((status = PdhMakeCounterPath(&cpe_proc_total, counter_path, (LPDWORD)sizeof(counter_path), 0)) != ERROR_SUCCESS) + { + zabbix_log( LOG_LEVEL_ERR, "Call to PdhMakeCounterPath() failed: %s", strerror_from_system(GetLastError())); + return 1; + } if (ERROR_SUCCESS != (status = PdhAddCounter( pcpus->pdh_query, @@ -153,8 +159,16 @@ 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)); + char cpu[16]; + PDH_COUNTER_PATH_ELEMENTS cpe_proc_instance = { NULL, "Processor", cpu, NULL, -1, "% Processor Time" }; + _itoa_s(i, cpu, sizeof(cpu), 10); + if ((status = PdhMakeCounterPath(&cpe_proc_instance, counter_path, (LPDWORD)sizeof(counter_path), 0)) != ERROR_SUCCESS) + { + zabbix_log( LOG_LEVEL_ERR, "Call to PdhMakeCounterPath() failed: %s", strerror_from_system(GetLastError())); + return 1; + } + if (ERROR_SUCCESS != (status = PdhAddCounter( pcpus->pdh_query, counter_path,0, @@ -176,7 +190,11 @@ 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)); + if ((status = PdhMakeCounterPath(&cpe_proc, counter_path, (LPDWORD)sizeof(counter_path), 0)) != ERROR_SUCCESS) + { + zabbix_log( LOG_LEVEL_ERR, "Call to PdhMakeCounterPath() failed: %s", strerror_from_system(GetLastError())); + return 1; + } /* Prepare for CPU execution queue usage collection */ if (ERROR_SUCCESS != (status = PdhAddCounter(pcpus->pdh_query, counter_path, 0, &pcpus->queue_counter)))