Changeset 3b8eb61 in nscp for trunk/modules/CheckSystem
- Timestamp:
- 05/18/05 22:46:09 (8 years ago)
- Children:
- 7da80b5
- Parents:
- f896cfb
- Location:
- trunk/modules/CheckSystem
- Files:
-
- 3 edited
-
CheckSystem.cpp (modified) (6 diffs)
-
PDHCollector.cpp (modified) (2 diffs)
-
PDHCollector.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/CheckSystem/CheckSystem.cpp
rf896cfb r3b8eb61 48 48 49 49 if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 50 NSC_DEBUG_MSG_STD("Using PSAPI method."); 50 51 if (method == (method|ENUM_METHOD::PSAPI)) { 51 52 processMethod_ = ENUM_METHOD::PSAPI; 52 53 } else { 53 NSC_LOG_ERROR_STD("PSAPI method not ava lible, check " C_SYSTEM_ENUMPROC_METHOD " option.");54 NSC_LOG_ERROR_STD("PSAPI method not available, check " C_SYSTEM_ENUMPROC_METHOD " option."); 54 55 } 55 56 } else { 57 NSC_DEBUG_MSG_STD("Using TOOLHELP method."); 56 58 if (method == (method|ENUM_METHOD::TOOLHELP)) { 57 59 processMethod_ = ENUM_METHOD::TOOLHELP; … … 68 70 */ 69 71 bool CheckSystem::unloadModule() { 70 if (!pdhThread.exitThread(20000)) 72 if (!pdhThread.exitThread(20000)) { 73 std::cout << "MAJOR ERROR: Could not unload thread..." << std::endl; 71 74 NSC_LOG_ERROR("Could not exit the thread, memory leak and potential corruption may be the result..."); 75 } 72 76 return true; 73 77 } … … 168 172 for (std::list<std::string>::iterator it = times.begin(); it != times.end(); ++it) { 169 173 PDHCollector *pObject = pdhThread.getThread(); 170 assert(pObject); 174 if (!pObject) { 175 msg = "ERROR: PDH Collection thread not running."; 176 return NSCAPI::returnUNKNOWN; 177 } 171 178 if (bNSCLientCompatible) { 172 179 int v = pObject->getCPUAvrage((*it) + "m"); … … 233 240 } 234 241 PDHCollector *pObject = pdhThread.getThread(); 235 assert(pObject); 242 if (!pObject) { 243 msg = "ERROR: PDH Collection thread not running."; 244 return NSCAPI::returnUNKNOWN; 245 } 236 246 unsigned long long uptime = pObject->getUptime(); 237 247 if (bNSCLientCompatible) { … … 381 391 382 392 PDHCollector *pObject = pdhThread.getThread(); 383 assert(pObject); 393 if (!pObject) { 394 msg = "ERROR: PDH Collection thread not running."; 395 return NSCAPI::returnUNKNOWN; 396 } 384 397 long long pageCommit = pObject->getMemCommit(); 385 398 long long pageCommitLimit = pObject->getMemCommitLimit(); … … 567 580 568 581 for (std::list<std::pair<std::string,std::string> >::iterator it = counters.begin(); it != counters.end(); ++it) { 582 std::string name; 569 583 try { 570 try { 571 PDH::PDHQuery pdh; 572 PDHCollectors::StaticPDHCounterListener counter; 573 pdh.addCounter((*it).second, &counter); 574 pdh.open(); 575 pdh.collect(); 576 std::string name = (*it).first; 577 if (name.empty()) 578 name = (*it).second; 579 if (bNSCLientCompatible) { 580 msg += strEx::itos(counter.getValue()); 581 } else { 582 std::string tStr; 583 if (crit.max.hasBounds() && crit.max.checkMAX(counter.getValue())) { 584 tStr = crit.max.prettyPrint(name, counter.getValue()) + " > critical"; 585 NSCHelper::escalteReturnCodeToCRIT(returnCode); 586 } else if (crit.min.hasBounds() && crit.min.checkMIN(counter.getValue())) { 587 tStr = crit.min.prettyPrint(name, counter.getValue()) + " < critical"; 588 NSCHelper::escalteReturnCodeToCRIT(returnCode); 589 } else if (warn.max.hasBounds() && warn.max.checkMAX(counter.getValue())) { 590 tStr = warn.max.prettyPrint(name, counter.getValue()) + " > warning"; 591 NSCHelper::escalteReturnCodeToWARN(returnCode); 592 } else if (warn.min.hasBounds() && warn.min.checkMIN(counter.getValue())) { 593 tStr = warn.min.prettyPrint(name, counter.getValue()) + " < warning"; 594 NSCHelper::escalteReturnCodeToWARN(returnCode); 595 } else if (bShowAll) { 596 tStr = name + ": " + strEx::itos(counter.getValue()); 597 } 598 perf += checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> >::printPerf(name, counter.getValue(), warn, crit); 599 msg += tStr; 584 PDH::PDHQuery pdh; 585 PDHCollectors::StaticPDHCounterListener counter; 586 std::string name = (*it).first; 587 if (name.empty()) 588 name = (*it).second; 589 pdh.addCounter((*it).second, &counter); 590 pdh.open(); 591 pdh.collect(); 592 if (bNSCLientCompatible) { 593 msg += strEx::itos(counter.getValue()); 594 } else { 595 std::string tStr; 596 if (crit.max.hasBounds() && crit.max.checkMAX(counter.getValue())) { 597 tStr = crit.max.prettyPrint(name, counter.getValue()) + " > critical"; 598 NSCHelper::escalteReturnCodeToCRIT(returnCode); 599 } else if (crit.min.hasBounds() && crit.min.checkMIN(counter.getValue())) { 600 tStr = crit.min.prettyPrint(name, counter.getValue()) + " < critical"; 601 NSCHelper::escalteReturnCodeToCRIT(returnCode); 602 } else if (warn.max.hasBounds() && warn.max.checkMAX(counter.getValue())) { 603 tStr = warn.max.prettyPrint(name, counter.getValue()) + " > warning"; 604 NSCHelper::escalteReturnCodeToWARN(returnCode); 605 } else if (warn.min.hasBounds() && warn.min.checkMIN(counter.getValue())) { 606 tStr = warn.min.prettyPrint(name, counter.getValue()) + " < warning"; 607 NSCHelper::escalteReturnCodeToWARN(returnCode); 608 } else if (bShowAll) { 609 tStr = name + ": " + strEx::itos(counter.getValue()); 600 610 } 601 602 pdh.close(); 603 } catch (const PDH::PDHException &e) { 604 NSC_LOG_ERROR_STD("ERROR: " + e.str_); 605 msg = static_cast<std::string>("ERROR: ") + e.str_; 606 return 0; 611 perf += checkHolders::SizeMaxMin<__int64, checkHolders::int64_handler<> >::printPerf(name, counter.getValue(), warn, crit); 612 msg += tStr; 607 613 } 608 } catch (PDH::PDHException e) { 609 NSC_LOG_ERROR_STD("ERROR: " + e.str_); 614 pdh.close(); 615 } catch (const PDH::PDHException &e) { 616 NSC_LOG_ERROR_STD("ERROR: " + e.str_ + " (" + name + ")"); 610 617 msg = static_cast<std::string>("ERROR: ") + e.str_; 611 return NSCAPI::returnCRIT;618 return 0; 612 619 } 613 620 } -
trunk/modules/CheckSystem/PDHCollector.cpp
rae192e3 r3b8eb61 82 82 }while (!(WaitForSingleObject(hStopEvent_, checkIntervall_*100) == WAIT_OBJECT_0)); 83 83 84 if (!CloseHandle(hStopEvent_)) 85 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 86 else 87 hStopEvent_ = NULL; 88 try { 89 pdh.close(); 90 } catch (const PDH::PDHException &e) { 91 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 84 { 85 MutexLock mutex(mutexHandler); 86 if (!mutex.hasMutex()) { 87 NSC_LOG_ERROR("Failed to get Mute when closing thread!"); 88 } 89 90 if (!CloseHandle(hStopEvent_)) 91 NSC_LOG_ERROR_STD("Failed to close stopEvent handle: " + strEx::itos(GetLastError())); 92 else 93 hStopEvent_ = NULL; 94 try { 95 pdh.close(); 96 } catch (const PDH::PDHException &e) { 97 NSC_LOG_ERROR_STD("Failed to close performance counters: " + e.str_); 98 } 92 99 } 93 100 return 0; … … 99 106 */ 100 107 void PDHCollector::exitThread(void) { 108 MutexLock mutex(mutexHandler); 109 if (!mutex.hasMutex()) { 110 NSC_LOG_ERROR("Failed to get Mute when trying to close thread!"); 111 return; 112 } 101 113 if (hStopEvent_ == NULL) 102 NSC_LOG_ERROR("Failed to get Mutex!");114 NSC_LOG_ERROR("Failed to get stop event!"); 103 115 else 104 116 if (!SetEvent(hStopEvent_)) { -
trunk/modules/CheckSystem/PDHCollector.h
r5d8e0b5 r3b8eb61 49 49 50 50 private: 51 bool isRunning(void);52 void startRunning(void);53 void stopRunning(void);51 // bool isRunning(void); 52 // void startRunning(void); 53 // void stopRunning(void); 54 54 55 55 };
Note: See TracChangeset
for help on using the changeset viewer.








