Changeset 3b8eb61 in nscp for trunk/modules/CheckSystem


Ignore:
Timestamp:
05/18/05 22:46:09 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
7da80b5
Parents:
f896cfb
Message:

2005-05-18 MickeM

  • Fixed bug in NSC.ini (section title for Check System was wrong) + Added multitasking for plugins (now two plugins can handle requests simultaniously)
  • Fixed som minor issues here and there
Location:
trunk/modules/CheckSystem
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/CheckSystem/CheckSystem.cpp

    rf896cfb r3b8eb61  
    4848 
    4949  if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 
     50    NSC_DEBUG_MSG_STD("Using PSAPI method."); 
    5051    if (method == (method|ENUM_METHOD::PSAPI)) { 
    5152      processMethod_ = ENUM_METHOD::PSAPI; 
    5253    } else { 
    53       NSC_LOG_ERROR_STD("PSAPI method not avalible, check " C_SYSTEM_ENUMPROC_METHOD " option."); 
     54      NSC_LOG_ERROR_STD("PSAPI method not available, check " C_SYSTEM_ENUMPROC_METHOD " option."); 
    5455    } 
    5556  } else { 
     57    NSC_DEBUG_MSG_STD("Using TOOLHELP method."); 
    5658    if (method == (method|ENUM_METHOD::TOOLHELP)) { 
    5759      processMethod_ = ENUM_METHOD::TOOLHELP; 
     
    6870 */ 
    6971bool CheckSystem::unloadModule() { 
    70   if (!pdhThread.exitThread(20000)) 
     72  if (!pdhThread.exitThread(20000)) { 
     73    std::cout << "MAJOR ERROR: Could not unload thread..." << std::endl; 
    7174    NSC_LOG_ERROR("Could not exit the thread, memory leak and potential corruption may be the result..."); 
     75  } 
    7276  return true; 
    7377} 
     
    168172  for (std::list<std::string>::iterator it = times.begin(); it != times.end(); ++it) { 
    169173    PDHCollector *pObject = pdhThread.getThread(); 
    170     assert(pObject); 
     174    if (!pObject) { 
     175      msg = "ERROR: PDH Collection thread not running."; 
     176      return NSCAPI::returnUNKNOWN; 
     177    } 
    171178    if (bNSCLientCompatible) { 
    172179      int v = pObject->getCPUAvrage((*it) + "m"); 
     
    233240  } 
    234241  PDHCollector *pObject = pdhThread.getThread(); 
    235   assert(pObject); 
     242  if (!pObject) { 
     243    msg = "ERROR: PDH Collection thread not running."; 
     244    return NSCAPI::returnUNKNOWN; 
     245  } 
    236246  unsigned long long uptime = pObject->getUptime(); 
    237247  if (bNSCLientCompatible) { 
     
    381391 
    382392  PDHCollector *pObject = pdhThread.getThread(); 
    383   assert(pObject); 
     393  if (!pObject) { 
     394    msg = "ERROR: PDH Collection thread not running."; 
     395    return NSCAPI::returnUNKNOWN; 
     396  } 
    384397  long long pageCommit = pObject->getMemCommit();  
    385398  long long pageCommitLimit = pObject->getMemCommitLimit();  
     
    567580 
    568581  for (std::list<std::pair<std::string,std::string> >::iterator it = counters.begin(); it != counters.end(); ++it) { 
     582    std::string name; 
    569583    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()); 
    600610        } 
    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; 
    607613      } 
    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 + ")"); 
    610617      msg = static_cast<std::string>("ERROR: ") + e.str_; 
    611       return NSCAPI::returnCRIT; 
     618      return 0; 
    612619    } 
    613620  } 
  • trunk/modules/CheckSystem/PDHCollector.cpp

    rae192e3 r3b8eb61  
    8282  }while (!(WaitForSingleObject(hStopEvent_, checkIntervall_*100) == WAIT_OBJECT_0)); 
    8383 
    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    } 
    9299  } 
    93100  return 0; 
     
    99106 */ 
    100107void 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  } 
    101113  if (hStopEvent_ == NULL) 
    102     NSC_LOG_ERROR("Failed to get Mutex!"); 
     114    NSC_LOG_ERROR("Failed to get stop event!"); 
    103115  else 
    104116    if (!SetEvent(hStopEvent_)) { 
  • trunk/modules/CheckSystem/PDHCollector.h

    r5d8e0b5 r3b8eb61  
    4949 
    5050private: 
    51   bool isRunning(void); 
    52   void startRunning(void); 
    53   void stopRunning(void); 
     51//  bool isRunning(void); 
     52//  void startRunning(void); 
     53//  void stopRunning(void); 
    5454 
    5555}; 
Note: See TracChangeset for help on using the changeset viewer.