Changeset 24f7192 in nscp for trunk/modules/CheckSystem
- Timestamp:
- 07/11/05 21:55:28 (8 years ago)
- Children:
- 237da21
- Parents:
- e93e741
- Location:
- trunk/modules/CheckSystem
- Files:
-
- 6 edited
-
CheckSystem.cpp (modified) (21 diffs)
-
CheckSystem.def (modified) (1 diff)
-
CheckSystem.h (modified) (1 diff)
-
CheckSystem.vcproj (modified) (1 diff)
-
PDHCollector.cpp (modified) (5 diffs)
-
PDHCollector.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/CheckSystem/CheckSystem.cpp
re93e741 r24f7192 8 8 #include <EnumNtSrv.h> 9 9 #include <EnumProcess.h> 10 #include <sysinfo.h> 11 #include <checkHelpers.hpp> 10 12 11 13 CheckSystem gNSClientCompat; … … 47 49 int method = tmp.GetAvailableMethods(); 48 50 49 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 51 52 53 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_AUTO) { 54 OSVERSIONINFO osVer = systemInfo::getOSVersion(); 55 if (systemInfo::isBelowNT4(osVer)) { 56 NSC_DEBUG_MSG_STD("Autodetected NT4<, using PSAPI process enumeration."); 57 processMethod_ = ENUM_METHOD::PSAPI; 58 } else if (systemInfo::isAboveW2K(osVer)) { 59 NSC_DEBUG_MSG_STD("Autodetected W2K>, using TOOLHELP process enumeration."); 60 processMethod_ = ENUM_METHOD::TOOLHELP; 61 } else { 62 NSC_DEBUG_MSG_STD("Autodetected failed, using PSAPI process enumeration."); 63 processMethod_ = ENUM_METHOD::PSAPI; 64 } 65 } else if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 50 66 NSC_DEBUG_MSG_STD("Using PSAPI method."); 51 67 if (method == (method|ENUM_METHOD::PSAPI)) { … … 75 91 } 76 92 return true; 77 }78 /**79 * Return the module name.80 * @return The module name81 */82 std::string CheckSystem::getModuleName() {83 return "System Checks Module.";84 }85 /**86 * Module version87 * @return module version88 */89 NSCModuleWrapper::module_version CheckSystem::getModuleVersion() {90 NSCModuleWrapper::module_version version = {0, 3, 0 };91 return version;92 93 } 93 94 /** … … 136 137 } 137 138 138 // checkCPU warn=80 crit=90 time=20m time=10s time=4139 // checkCPU warn=80 crit=90 time=20m time=10s time=4 showAll140 // checkCPU 20 10 4 nsclient141 139 NSCAPI::nagiosReturn CheckSystem::checkCPU(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 142 140 { 141 typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsInteger> CPULoadConatiner; 142 143 143 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 144 144 if (stl_args.empty()) { … … 146 146 return NSCAPI::returnUNKNOWN; 147 147 } 148 int warn; 149 int crit; 150 std::list<std::string> times; 151 bool bNSCLientCompatible = false; 148 std::list<CPULoadConatiner> list; 149 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 152 150 bool bShowAll = false; 153 NSCAPI::nagiosReturn ret = NSCAPI::returnOK; 154 155 156 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 157 strEx::token t = strEx::getToken((*it), '='); 158 if (t.first == "crit") 159 crit = strEx::stoi(t.second); 160 else if (t.first == "warn") 161 warn = strEx::stoi(t.second); 162 else if (t.first == "time") 163 times.push_back(t.second); 164 else if (t.first == NSCLIENT) 165 bNSCLientCompatible = true; 166 else if (t.first == "showAll") 167 bShowAll = true; 168 else 169 times.push_back(t.first); 170 } 171 172 for (std::list<std::string>::iterator it = times.begin(); it != times.end(); ++it) { 151 bool bNSClient = false; 152 CPULoadConatiner tmpObject; 153 154 tmpObject.data = "cpuload"; 155 156 MAP_OPTIONS_BEGIN(stl_args) 157 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 158 MAP_OPTIONS_STR("warn", tmpObject.warn.max) 159 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 160 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 161 MAP_OPTIONS_STR("crit", tmpObject.crit.max) 162 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 163 MAP_OPTIONS_STR_AND("time", tmpObject.data, list.push_back(tmpObject)) 164 MAP_OPTIONS_STR_AND("Time", tmpObject.data, list.push_back(tmpObject)) 165 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 166 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 167 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 168 else if (p2.first == "Time") { 169 tmpObject.data = p__.second; 170 tmpObject.alias = p2.second; 171 list.push_back(tmpObject); 172 } 173 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 174 MAP_OPTIONS_SECONDARY_END() 175 else { tmpObject.data = p__.first, list.push_back(tmpObject); } 176 MAP_OPTIONS_END() 177 178 for (std::list<CPULoadConatiner>::const_iterator it = list.begin(); it != list.end(); ++it) { 179 CPULoadConatiner load = (*it); 173 180 PDHCollector *pObject = pdhThread.getThread(); 174 181 if (!pObject) { … … 176 183 return NSCAPI::returnUNKNOWN; 177 184 } 178 if (bNSC LientCompatible) {179 int v = pObject->getCPUAvrage((*it)+ "m");180 if (v == -1) {181 msg = "ERROR: We don't collect data this far back: " + (*it);185 if (bNSClient) { 186 int value = pObject->getCPUAvrage(load.data + "m"); 187 if (value == -1) { 188 msg = "ERROR: We don't collect data this far back: " + load.getAlias(); 182 189 return NSCAPI::returnUNKNOWN; 183 190 } 184 191 if (!msg.empty()) msg += "&"; 185 msg += strEx::itos(v );192 msg += strEx::itos(value); 186 193 } else { 187 int v = pObject->getCPUAvrage((*it));188 if (v == -1) {189 msg = "ERROR: We don't collect data this far back: " + (*it);194 int value = pObject->getCPUAvrage(load.data); 195 if (value == -1) { 196 msg = "ERROR: We don't collect data this far back: " + load.getAlias(); 190 197 return NSCAPI::returnUNKNOWN; 191 198 } else { 192 if (v > warn) { 193 NSCHelper::escalteReturnCodeToWARN(ret); 194 msg += strEx::itos(v) + "% > " + strEx::itos(warn) + " " + (*it); 195 } if (v > crit) { 196 NSCHelper::escalteReturnCodeToCRIT(ret); 197 msg += strEx::itos(v) + "% > " + strEx::itos(crit) + " " + (*it); 198 } else if (bShowAll) { 199 msg += strEx::itos(v) + "% "; 200 } 201 perf += "'" + (*it) + " average'=" + strEx::itos(v) + "%;" + strEx::itos(warn) + ";" + strEx::itos(crit) + "; "; 202 } 203 } 204 } 205 if (bNSCLientCompatible) { 206 // Don't prefix/postfix the output for NSClient 207 } else if (msg.empty()) { 208 msg = "CPU Load ok."; 209 } else { 210 msg = "CPU Load: " + msg; 211 } 212 return ret; 213 } 214 215 // checkUpTime crit=1d warn=6h 216 // checkUpTime nsclient 199 load.setDefault(tmpObject); 200 load.runCheck(value, returnCode, msg, perf, bShowAll); 201 } 202 } 203 } 204 205 if (msg.empty()) 206 msg = "OK CPU Load ok."; 207 else if (!bNSClient) 208 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 209 return returnCode; 210 } 211 217 212 NSCAPI::nagiosReturn CheckSystem::checkUpTime(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 218 213 { 214 typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsTime> UpTimeConatiner; 215 219 216 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 220 217 if (stl_args.empty()) { … … 222 219 return NSCAPI::returnUNKNOWN; 223 220 } 224 unsigned long long warn; 225 unsigned long long crit; 226 bool bNSCLientCompatible = false; 227 228 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 229 strEx::token t = strEx::getToken((*it), '='); 230 if (t.first == "crit") 231 crit = strEx::stoi64_as_time(t.second); 232 else if (t.first == "warn") 233 warn = strEx::stoi64_as_time(t.second); 234 else if (t.first == NSCLIENT) 235 bNSCLientCompatible = true; 236 else { 237 msg = "Invalid argument: " + t.first; 238 return NSCAPI::returnUNKNOWN; 239 } 240 } 221 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 222 bool bShowAll = false; 223 bool bNSClient = false; 224 UpTimeConatiner bounds; 225 226 bounds.data = "uptime"; 227 228 MAP_OPTIONS_BEGIN(stl_args) 229 MAP_OPTIONS_STR("MaxWarn", bounds.warn.max) 230 MAP_OPTIONS_STR("warn", bounds.warn.min) 231 MAP_OPTIONS_STR("MinWarn", bounds.warn.min) 232 MAP_OPTIONS_STR("MaxCrit", bounds.crit.max) 233 MAP_OPTIONS_STR("crit", bounds.crit.min) 234 MAP_OPTIONS_STR("MinCrit", bounds.crit.min) 235 MAP_OPTIONS_STR("Alias", bounds.data) 236 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 237 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 238 MAP_OPTIONS_MISSING(msg, "Unknown argument: ") 239 MAP_OPTIONS_END() 240 241 241 242 PDHCollector *pObject = pdhThread.getThread(); 242 243 if (!pObject) { … … 244 245 return NSCAPI::returnUNKNOWN; 245 246 } 246 unsigned long long uptime = pObject->getUptime(); 247 if (bNSCLientCompatible) { 248 msg = strEx::itos(uptime); 249 return NSCAPI::returnOK; 247 unsigned long long value = pObject->getUptime(); 248 if (bNSClient) { 249 msg = strEx::itos(value); 250 250 } else { 251 uptime *= 1000; 252 if (uptime < crit) { 253 msg = "Client has uptime (" + strEx::itos_as_time(uptime) + ") < critical (" + strEx::itos_as_time(crit) + ")"; 254 return NSCAPI::returnCRIT; 255 } 256 if (uptime < warn) { 257 msg = "Client has uptime (" + strEx::itos_as_time(uptime) + ") < warning (" + strEx::itos_as_time(warn) + ")"; 258 return NSCAPI::returnWARN; 259 } 260 } 261 return NSCAPI::returnOK; 262 } 263 251 value *= 1000; 252 bounds.runCheck(value, returnCode, msg, perf, bShowAll); 253 } 254 255 if (msg.empty()) 256 msg = "OK all counters within bounds."; 257 else if (!bNSClient) 258 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 259 return returnCode; 260 } 261 262 // @todo state_handler 264 263 265 264 … … 289 288 NSCAPI::nagiosReturn CheckSystem::checkServiceState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 290 289 { 290 typedef checkHolders::CheckConatiner<checkHolders::SimpleBoundsStateBoundsInteger> StateConatiner; 291 291 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 292 292 if (stl_args.empty()) { … … 294 294 return NSCAPI::returnUNKNOWN; 295 295 } 296 std::list< std::pair<std::string,states> > services;297 NSCAPI::nagiosReturn ret = NSCAPI::returnOK;296 std::list<StateConatiner> list; 297 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 298 298 bool bShowAll = false; 299 299 bool bNSClient = false; 300 301 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 302 strEx::token t = strEx::getToken((*it), '='); 303 if (t.first == SHOW_ALL) 304 bShowAll = true; 305 else if (t.first == NSCLIENT) 306 bNSClient = true; 307 else if (t.first == SHOW_FAIL) { 308 bShowAll = false; 300 StateConatiner tmpObject; 301 302 tmpObject.data = "uptime"; 303 tmpObject.warn.state = "started"; 304 305 MAP_OPTIONS_BEGIN(stl_args) 306 /* 307 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 308 MAP_OPTIONS_STR("warn", tmpObject.warn.min) 309 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 310 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 311 MAP_OPTIONS_STR("crit", tmpObject.crit.min) 312 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 313 */ 314 MAP_OPTIONS_STR("Alias", tmpObject.data) 315 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 316 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll) 317 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 318 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 319 else if (p2.first == "Time") { 320 tmpObject.data = p__.second; 321 tmpObject.alias = p2.second; 322 list.push_back(tmpObject); 323 } 324 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 325 MAP_OPTIONS_SECONDARY_END() 326 else { 327 tmpObject.data = p__.first; 328 if (p__.second.empty()) 329 tmpObject.crit.state = "started"; 330 else 331 tmpObject.crit.state = p__.second; 332 list.push_back(tmpObject); 333 } 334 MAP_OPTIONS_END() 335 336 for (std::list<StateConatiner>::iterator it = list.begin(); it != list.end(); ++it) { 337 TNtServiceInfo info; 338 if (bNSClient) { 339 try { 340 info = TNtServiceInfo::GetService((*it).data.c_str()); 341 } catch (NTServiceException e) { 342 if (!msg.empty()) msg += " - "; 343 msg += (*it).data + ": Unknown"; 344 NSCHelper::escalteReturnCodeToWARN(returnCode); 345 continue; 346 } 347 if ((info.m_dwCurrentState == SERVICE_RUNNING) && (bShowAll)) { 348 if (!msg.empty()) msg += " - "; 349 msg += (*it).data + ": Started"; 350 } else if (info.m_dwCurrentState == SERVICE_RUNNING) { 351 } else if (info.m_dwCurrentState == SERVICE_STOPPED) { 352 if (!msg.empty()) msg += " - "; 353 msg += (*it).data + ": Stopped"; 354 NSCHelper::escalteReturnCodeToCRIT(returnCode); 355 } else { 356 if (!msg.empty()) msg += " - "; 357 msg += (*it).data + ": Unknown"; 358 NSCHelper::escalteReturnCodeToWARN(returnCode); 359 } 309 360 } else { 310 if (t.second.empty()) 311 services.push_back(std::pair<std::string,states>(t.first, started)); 312 else { 313 if (t.second == "started") 314 services.push_back(std::pair<std::string,states>(t.first, started)); 315 else 316 services.push_back(std::pair<std::string,states>(t.first, stopped)); 317 } 318 } 319 } 320 for (std::list<std::pair<std::string,states> >::iterator it = services.begin(); it != services.end(); ++it) { 321 TNtServiceInfo info = TNtServiceInfo::GetService((*it).first.c_str()); 322 std::string tmp; 323 if ( (info.m_dwCurrentState == SERVICE_RUNNING) && ((*it).second == started) ) { 324 if (bShowAll) 325 tmp = info.m_strServiceName + " : Started"; 326 } else if ( (info.m_dwCurrentState == SERVICE_STOPPED) && ((*it).second == stopped) ) { 327 if (bShowAll) 328 tmp = info.m_strServiceName + " : Stopped"; 329 } else if ((info.m_dwCurrentState == SERVICE_STOPPED) && ((*it).second == started) ) { 330 NSCHelper::escalteReturnCodeToCRIT(ret); 331 tmp = info.m_strServiceName + " : Stopped"; 332 } else if ((info.m_dwCurrentState == SERVICE_RUNNING) && ((*it).second == stopped) ) { 333 NSCHelper::escalteReturnCodeToCRIT(ret); 334 tmp = info.m_strServiceName + " : Started"; 335 } else { 336 NSCHelper::escalteReturnCodeToWARN(ret); 337 tmp = info.m_strServiceName + " : Unknown"; 338 } 339 if (!msg.empty()&&!tmp.empty()) 340 msg += " - "; 341 msg += tmp; 361 try { 362 info = TNtServiceInfo::GetService((*it).data.c_str()); 363 } catch (NTServiceException e) { 364 NSC_LOG_ERROR_STD(e.getError()); 365 msg = e.getError(); 366 return NSCAPI::returnUNKNOWN; 367 } 368 checkHolders::state_type value; 369 if (info.m_dwCurrentState == SERVICE_RUNNING) 370 value = checkHolders::state_started; 371 else if (info.m_dwCurrentState == SERVICE_STOPPED) 372 value = checkHolders::state_stopped; 373 else 374 value = checkHolders::state_none; 375 (*it).runCheck(value, returnCode, msg, perf, bShowAll); 376 } 377 342 378 } 343 379 if (msg.empty()) 344 msg = "All services are running.";380 msg = "OK: All services are running."; 345 381 else if (!bNSClient) 346 msg = NSCHelper::translateReturn(ret ) + ": " + msg;347 return ret ;382 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 383 return returnCode; 348 384 } 349 385 … … 362 398 NSCAPI::nagiosReturn CheckSystem::checkMem(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 363 399 { 400 typedef checkHolders::CheckConatiner<checkHolders::MaxMinPercentageBoundsInt64 > MemoryConatiner; 364 401 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 365 402 if (stl_args.empty()) { … … 367 404 return NSCAPI::returnUNKNOWN; 368 405 } 369 std::list<std::pair<std::string,states> > services;370 406 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 371 407 bool bShowAll = false; 372 bool bNSCLientCompatible = false; 373 374 checkHolders::SizeMaxMinPercentage<> warn; 375 checkHolders::SizeMaxMinPercentage<> crit; 376 377 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 378 strEx::token t = strEx::getToken((*it), '='); 379 if (t.first == SHOW_ALL) 380 bShowAll = true; 381 else if (t.first == "MaxWarn") { 382 warn.max.set(t.second); 383 } else if (t.first == "MinWarn") { 384 warn.min.set(t.second); 385 } else if (t.first == "MaxCrit") { 386 crit.max.set(t.second); 387 } else if (t.first == "MinCrit") { 388 crit.min.set(t.second); 389 } else if (t.first == NSCLIENT) 390 bNSCLientCompatible = true; 391 else { 392 msg = "Invalid argument: " + t.first; 393 return NSCAPI::returnUNKNOWN; 394 } 395 } 408 bool bNSClient = false; 409 MemoryConatiner bounds; 410 411 bounds.data = "page"; 412 413 MAP_OPTIONS_BEGIN(stl_args) 414 MAP_OPTIONS_STR("MaxWarn", bounds.warn.max) 415 MAP_OPTIONS_STR("MinWarn", bounds.warn.min) 416 MAP_OPTIONS_STR("MaxCrit", bounds.crit.max) 417 MAP_OPTIONS_STR("MinCrit", bounds.crit.min) 418 MAP_OPTIONS_STR("Alias", bounds.data) 419 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 420 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 421 MAP_OPTIONS_MISSING(msg, "Unknown argument: ") 422 MAP_OPTIONS_END() 396 423 397 424 PDHCollector *pObject = pdhThread.getThread(); … … 402 429 long long pageCommit = pObject->getMemCommit(); 403 430 long long pageCommitLimit = pObject->getMemCommitLimit(); 404 if (bNSC LientCompatible) {431 if (bNSClient) { 405 432 msg = strEx::itos(pageCommitLimit) + "&" + strEx::itos(pageCommit); 406 433 return NSCAPI::returnOK; 407 434 } else { 408 std::string tStr; 409 if (crit.max.hasBounds() && crit.max.checkMAX(pageCommit, pageCommitLimit)) { 410 tStr = crit.max.prettyPrint("page", pageCommit, pageCommitLimit) + " > critical"; 411 NSCHelper::escalteReturnCodeToCRIT(returnCode); 412 } else if (crit.min.hasBounds() && crit.min.checkMIN(pageCommit, pageCommitLimit)) { 413 tStr = crit.min.prettyPrint("page", pageCommit, pageCommitLimit) + " < critical"; 414 NSCHelper::escalteReturnCodeToCRIT(returnCode); 415 } else if (warn.max.hasBounds() && warn.max.checkMAX(pageCommit, pageCommitLimit)) { 416 tStr = warn.max.prettyPrint("page", pageCommit, pageCommitLimit) + " > warning"; 417 NSCHelper::escalteReturnCodeToWARN(returnCode); 418 } else if (warn.min.hasBounds() && warn.min.checkMIN(pageCommit, pageCommitLimit)) { 419 tStr = warn.min.prettyPrint("page", pageCommit, pageCommitLimit) + " < warning"; 420 NSCHelper::escalteReturnCodeToWARN(returnCode); 421 } else if (bShowAll) { 422 tStr = "page: " + strEx::itos_as_BKMG(pageCommit); 423 } 424 perf += checkHolders::SizeMaxMinPercentage<>::printPerf("page", pageCommit, pageCommitLimit, warn, crit); 425 msg += tStr; 435 bounds.warn.max.setMax(pageCommitLimit); 436 bounds.warn.min.setMax(pageCommitLimit); 437 bounds.crit.max.setMax(pageCommitLimit); 438 bounds.crit.min.setMax(pageCommitLimit); 439 bounds.runCheck(pageCommit, returnCode, msg, perf, bShowAll); 426 440 } 427 441 if (msg.empty()) … … 431 445 return returnCode; 432 446 } 433 434 typedef std::hash_map<std::string,DWORD> NSPROCLST; 447 typedef struct NSPROCDATA__ { 448 NSPROCDATA__() : count(0) {} 449 NSPROCDATA__(const NSPROCDATA__ &other) { 450 count = other.count; 451 entry = other.entry; 452 } 453 454 unsigned int count; 455 CEnumProcess::CProcessEntry entry; 456 } NSPROCDATA; 457 typedef std::hash_map<std::string,NSPROCDATA> NSPROCLST; 435 458 /** 436 459 * Get a hash_map with all running processes. … … 448 471 CEnumProcess::CProcessEntry entry; 449 472 for (BOOL OK = enumeration.GetProcessFirst(&entry); OK; OK = enumeration.GetProcessNext(&entry) ) { 450 ret[entry.lpFilename] = entry.dwPID; 473 NSPROCLST::iterator it = ret.find(entry.sFilename); 474 if (it == ret.end()) 475 ret[entry.sFilename].entry = entry; 476 else 477 (*it).second.count++; 451 478 } 452 479 return ret; … … 465 492 NSCAPI::nagiosReturn CheckSystem::checkProcState(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 466 493 { 494 typedef checkHolders::CheckConatiner<checkHolders::MaxMinStateBoundsStateBoundsInteger> StateConatiner; 467 495 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 468 496 if (stl_args.empty()) { … … 470 498 return NSCAPI::returnUNKNOWN; 471 499 } 472 std::list< std::pair<std::string,states> > procs;473 NSCAPI::nagiosReturn ret = NSCAPI::returnOK;500 std::list<StateConatiner> list; 501 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 474 502 bool bShowAll = false; 475 503 bool bNSClient = false; 476 477 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 478 strEx::token t = strEx::getToken((*it), '='); 479 if (t.first == SHOW_ALL) 480 bShowAll = true; 481 else if (t.first == NSCLIENT) 482 bNSClient = true; 483 else if (t.first == SHOW_FAIL) { 484 bShowAll = false; 485 } else { 486 if (t.second.empty()) 487 procs.push_back(std::pair<std::string,states>(t.first, started)); 488 else { 489 if (t.second == "started") 490 procs.push_back(std::pair<std::string,states>(t.first, started)); 491 else 492 procs.push_back(std::pair<std::string,states>(t.first, stopped)); 493 } 494 } 495 } 504 StateConatiner tmpObject; 505 506 tmpObject.data = "uptime"; 507 tmpObject.crit.state = "started"; 508 509 MAP_OPTIONS_BEGIN(stl_args) 510 MAP_OPTIONS_STR("MaxWarnCount", tmpObject.warn.max) 511 MAP_OPTIONS_STR("MinWarnCount", tmpObject.warn.min) 512 MAP_OPTIONS_STR("MaxCritCount", tmpObject.crit.max) 513 MAP_OPTIONS_STR("MinCritCount", tmpObject.crit.min) 514 MAP_OPTIONS_STR("Alias", tmpObject.alias) 515 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 516 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll) 517 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 518 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 519 else if (p2.first == "Proc") { 520 tmpObject.data = p__.second; 521 tmpObject.alias = p2.second; 522 list.push_back(tmpObject); 523 } 524 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 525 MAP_OPTIONS_SECONDARY_END() 526 else { 527 tmpObject.data = p__.first; 528 if (p__.second.empty()) 529 tmpObject.crit.state = "started"; 530 else 531 tmpObject.crit.state = p__.second; 532 list.push_back(tmpObject); 533 } 534 MAP_OPTIONS_END() 535 536 496 537 NSPROCLST runningProcs; 497 538 try { … … 500 541 NSC_LOG_ERROR_STD("ERROR: " + c); 501 542 msg = static_cast<std::string>("ERROR: ") + c; 502 return NSCAPI::return CRIT;503 } 504 505 for (std::list< std::pair<std::string,states> >::iterator it = procs.begin(); it != procs.end(); ++it) {506 NSPROCLST::iterator proc = runningProcs.find((*it). first);543 return NSCAPI::returnUNKNOWN; 544 } 545 546 for (std::list<StateConatiner>::iterator it = list.begin(); it != list.end(); ++it) { 547 NSPROCLST::iterator proc = runningProcs.find((*it).data); 507 548 bool bFound = proc != runningProcs.end(); 508 549 std::string tmp; 509 if ( (bFound) && ((*it).second == started) ) { 510 if (bShowAll) 511 tmp = (*it).first + " : Running"; 512 } else if ( (!bFound) && ((*it).second == stopped) ) { 513 if (bShowAll) 514 tmp = (*it).first + " : Stopped"; 515 } else if ( (!bFound) && ((*it).second == started) ) { 516 NSCHelper::escalteReturnCodeToCRIT(ret); 517 tmp = (*it).first + " : Stopped"; 518 } else if ( (bFound) && ((*it).second == stopped) ) { 519 NSCHelper::escalteReturnCodeToCRIT(ret); 520 tmp = (*it).first + " : Running"; 521 } 522 if (!msg.empty()&&!tmp.empty()) 523 msg += " - "; 524 msg += tmp; 550 TNtServiceInfo info; 551 if (bNSClient) { 552 if (bFound && bShowAll) { 553 if (!msg.empty()) msg += " - "; 554 msg += (*it).data + ": Started"; 555 } else if (bFound) { 556 } else { 557 if (!msg.empty()) msg += " - "; 558 msg += (*it).data + ": Stopped"; 559 NSCHelper::escalteReturnCodeToCRIT(returnCode); 560 } 561 } else { 562 checkHolders::MaxMinStateValueType<int, checkHolders::state_type> value; 563 if (bFound) { 564 value.count = (*proc).second.count; 565 value.state = checkHolders::state_started; 566 } else { 567 value.count = 0; 568 value.state = checkHolders::state_stopped; 569 } 570 (*it).runCheck(value, returnCode, msg, perf, bShowAll); 571 } 572 525 573 } 526 574 if (msg.empty()) 527 msg = "All processes ok.";575 msg = "OK: All processes are running."; 528 576 else if (!bNSClient) 529 msg = NSCHelper::translateReturn(ret) + ": " + msg; 530 return ret; 531 } 577 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 578 return returnCode; 579 } 580 532 581 533 582 /** … … 545 594 NSCAPI::nagiosReturn CheckSystem::checkCounter(const unsigned int argLen, char **char_args, std::string &msg, std::string &perf) 546 595 { 596 typedef checkHolders::CheckConatiner<checkHolders::MaxMinBoundsDouble> CounterConatiner; 597 547 598 std::list<std::string> stl_args = arrayBuffer::arrayBuffer2list(argLen, char_args); 548 599 if (stl_args.empty()) { … … 550 601 return NSCAPI::returnUNKNOWN; 551 602 } 552 std::list< std::pair<std::string,std::string>> counters;603 std::list<CounterConatiner> counters; 553 604 NSCAPI::nagiosReturn returnCode = NSCAPI::returnOK; 554 605 bool bShowAll = false; 555 bool bNSCLientCompatible = false; 556 557 checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> > warn; 558 checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> > crit; 559 560 for (arrayBuffer::arrayList::const_iterator it = stl_args.begin(); it != stl_args.end(); ++it) { 561 strEx::token t = strEx::getToken((*it), '='); 562 if (t.first == SHOW_ALL) 563 bShowAll = true; 564 else if (t.first == SHOW_FAIL) { 565 bShowAll = false; 566 } else if (t.first == "MaxWarn") { 567 warn.max.set(t.second); 568 } else if (t.first == "MinWarn") { 569 warn.min.set(t.second); 570 } else if (t.first == "MaxCrit") { 571 crit.max.set(t.second); 572 } else if (t.first == "MinCrit") { 573 crit.min.set(t.second); 574 } else if (t.first == NSCLIENT) { 575 bNSCLientCompatible = true; 576 } else if (t.first == "Counter") { 577 counters.push_back(std::pair<std::string,std::string>("",t.second)); 578 } else if (t.first.find(":") != std::string::npos) { 579 std::pair<std::string,std::string> t2 = strEx::split(t.first,":"); 580 if (t2.first == "Counter") { 581 counters.push_back(std::pair<std::string,std::string>(t2.second,t.second)); 582 } else { 583 msg = "Unknown command: " + t.first; 606 bool bNSClient = false; 607 /* average maax */ 608 bool bCheckAverages = true; 609 unsigned int averageDelay = 1000; 610 CounterConatiner tmpObject; 611 612 MAP_OPTIONS_BEGIN(stl_args) 613 MAP_OPTIONS_STR_AND("Counter", tmpObject.data, counters.push_back(tmpObject)) 614 MAP_OPTIONS_STR("MaxWarn", tmpObject.warn.max) 615 MAP_OPTIONS_STR("MinWarn", tmpObject.warn.min) 616 MAP_OPTIONS_STR("MaxCrit", tmpObject.crit.max) 617 MAP_OPTIONS_STR("MinCrit", tmpObject.crit.min) 618 MAP_OPTIONS_STR("Alias", tmpObject.data) 619 MAP_OPTIONS_BOOL_TRUE(SHOW_ALL, bShowAll) 620 MAP_OPTIONS_BOOL_FALSE(SHOW_FAIL, bShowAll) 621 MAP_OPTIONS_BOOL_EX("Averages", bCheckAverages, "true", "false") 622 MAP_OPTIONS_BOOL_TRUE(NSCLIENT, bNSClient) 623 MAP_OPTIONS_SECONDARY_BEGIN(":", p2) 624 else if (p2.first == "Counter") { 625 tmpObject.data = p__.second; 626 tmpObject.alias = p2.second; 627 counters.push_back(tmpObject); 628 } 629 MAP_OPTIONS_MISSING_EX(p2, msg, "Unknown argument: ") 630 MAP_OPTIONS_SECONDARY_END() 631 else { 632 tmpObject.data = p__.first; 633 counters.push_back(tmpObject); 634 } 635 MAP_OPTIONS_END() 636 637 for (std::list<CounterConatiner>::const_iterator cit = counters.begin(); cit != counters.end(); ++cit) { 638 CounterConatiner counter = (*cit); 639 try { 640 std::string tstr; 641 if (!PDH::Enumerations::validate(counter.data, tstr)) { 642 msg = tstr; 584 643 return NSCAPI::returnUNKNOWN; 585 644 } 586 } else {587 counters.push_back(std::pair<std::string,std::string>("",t.first));588 }589 }590 591 for (std::list<std::pair<std::string,std::string> >::iterator it = counters.begin(); it != counters.end(); ++it) {592 std::string name;593 try {594 645 PDH::PDHQuery pdh; 595 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> counter; 596 std::string name = (*it).first; 597 if (name.empty()) 598 name = (*it).second; 599 pdh.addCounter((*it).second, &counter); 646 PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 647 pdh.addCounter(counter.data, &cDouble); 600 648 pdh.open(); 601 649 pdh.collect(); 602 if (bNSCLientCompatible) { 603 msg += strEx::itos(counter.getValue()); 650 Sleep(1000); 651 pdh.gatherData(); 652 pdh.close(); 653 double value = cDouble.getValue(); 654 std::cout << "Collected double data: " << value << std::endl; 655 if (bNSClient) { 656 msg += strEx::itos(value); 604 657 } else { 605 std::string tStr; 606 if (crit.max.hasBounds() && crit.max.checkMAX(counter.getValue())) { 607 tStr = crit.max.prettyPrint(name, counter.getValue()) + " > critical"; 608 NSCHelper::escalteReturnCodeToCRIT(returnCode); 609 } else if (crit.min.hasBounds() && crit.min.checkMIN(counter.getValue())) { 610 tStr = crit.min.prettyPrint(name, counter.getValue()) + " < critical"; 611 NSCHelper::escalteReturnCodeToCRIT(returnCode); 612 } else if (warn.max.hasBounds() && warn.max.checkMAX(counter.getValue())) { 613 tStr = warn.max.prettyPrint(name, counter.getValue()) + " > warning"; 614 NSCHelper::escalteReturnCodeToWARN(returnCode); 615 } else if (warn.min.hasBounds() && warn.min.checkMIN(counter.getValue())) { 616 tStr = warn.min.prettyPrint(name, counter.getValue()) + " < warning"; 617 NSCHelper::escalteReturnCodeToWARN(returnCode); 618 } else if (bShowAll) { 619 tStr = name + ": " + strEx::itos(counter.getValue()); 620 } 621 perf += checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> >::printPerf(name, counter.getValue(), warn, crit); 622 msg += tStr; 623 } 624 pdh.close(); 625 } catch (const PDH::PDHException &e) { 626 NSC_LOG_ERROR_STD("ERROR: " + e.str_ + " (" + name + ")"); 627 msg = static_cast<std::string>("ERROR: ") + e.str_; 628 return 0; 629 } 630 } 658 counter.setDefault(tmpObject); 659 counter.runCheck(value, returnCode, msg, perf, bShowAll); 660 } 661 } catch (const PDH::PDHException e) { 662 NSC_LOG_ERROR_STD("ERROR: " + e.getError() + " (" + counter.getAlias() + ")"); 663 msg = static_cast<std::string>("ERROR: ") + e.getError(); 664 return NSCAPI::returnUNKNOWN; 665 } 666 } 667 631 668 if (msg.empty()) 632 669 msg = "OK all counters within bounds."; 633 else if (!bNSC LientCompatible)670 else if (!bNSClient) 634 671 msg = NSCHelper::translateReturn(returnCode) + ": " + msg; 635 672 return returnCode; … … 638 675 NSC_WRAPPERS_IGNORE_MSG_DEF(); 639 676 NSC_WRAPPERS_HANDLE_CMD_DEF(gNSClientCompat); 677 NSC_WRAPPERS_HANDLE_CONFIGURATION(gNSClientCompat); 678 679 680 681 MODULE_SETTINGS_START(CheckSystem, "System check module", "...") 682 683 PAGE("Check options") 684 685 ITEM_EDIT_TEXT("Check resolution", "This is how often the PDH data is polled and stored in the CPU buffer. (this is enterd in 1/th: of a second)") 686 OPTION("unit", "1/10:th of a second") 687 ITEM_MAP_TO("basic_ini_text_mapper") 688 OPTION("section", "Check System") 689 OPTION("key", "CheckResolution") 690 OPTION("default", "10") 691 ITEM_END() 692 693 ITEM_EDIT_TEXT("CPU buffer size", "This is the size of the buffer that stores CPU history.") 694 ITEM_MAP_TO("basic_ini_text_mapper") 695 OPTION("section", "Check System") 696 OPTION("key", "CPUBufferSize") 697 OPTION("default", "1h") 698 ITEM_END() 699 700 PAGE_END() 701 ADVANCED_PAGE("Compatiblity settings") 702 703 ITEM_EDIT_TEXT("MemoryCommitByte", "The memory commited bytes used to calculate the avalible memory.") 704 OPTION("disableCaption", "Attempt to autodetect this.") 705 OPTION("disabled", "auto") 706 ITEM_MAP_TO("basic_ini_text_mapper") 707 OPTION("section", "Check System") 708 OPTION("key", "MemoryCommitByte") 709 OPTION("default", "auto") 710 ITEM_END() 711 712 ITEM_EDIT_TEXT("MemoryCommitLimit", "The memory commit limit used to calculate the avalible memory.") 713 OPTION("disableCaption", "Attempt to autodetect this.") 714 OPTION("disabled", "auto") 715 ITEM_MAP_TO("basic_ini_text_mapper") 716 OPTION("section", "Check System") 717 OPTION("key", "MemoryCommitLimit") 718 OPTION("default", "auto") 719 ITEM_END() 720 721 ITEM_EDIT_TEXT("SystemSystemUpTime", "The PDH counter for the System uptime.") 722 OPTION("disableCaption", "Attempt to autodetect this.") 723 OPTION("disabled", "auto") 724 ITEM_MAP_TO("basic_ini_text_mapper") 725 OPTION("section", "Check System") 726 OPTION("key", "SystemSystemUpTime") 727 OPTION("default", "auto") 728 ITEM_END() 729 730 ITEM_EDIT_TEXT("SystemTotalProcessorTime", "The PDH conter usaed to measure CPU load.") 731 OPTION("disableCaption", "Attempt to autodetect this.") 732 OPTION("disabled", "auto") 733 ITEM_MAP_TO("basic_ini_text_mapper") 734 OPTION("section", "Check System") 735 OPTION("key", "SystemTotalProcessorTime") 736 OPTION("default", "auto") 737 ITEM_END() 738 739 ITEM_EDIT_TEXT("ProcessEnumerationMethod", "The method to use when enumerating processes") 740 OPTION("count", "3") 741 OPTION("caption_1", "Autodetect (TOOLHELP for NT/4 and PSAPI for W2k)") 742 OPTION("value_1", "auto") 743 OPTION("caption_2", "TOOLHELP use this for NT/4 systems") 744 OPTION("value_2", "TOOLHELP") 745 OPTION("caption_3", "PSAPI use this for W2k (and abowe) systems") 746 OPTION("value_3", "PSAPI") 747 ITEM_MAP_TO("basic_ini_text_mapper") 748 OPTION("section", "Check System") 749 OPTION("key", "ProcessEnumerationMethod") 750 OPTION("default", "auto") 751 ITEM_END() 752 753 PAGE_END() 754 MODULE_SETTINGS_END() -
trunk/modules/CheckSystem/CheckSystem.def
r5d8e0b5 r24f7192 11 11 NSHandleCommand 12 12 NSUnloadModule 13 13 NSGetConfigurationMeta 14 NSGetModuleDescription -
trunk/modules/CheckSystem/CheckSystem.h
rf896cfb r24f7192 25 25 bool loadModule(); 26 26 bool unloadModule(); 27 std::string getModuleName(); 28 NSCModuleWrapper::module_version getModuleVersion(); 27 std::string getConfigurationMeta(); 28 29 /** 30 * Return the module name. 31 * @return The module name 32 */ 33 std::string getModuleName() { 34 return "System Checks Module."; 35 } 36 /** 37 * Module version 38 * @return module version 39 */ 40 NSCModuleWrapper::module_version getModuleVersion() { 41 NSCModuleWrapper::module_version version = {0, 3, 0 }; 42 return version; 43 } 44 std::string getModuleDescription() { 45 return "Various system related checks, such as CPU load, process state, service state memory usage and PDH counters."; 46 } 47 29 48 bool hasCommandHandler(); 30 49 bool hasMessageHandler(); -
trunk/modules/CheckSystem/CheckSystem.vcproj
rf22f5a9 r24f7192 214 214 </File> 215 215 <File 216 RelativePath="..\..\include\sysinfo.cpp"> 217 <FileConfiguration 218 Name="Debug|Win32"> 219 <Tool 220 Name="VCCLCompilerTool" 221 UsePrecompiledHeader="0"/> 222 </FileConfiguration> 223 <FileConfiguration 224 Name="Release|Win32"> 225 <Tool 226 Name="VCCLCompilerTool" 227 UsePrecompiledHeader="0"/> 228 </FileConfiguration> 229 <FileConfiguration 230 Name="Distribution|Win32"> 231 <Tool 232 Name="VCCLCompilerTool" 233 UsePrecompiledHeader="0"/> 234 </FileConfiguration> 235 </File> 236 <File 216 237 RelativePath="..\..\include\utils.cpp"> 217 238 <FileConfiguration -
trunk/modules/CheckSystem/PDHCollector.cpp
re93e741 r24f7192 20 20 #include "stdafx.h" 21 21 #include "PDHCollector.h" 22 #include <Settings.h> 23 #include <sysinfo.h> 22 24 23 25 … … 56 58 } 57 59 PDH::PDHQuery pdh; 58 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 59 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 60 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 61 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 60 61 62 if (NSCModuleHelper::getSettingsInt(C_SYSTEM_SECTION_TITLE, C_SYSTEM_AUTODETECT_PDH, C_SYSTEM_AUTODETECT_PDH_DEFAULT) == 1) { 63 64 SettingsT settings; 65 std::string prefix; 66 std::string section; 67 settings.setFile(NSCModuleHelper::getBasePath() + "\\counters.defs"); 68 69 70 try { 71 OSVERSIONINFO osVer = systemInfo::getOSVersion(); 72 if (!systemInfo::isNTBased(osVer)) { 73 NSC_LOG_ERROR_STD("Detected Windows 3.x or Windows 9x, PDH will be disabled."); 74 NSC_LOG_ERROR_STD("To manual set performance counters you need to first set " C_SYSTEM_AUTODETECT_PDH "=0 in the config file, and then you also need to configure the various counter."); 75 return 0; 76 } 77 78 LANGID langId = -1; 79 if (systemInfo::isBelowNT4(osVer)) { 80 NSC_DEBUG_MSG_STD("Autodetected NT4, using NT4 PDH counters."); 81 prefix = "NT4"; 82 langId = systemInfo::GetSystemDefaultLangID(); 83 } else if (systemInfo::isAboveW2K(osVer)) { 84 NSC_DEBUG_MSG_STD("Autodetected w2k or later, using w2k PDH counters."); 85 prefix = "W2K"; 86 langId = systemInfo::GetSystemDefaultUILanguage(); 87 } else { 88 NSC_LOG_ERROR_STD("Unknown OS detected, PDH will be disabled."); 89 NSC_LOG_ERROR_STD("To manual set performance counters you need to first set " C_SYSTEM_AUTODETECT_PDH "=0 in the config file, and then you also need to configure the various counter."); 90 return 0; 91 } 92 93 section = "0000" + strEx::ihextos(langId); 94 section = "0x" + section.substr(section.length()-4); 95 NSC_DEBUG_MSG_STD("Detected language: " + settings.getString(section, "Description", "Not found") + " (" + section + ")"); 96 } catch (systemInfo::SystemInfoException e) { 97 NSC_LOG_ERROR_STD("System detection failed, PDH will be disabled: " + e.error_); 98 NSC_LOG_ERROR_STD("To manual set performance counters you need to first set " C_SYSTEM_AUTODETECT_PDH "=0 in the config file, and then you also need to configure the various counter."); 99 return -1; 100 } 101 102 pdh.addCounter(settings.getString(section, prefix + "_" + C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 103 pdh.addCounter(settings.getString(section, prefix + "_" + C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 104 pdh.addCounter(settings.getString(section, prefix + "_" + C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 105 pdh.addCounter(settings.getString(section, prefix + "_" + C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 106 } else { 107 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 108 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 109 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 110 pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 111 } 62 112 63 113 try { 64 114 pdh.open(); 65 115 } catch (const PDH::PDHException &e) { 66 NSC_LOG_ERROR_STD("Failed to open performance counters: " + e. str_);116 NSC_LOG_ERROR_STD("Failed to open performance counters: " + e.getError()); 67 117 return 0; 68 118 } 69 119 70 120 121 DWORD waitStatus = 0; 71 122 do { 72 123 MutexLock mutex(mutexHandler); … … 75 126 else { 76 127 try { 77 pdh. collect();128 pdh.gatherData(); 78 129 } catch (const PDH::PDHException &e) { 79 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e. str_);130 NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 80 131 } 81 132 } 82 }while (!(WaitForSingleObject(hStopEvent_, checkIntervall_*100) == WAIT_OBJECT_0)); 133 }while (((waitStatus = WaitForSingleObject(hStopEvent_, checkIntervall_*100)) == WAIT_TIMEOUT)); 134 if (waitStatus != WAIT_OBJECT_0) { 135 NSC_LOG_ERROR("Something odd happend, terminating PDH collection thread!"); 136 } 83 137 84 138 { … … 95 149 pdh.close(); 96 150 } catch (const PDH::PDHException &e) { 97 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e. str_);151 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.getError()); 98 152 } 99 153 } … … 130 184 return -1; 131 185 } 132 return cpu.getAvrage(mseconds / (checkIntervall_*100));186 return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 133 187 } 134 188 /** -
trunk/modules/CheckSystem/PDHCollector.h
re93e741 r24f7192 30 30 int checkIntervall_; 31 31 32 PDHCollectors::StaticPDHCounterListener<__int64, PDH _FMT_LARGE> memCmtLim;33 PDHCollectors::StaticPDHCounterListener<__int64, PDH _FMT_LARGE> memCmt;34 PDHCollectors::StaticPDHCounterListener<__int64, PDH _FMT_LARGE> upTime;35 PDHCollectors::RoundINTPDHBufferListener<__int64, PDH _FMT_LARGE> cpu;32 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large> memCmtLim; 33 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large> memCmt; 34 PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large> upTime; 35 PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large> cpu; 36 36 37 37 public:
Note: See TracChangeset
for help on using the changeset viewer.








