MCPcopy Create free account
hub / github.com/Icinga/icinga2 / QueryPerfData

Function QueryPerfData

plugins/check_perfmon.cpp:267–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265}
266
267bool QueryPerfData(printInfoStruct& pI)
268{
269 PDH_HQUERY hQuery = NULL;
270 PDH_HCOUNTER hCounter = NULL;
271 DWORD dwBufferSize = 0, dwItemCount = 0;
272
273 if (pI.wsFullPath.empty()) {
274 std::wcout << "No performance counter path given!\n";
275 return false;
276 }
277
278 PDH_FMT_COUNTERVALUE_ITEM *pDisplayValues = NULL;
279
280 PDH_STATUS status = PdhOpenQuery(NULL, NULL, &hQuery);
281 if (FAILED(status))
282 goto die;
283
284 status = PdhAddEnglishCounter(hQuery, pI.wsFullPath.c_str(), NULL, &hCounter);
285
286 if (FAILED(status))
287 status = PdhAddCounter(hQuery, pI.wsFullPath.c_str(), NULL, &hCounter);
288
289 if (FAILED(status))
290 goto die;
291
292 status = PdhCollectQueryData(hQuery);
293 if (FAILED(status))
294 goto die;
295
296 /*
297 * Most counters need two queries to provide a value.
298 * Those which need only one will return the second.
299 */
300 Sleep(pI.dwPerformanceWait);
301
302 status = PdhCollectQueryData(hQuery);
303 if (FAILED(status))
304 goto die;
305
306 status = PdhGetFormattedCounterArray(hCounter, pI.dwRequestedType, &dwBufferSize, &dwItemCount, NULL);
307 if (status != PDH_MORE_DATA)
308 goto die;
309
310 pDisplayValues = reinterpret_cast<PDH_FMT_COUNTERVALUE_ITEM*>(new BYTE[dwBufferSize]);
311 status = PdhGetFormattedCounterArray(hCounter, pI.dwRequestedType, &dwBufferSize, &dwItemCount, pDisplayValues);
312
313 if (FAILED(status))
314 goto die;
315
316 switch (pI.dwRequestedType) {
317 case (PDH_FMT_LONG):
318 pI.dValue = pDisplayValues[0].FmtValue.longValue;
319 break;
320 case (PDH_FMT_LARGE):
321 pI.dValue = (double) pDisplayValues[0].FmtValue.largeValue;
322 break;
323 default:
324 pI.dValue = pDisplayValues[0].FmtValue.doubleValue;

Callers 1

wmainFunction · 0.85

Calls 2

printPDHErrorFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected