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

Function check_load

plugins/check_load.cpp:165–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static int check_load(printInfoStruct& printInfo)
166{
167 if (l_Debug)
168 std::wcout << L"Creating query and adding counter" << '\n';
169
170 PDH_HQUERY phQuery;
171 PDH_STATUS err = PdhOpenQuery(NULL, NULL, &phQuery);
172 if (!SUCCEEDED(err))
173 goto die;
174
175 PDH_HCOUNTER phCounter;
176 err = PdhAddEnglishCounter(phQuery, L"\\Processor(_Total)\\% Idle Time", NULL, &phCounter);
177 if (!SUCCEEDED(err))
178 goto die;
179
180 if (l_Debug)
181 std::wcout << L"Collecting first batch of query data" << '\n';
182
183 err = PdhCollectQueryData(phQuery);
184 if (!SUCCEEDED(err))
185 goto die;
186
187 if (l_Debug)
188 std::wcout << L"Sleep for one second" << '\n';
189
190 Sleep(1000);
191
192 if (l_Debug)
193 std::wcout << L"Collecting second batch of query data" << '\n';
194
195 err = PdhCollectQueryData(phQuery);
196 if (!SUCCEEDED(err))
197 goto die;
198
199 if (l_Debug)
200 std::wcout << L"Creating formatted counter array" << '\n';
201
202 DWORD CounterType;
203 PDH_FMT_COUNTERVALUE DisplayValue;
204 err = PdhGetFormattedCounterValue(phCounter, PDH_FMT_DOUBLE, &CounterType, &DisplayValue);
205 if (SUCCEEDED(err)) {
206 if (DisplayValue.CStatus == PDH_CSTATUS_VALID_DATA) {
207 if (l_Debug)
208 std::wcout << L"Recieved Value of " << DisplayValue.doubleValue << L" (idle)" << '\n';
209 printInfo.load = 100.0 - DisplayValue.doubleValue;
210 }
211 else {
212 if (l_Debug)
213 std::wcout << L"Received data was not valid\n";
214 goto die;
215 }
216
217 if (l_Debug)
218 std::wcout << L"Finished collection. Cleaning up and returning" << '\n';
219
220 PdhCloseQuery(phQuery);
221 return -1;
222 }

Callers 1

wmainFunction · 0.85

Calls 1

printErrorInfoFunction · 0.85

Tested by

no test coverage detected