Changeset 34f5502 in nscp for trunk/modules/CheckSystem


Ignore:
Timestamp:
02/18/08 23:21:23 (5 years ago)
Author:
Michael Medin <michael@…>
Children:
087a3c9
Parents:
e0936e3
Message:

+ Added propper output handling to process subsystem (now you can execute programs tat return "much" data.

+ Added select support for SSL_write (now you can send "any amount of data" to the (SSL) socket.

Since check_nrpe doesn't do this it wont work in that end, but still...

Location:
trunk/modules/CheckSystem
Files:
3 edited

Legend:

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

    r907d5b0 r34f5502  
    402402    int value = pObject->getCPUAvrage(load.data + _T("m")); 
    403403    if (value == -1) { 
    404       msg = _T("ERROR: We don't collect data this far back: ") + load.getAlias(); 
     404      msg = _T("ERROR: Could not get data for ") + load.getAlias() + _T(" perhaps we don't collect data this far back?"); 
    405405      return NSCAPI::returnUNKNOWN; 
    406406    } 
     
    720720    } 
    721721  } 
    722   NSC_DEBUG_MSG_STD(_T("Perf data: ") + strEx::itos(bPerfData) + _T(":") + perf); 
    723722 
    724723  if (msg.empty()) 
  • trunk/modules/CheckSystem/PDHCollector.cpp

    rbe0202f r34f5502  
    159159  bool bInit = true; 
    160160 
    161   if (!loadCounter(pdh)) { 
    162     pdh.removeAllCounters(); 
    163     NSC_DEBUG_MSG_STD(_T("We aparently failed to load counters trying to use default (English) counters or those configured in nsc.ini")); 
    164     SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 
    165     pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 
    166     pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 
    167     pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 
    168     pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 
    169     try { 
    170       pdh.open(); 
    171     } catch (const PDH::PDHException &e) { 
    172       NSC_LOG_ERROR_STD(_T("Failed to open performance counters: ") + e.getError()); 
     161  { 
     162    WriteLock lock(&mutex_, true, 5000); 
     163    if (!lock.IsLocked()) { 
     164      NSC_LOG_ERROR_STD(_T("Failed to get mutex when trying to start thread... thread will now die...")); 
    173165      bInit = false; 
     166    } else if (!loadCounter(pdh)) { 
     167      pdh.removeAllCounters(); 
     168      NSC_DEBUG_MSG_STD(_T("We aparently failed to load counters trying to use default (English) counters or those configured in nsc.ini")); 
     169      SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT)); 
     170      pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE_LIMIT, C_SYSTEM_MEM_PAGE_LIMIT_DEFAULT), &memCmtLim); 
     171      pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_MEM_PAGE, C_SYSTEM_MEM_PAGE_DEFAULT), &memCmt); 
     172      pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_UPTIME, C_SYSTEM_UPTIME_DEFAULT), &upTime); 
     173      pdh.addCounter(NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_CPU, C_SYSTEM_MEM_CPU_DEFAULT), &cpu); 
     174      try { 
     175        pdh.open(); 
     176      } catch (const PDH::PDHException &e) { 
     177        NSC_LOG_ERROR_STD(_T("Failed to open performance counters: ") + e.getError()); 
     178        bInit = false; 
     179      } 
    174180    } 
    175181  } 
     
    181187      std::list<std::wstring> errors; 
    182188      { 
    183         MutexLock mutex(mutexHandler); 
    184         if (!mutex.hasMutex())  
     189        ReadLock lock(&mutex_, true, 5000); 
     190        if (!lock.IsLocked())  
    185191          NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    186192        else { 
     
    210216 
    211217  { 
    212     MutexLock mutex(mutexHandler); 
    213     if (!mutex.hasMutex()) { 
     218    WriteLock lock(&mutex_, true, 5000); 
     219    if (!lock.IsLocked()) { 
    214220      NSC_LOG_ERROR(_T("Failed to get Mute when closing thread!")); 
    215221    } 
     
    235241  if (hStopEvent_ == NULL) 
    236242    NSC_LOG_ERROR(_T("Stop event is not created!")); 
    237   else 
    238     if (!SetEvent(hStopEvent_)) { 
     243  else if (!SetEvent(hStopEvent_)) { 
    239244      NSC_LOG_ERROR_STD(_T("SetStopEvent failed")); 
    240     } 
     245  } 
    241246} 
    242247/** 
     
    247252int PDHCollector::getCPUAvrage(std::wstring time) { 
    248253  unsigned int mseconds = strEx::stoui_as_time(time, checkIntervall_*100); 
    249   MutexLock mutex(mutexHandler); 
    250   if (!mutex.hasMutex()) { 
     254  ReadLock lock(&mutex_, true, 5000); 
     255  if (!lock.IsLocked()) { 
    251256    NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    252257    return -1; 
    253258  } 
    254   return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 
     259  try { 
     260    return static_cast<int>(cpu.getAvrage(mseconds / (checkIntervall_*100))); 
     261  } catch (PDHCollectors::PDHException &e) { 
     262    NSC_LOG_ERROR(_T("Failed to get (sub) Mutex!")); 
     263    return -1; 
     264  } 
    255265} 
    256266/** 
     
    261271*/ 
    262272long long PDHCollector::getUptime() { 
    263   MutexLock mutex(mutexHandler); 
    264   if (!mutex.hasMutex()) { 
     273  ReadLock lock(&mutex_, true, 5000); 
     274  if (!lock.IsLocked()) { 
    265275    NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    266276    return -1; 
     
    273283*/ 
    274284unsigned long long PDHCollector::getMemCommitLimit() { 
    275   MutexLock mutex(mutexHandler); 
    276   if (!mutex.hasMutex()) { 
     285  ReadLock lock(&mutex_, true, 5000); 
     286  if (!lock.IsLocked()) { 
    277287    NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    278288    return -1; 
     
    286296*/ 
    287297unsigned long long PDHCollector::getMemCommit() { 
    288   MutexLock mutex(mutexHandler); 
    289   if (!mutex.hasMutex()) { 
     298  ReadLock lock(&mutex_, true, 5000); 
     299  if (!lock.IsLocked()) { 
    290300    NSC_LOG_ERROR(_T("Failed to get Mutex!")); 
    291301    return -1; 
  • trunk/modules/CheckSystem/PDHCollector.h

    r306c51b r34f5502  
    2323#include "PDHCollectors.h" 
    2424#include <thread.h> 
    25 #include <Mutex.h> 
     25#include <MutexRW.h> 
    2626 
    2727/** 
     
    4646class PDHCollector { 
    4747private: 
    48   MutexHandler mutexHandler; 
     48 
     49  MutexRW mutex_; 
    4950  HANDLE hStopEvent_; 
    5051  int checkIntervall_; 
    5152 
    52   PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large> memCmtLim; 
    53   PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large> memCmt; 
    54   PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large> upTime; 
    55   PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large> cpu; 
     53  PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmtLim; 
     54  PDHCollectors::StaticPDHCounterListener<unsigned __int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> memCmt; 
     55  PDHCollectors::StaticPDHCounterListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> upTime; 
     56  PDHCollectors::RoundINTPDHBufferListener<__int64, PDHCollectors::format_large, PDHCollectors::PDHCounterNormalMutex> cpu; 
    5657 
    5758public: 
Note: See TracChangeset for help on using the changeset viewer.