Changeset fff754b in nscp
- Timestamp:
- 08/06/12 23:43:08 (10 months ago)
- Branches:
- master, 0.4.1, 0.4.2
- Children:
- 29ff7e1
- Parents:
- 48b6b97
- Files:
-
- 5 edited
-
changelog (modified) (1 diff)
-
include/pdh/enumerations.hpp (modified) (3 diffs)
-
include/socket/client.hpp (modified) (1 diff)
-
modules/CheckSystem/CheckSystem.cpp (modified) (8 diffs)
-
modules/NSClientServer/NSClientServer.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
changelog
r48b6b97 rfff754b 7 7 2012-08-04 MickeM 8 8 * Re implemented INSTANCES command via the new pdh exec subsystem. 9 Still has an unfixed isue as it return duplicates (one for each counter on the object) which will be fixed later today.10 9 11 10 2012-08-04 MickeM -
include/pdh/enumerations.hpp
r48b6b97 rfff754b 40 40 41 41 typedef std::list<Object> Objects; 42 static Objects EnumObjects(DWORD dwDetailLevel = PERF_DETAIL_WIZARD) { 42 43 44 static void fetch_object_details(Object &object, bool instances = true, bool objects = true, DWORD dwDetailLevel = PERF_DETAIL_WIZARD) { 45 DWORD dwCounterBufLen = 0; 46 TCHAR* szCounterBuffer = NULL; 47 DWORD dwInstanceBufLen = 0; 48 TCHAR* szInstanceBuffer = NULL; 49 try { 50 PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, object.name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 51 if (status.is_more_data()) { 52 szCounterBuffer = new TCHAR[dwCounterBufLen+1]; 53 szInstanceBuffer = new TCHAR[dwInstanceBufLen+1]; 54 55 status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, object.name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 56 if (status.is_error()) { 57 delete [] szCounterBuffer; 58 delete [] szInstanceBuffer; 59 object.error = "Failed to enumerate object: " + utf8::cvt<std::string>(object.name); 60 } 61 62 if (dwCounterBufLen > 0 && objects) { 63 TCHAR *cp=szCounterBuffer; 64 while(*cp != '\0') { 65 object.counters.push_back(cp); 66 cp += lstrlen(cp)+1; 67 } 68 } 69 if (dwInstanceBufLen > 0 && instances) { 70 TCHAR *cp=szInstanceBuffer; 71 while(*cp != '\0') { 72 object.instances.push_back(cp); 73 cp += lstrlen(cp)+1; 74 } 75 } 76 delete [] szCounterBuffer; 77 delete [] szInstanceBuffer; 78 } else { 79 object.error = "Failed to enumerate object: " + utf8::cvt<std::string>(object.name); 80 } 81 } catch (std::exception &e) { 82 object.error = e.what(); 83 } catch (...) { 84 object.error = "Exception fetching data for: " + utf8::cvt<std::string>(object.name); 85 } 86 } 87 static Objects EnumObjects(bool instances = true, bool objects = true, DWORD dwDetailLevel = PERF_DETAIL_WIZARD) { 43 88 Objects ret; 44 89 … … 63 108 delete [] szObjectBuffer; 64 109 65 BOOST_FOREACH(Object &o, ret) { 66 DWORD dwCounterBufLen = 0; 67 TCHAR* szCounterBuffer = NULL; 68 DWORD dwInstanceBufLen = 0; 69 TCHAR* szInstanceBuffer = NULL; 70 try { 71 status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, o.name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 72 if (status.is_more_data()) { 73 szCounterBuffer = new TCHAR[dwCounterBufLen+1024]; 74 szInstanceBuffer = new TCHAR[dwInstanceBufLen+1024]; 75 76 status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, o.name.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 77 if (status.is_error()) { 78 delete [] szCounterBuffer; 79 delete [] szInstanceBuffer; 80 throw PDHException(_T("PdhEnumObjectItems failed when trying to retrieve buffer for ") + o.name, status); 81 } 82 83 if (dwCounterBufLen > 0) { 84 cp=szCounterBuffer; 85 while(*cp != '\0') { 86 o.counters.push_back(cp); 87 cp += lstrlen(cp)+1; 88 } 89 } 90 if (dwInstanceBufLen > 0) { 91 cp=szInstanceBuffer; 92 while(*cp != '\0') { 93 o.counters.push_back(cp); 94 cp += lstrlen(cp)+1; 95 } 96 } 97 delete [] szCounterBuffer; 98 delete [] szInstanceBuffer; 99 } 100 } catch (std::exception &e) { 101 o.error = e.what(); 102 } catch (...) { 103 o.error = "Exception fetching data"; 110 if (objects || instances) { 111 BOOST_FOREACH(Object &o, ret) { 112 fetch_object_details(o, instances, objects, dwDetailLevel); 104 113 } 105 114 } … … 107 116 } 108 117 109 static Object EnumObject(std::wstring object, DWORD dwDetailLevel = PERF_DETAIL_WIZARD) {118 static Object EnumObject(std::wstring object, bool instances = true, bool objects = true, DWORD dwDetailLevel = PERF_DETAIL_WIZARD) { 110 119 Object ret; 111 120 ret.name = object; 112 DWORD dwCounterBufLen = 0; 113 TCHAR* szCounterBuffer = NULL; 114 DWORD dwInstanceBufLen = 0; 115 TCHAR* szInstanceBuffer = NULL; 116 try { 117 PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, object.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 118 if (status.is_more_data()) { 119 szCounterBuffer = new TCHAR[dwCounterBufLen+1024]; 120 szInstanceBuffer = new TCHAR[dwInstanceBufLen+1024]; 121 122 status = PDH::PDHFactory::get_impl()->PdhEnumObjectItems(NULL, NULL, object.c_str(), szCounterBuffer, &dwCounterBufLen, szInstanceBuffer, &dwInstanceBufLen, dwDetailLevel, 0); 123 if (status.is_error()) { 124 delete [] szCounterBuffer; 125 delete [] szInstanceBuffer; 126 throw PDHException(_T("PdhEnumObjectItems failed when trying to retrieve buffer for ") + object, status); 127 } 128 129 if (dwCounterBufLen > 0) { 130 TCHAR *cp=szCounterBuffer; 131 while(*cp != '\0') { 132 ret.counters.push_back(cp); 133 cp += lstrlen(cp)+1; 134 } 135 } 136 if (dwInstanceBufLen > 0) { 137 TCHAR *cp=szInstanceBuffer; 138 while(*cp != '\0') { 139 ret.instances.push_back(cp); 140 cp += lstrlen(cp)+1; 141 } 142 } 143 delete [] szCounterBuffer; 144 delete [] szInstanceBuffer; 145 } 146 } catch (std::exception &e) { 147 ret.error = e.what(); 148 } catch (...) { 149 ret.error = "Exception fetching data"; 150 } 121 fetch_object_details(ret, instances, objects, dwDetailLevel); 151 122 return ret; 152 123 } -
include/socket/client.hpp
r24f6e3f rfff754b 331 331 332 332 typename protocol_type::response_type process_request(typename protocol_type::request_type &packet, int retries = 3) { 333 boost::optional< protocol_type::response_type> response = connection_->process_request(packet);333 boost::optional<typename protocol_type::response_type> response = connection_->process_request(packet); 334 334 if (!response) { 335 335 for (int i=0;i<retries;i++) { -
modules/CheckSystem/CheckSystem.cpp
r48b6b97 rfff754b 309 309 bool render_list(const PDH::Enumerations::Objects &list, bool validate, bool porcelain, std::wstring filter, std::wstring &result) { 310 310 if (!porcelain) { 311 result += _T("Listing allcounters\n");311 result += _T("Listing counters\n"); 312 312 result += _T("---------------------------\n"); 313 313 } … … 315 315 int total = 0, match = 0; 316 316 BOOST_FOREACH(const PDH::Enumerations::Object &obj, list) { 317 if (!obj.error.empty()) { 318 result += _T("error,") + obj.name + _T(",") + utf8::to_unicode(obj.error) + _T("\n"); 317 if (porcelain) { 318 BOOST_FOREACH(const std::wstring &inst, obj.instances) { 319 std::wstring line = _T("\\") + obj.name + _T("(") + inst + _T(")\\") ; 320 total++; 321 if (!filter.empty() && line.find(filter) == std::wstring::npos) 322 continue; 323 result += _T("instance,") + qoute(obj.name) + _T(",") + qoute(inst) + _T("\n"); 324 match++; 325 } 326 BOOST_FOREACH(const std::wstring &count, obj.counters) { 327 std::wstring line = _T("\\") + obj.name + _T("\\") + count; 328 total++; 329 if (!filter.empty() && line.find(filter) == std::wstring::npos) 330 continue; 331 result += _T("counter,") + qoute(obj.name) + _T(",") + qoute(count) + _T("\n"); 332 match++; 333 } 334 if (obj.instances.empty() && obj.counters.empty()) { 335 std::wstring line = _T("\\") + obj.name + _T("\\"); 336 total++; 337 if (!filter.empty() && line.find(filter) == std::wstring::npos) 338 continue; 339 result += _T("counter,") + qoute(obj.name) + _T(",") + _T(",\n"); 340 match++; 341 } else if (!obj.error.empty()) { 342 result += _T("error,") + obj.name + _T(",") + utf8::to_unicode(obj.error) + _T("\n"); 343 } 344 } else if (!obj.error.empty()) { 345 result += _T("Failed to enumerate counter ") + obj.name + _T(": ") + utf8::to_unicode(obj.error) + _T("\n"); 319 346 } else if (obj.instances.size() > 0) { 320 347 BOOST_FOREACH(const std::wstring &inst, obj.instances) { … … 325 352 continue; 326 353 boost::tuple<bool,std::wstring> status; 327 if (validate) 354 if (validate) { 328 355 status = validate_counter(line); 329 if (porcelain) 330 line = _T("counter,") + qoute(obj.name) + _T(",") + qoute(inst) + _T(",") + qoute(count) + _T(", ") + qoute(status.get<1>()); 331 else if (validate) 332 line = line + _T(": ") + status.get<1>(); 333 result += line + _T("\n"); 356 result += line + _T(": ") + status.get<1>() + _T("\n"); 357 } else 358 result += line + _T("\n"); 334 359 match++; 335 360 } … … 342 367 continue; 343 368 boost::tuple<bool,std::wstring> status; 344 if (validate) 369 if (validate) { 345 370 status = validate_counter(line); 346 347 if (porcelain) 348 line = _T("counter,") + qoute(obj.name) + _T(",,") + qoute(count) + _T(", ") + qoute(status.get<1>()); 349 else if (validate) 350 line = line + _T(": ") + status.get<1>(); 351 result += line + _T("\n"); 371 result += line + _T(": ") + status.get<1>() + _T("\n"); 372 } else 373 result += line + _T("\n"); 352 374 match++; 353 375 } … … 381 403 ("validate", po::wvalue<std::wstring>(&list_string)->implicit_value(_T("")), "List counters and/or instances") 382 404 ("all", "List/check all counters not configured counter") 405 ("no-counters", "Do not recurse and list/validate counters for any matching items") 406 ("no-instances", "Do not recurse and list/validate instances for any matching items") 383 407 ("counter", po::wvalue<std::wstring>(&counter)->implicit_value(_T("")), "Specify which counter to work with") 384 408 ("filter", po::wvalue<std::wstring>(&counter)->implicit_value(_T("")), "Specify a filter to match (substring matching)") … … 402 426 bool all = vm.count("all"); 403 427 bool validate = vm.count("validate"); 428 bool no_objects = vm.count("no-counters"); 429 bool no_instances = vm.count("no-instances"); 404 430 bool list = vm.count("list") || (validate && counter.empty()); 405 431 if (counter.empty()) … … 418 444 if (all) { 419 445 // If we specified all list all counters 420 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects( );446 PDH::Enumerations::Objects lst = PDH::Enumerations::EnumObjects(!no_instances, !no_objects); 421 447 return render_list(lst, validate, porcelain, counter, result)?NSCAPI::isSuccess:NSCAPI::hasFailed; 422 448 } else { … … 424 450 // If we specify a counter object we will only list instances of that 425 451 PDH::Enumerations::Objects lst; 426 lst.push_back(PDH::Enumerations::EnumObject(counter ));452 lst.push_back(PDH::Enumerations::EnumObject(counter, !no_instances, !no_objects)); 427 453 return render_list(lst, validate, porcelain, counter, result)?NSCAPI::isSuccess:NSCAPI::hasFailed; 428 454 } else { -
modules/NSClientServer/NSClientServer.cpp
r48b6b97 rfff754b 210 210 std::wstring list_instance(std::wstring counter) { 211 211 std::list<std::wstring> exeresult; 212 nscapi::core_helper::exec_simple_command(_T("*"), _T("pdh"), boost::assign::list_of(std::wstring(_T("--list")))(_T("--porcelain"))(_T("--counter"))(counter) , exeresult);212 nscapi::core_helper::exec_simple_command(_T("*"), _T("pdh"), boost::assign::list_of(std::wstring(_T("--list")))(_T("--porcelain"))(_T("--counter"))(counter)(_T("--no-counters")), exeresult); 213 213 std::wstring result; 214 214 … … 221 221 Tokenizer tok(line); 222 222 Tokenizer::const_iterator cit = tok.begin(); 223 int i = 2;223 int i = 1; 224 224 while ((i-->0) && (cit != tok.end())) 225 225 ++cit;
Note: See TracChangeset
for help on using the changeset viewer.








