Changeset 34f5502 in nscp for trunk/modules/CheckSystem
- Timestamp:
- 02/18/08 23:21:23 (5 years ago)
- Children:
- 087a3c9
- Parents:
- e0936e3
- Location:
- trunk/modules/CheckSystem
- Files:
-
- 3 edited
-
CheckSystem.cpp (modified) (2 diffs)
-
PDHCollector.cpp (modified) (8 diffs)
-
PDHCollector.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/modules/CheckSystem/CheckSystem.cpp
r907d5b0 r34f5502 402 402 int value = pObject->getCPUAvrage(load.data + _T("m")); 403 403 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?"); 405 405 return NSCAPI::returnUNKNOWN; 406 406 } … … 720 720 } 721 721 } 722 NSC_DEBUG_MSG_STD(_T("Perf data: ") + strEx::itos(bPerfData) + _T(":") + perf);723 722 724 723 if (msg.empty()) -
trunk/modules/CheckSystem/PDHCollector.cpp
rbe0202f r34f5502 159 159 bool bInit = true; 160 160 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...")); 173 165 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 } 174 180 } 175 181 } … … 181 187 std::list<std::wstring> errors; 182 188 { 183 MutexLock mutex(mutexHandler);184 if (! mutex.hasMutex())189 ReadLock lock(&mutex_, true, 5000); 190 if (!lock.IsLocked()) 185 191 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 186 192 else { … … 210 216 211 217 { 212 MutexLock mutex(mutexHandler);213 if (! mutex.hasMutex()) {218 WriteLock lock(&mutex_, true, 5000); 219 if (!lock.IsLocked()) { 214 220 NSC_LOG_ERROR(_T("Failed to get Mute when closing thread!")); 215 221 } … … 235 241 if (hStopEvent_ == NULL) 236 242 NSC_LOG_ERROR(_T("Stop event is not created!")); 237 else 238 if (!SetEvent(hStopEvent_)) { 243 else if (!SetEvent(hStopEvent_)) { 239 244 NSC_LOG_ERROR_STD(_T("SetStopEvent failed")); 240 }245 } 241 246 } 242 247 /** … … 247 252 int PDHCollector::getCPUAvrage(std::wstring time) { 248 253 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()) { 251 256 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 252 257 return -1; 253 258 } 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 } 255 265 } 256 266 /** … … 261 271 */ 262 272 long long PDHCollector::getUptime() { 263 MutexLock mutex(mutexHandler);264 if (! mutex.hasMutex()) {273 ReadLock lock(&mutex_, true, 5000); 274 if (!lock.IsLocked()) { 265 275 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 266 276 return -1; … … 273 283 */ 274 284 unsigned long long PDHCollector::getMemCommitLimit() { 275 MutexLock mutex(mutexHandler);276 if (! mutex.hasMutex()) {285 ReadLock lock(&mutex_, true, 5000); 286 if (!lock.IsLocked()) { 277 287 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 278 288 return -1; … … 286 296 */ 287 297 unsigned long long PDHCollector::getMemCommit() { 288 MutexLock mutex(mutexHandler);289 if (! mutex.hasMutex()) {298 ReadLock lock(&mutex_, true, 5000); 299 if (!lock.IsLocked()) { 290 300 NSC_LOG_ERROR(_T("Failed to get Mutex!")); 291 301 return -1; -
trunk/modules/CheckSystem/PDHCollector.h
r306c51b r34f5502 23 23 #include "PDHCollectors.h" 24 24 #include <thread.h> 25 #include <Mutex .h>25 #include <MutexRW.h> 26 26 27 27 /** … … 46 46 class PDHCollector { 47 47 private: 48 MutexHandler mutexHandler; 48 49 MutexRW mutex_; 49 50 HANDLE hStopEvent_; 50 51 int checkIntervall_; 51 52 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; 56 57 57 58 public:
Note: See TracChangeset
for help on using the changeset viewer.








