Changeset 76aafc4 in nscp for modules/CheckSystem


Ignore:
Timestamp:
10/26/06 07:03:39 (7 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
7aef770
Parents:
70f2d7b
Message:

* empty log message *

Location:
modules/CheckSystem
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • modules/CheckSystem/CheckSystem.cpp

    rf42280d r76aafc4  
    117117            std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 
    118118            std::cout << "testing: " << counter << ": "; 
     119            std::list<std::string> errors; 
     120            std::list<std::string> status; 
    119121            std::string error; 
     122            bool bStatus = true; 
    120123            if (PDH::Enumerations::validate(counter, error)) { 
    121               std::cout << " found "; 
     124              status.push_back("open"); 
    122125            } else { 
    123               std::cout << " *NOT* found (" << error << ") " << std::endl; 
    124               break; 
     126              errors.push_back("NOT found: " + error); 
     127              bStatus = false; 
    125128            } 
    126             bool bOpend = false; 
    127             try { 
     129            if (bStatus) { 
     130              PDH::PDHCounter *pCounter = NULL; 
    128131              PDH::PDHQuery pdh; 
    129               PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
    130               pdh.addCounter(counter, &cDouble); 
    131               pdh.open(); 
    132               pdh.gatherData(); 
    133               pdh.close(); 
    134               bOpend = true; 
    135             } catch (const PDH::PDHException e) { 
    136               std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
    137               break; 
     132              try { 
     133                PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
     134                pCounter = pdh.addCounter(counter, &cDouble); 
     135                pdh.open(); 
     136 
     137                if (pCounter != NULL) { 
     138                  try { 
     139                    PDH::PDHCounterInfo info = pCounter->getCounterInfo(); 
     140                    errors.push_back("CounterName: " + info.szCounterName); 
     141                    errors.push_back("ExplainText: " + info.szExplainText); 
     142                    errors.push_back("FullPath: " + info.szFullPath); 
     143                    errors.push_back("InstanceName: " + info.szInstanceName); 
     144                    errors.push_back("MachineName: " + info.szMachineName); 
     145                    errors.push_back("ObjectName: " + info.szObjectName); 
     146                    errors.push_back("ParentInstance: " + info.szParentInstance); 
     147                    errors.push_back("Type: " + strEx::itos(info.dwType)); 
     148                    errors.push_back("Scale: " + strEx::itos(info.lScale)); 
     149                    errors.push_back("Default Scale: " + strEx::itos(info.lDefaultScale)); 
     150                    errors.push_back("Status: " + strEx::itos(info.CStatus)); 
     151                    status.push_back("described"); 
     152                  } catch (const PDH::PDHException e) { 
     153                    errors.push_back("Describe failed: " + e.getError()); 
     154                    bStatus = false; 
     155                  } 
     156                } 
     157 
     158                pdh.gatherData(); 
     159                pdh.close(); 
     160                status.push_back("queried"); 
     161              } catch (const PDH::PDHException e) { 
     162                errors.push_back("Query failed: " + e.getError()); 
     163                bStatus = false; 
     164                try { 
     165                  pdh.gatherData(); 
     166                  pdh.close(); 
     167                  bStatus = true; 
     168                } catch (const PDH::PDHException e) { 
     169                  errors.push_back("Query failed (again!): " + e.getError()); 
     170                } 
     171              } 
     172 
    138173            } 
    139             std::cout << " open "; 
    140             std::cout << std::endl; 
     174            if (!bStatus) { 
     175              std::list<std::string>::const_iterator cit = status.begin(); 
     176              for (;cit != status.end(); ++cit) { 
     177                std::cout << *cit << ", "; 
     178              } 
     179              std::cout << std::endl; 
     180              std::cout << "  | Log" << std::endl; 
     181              std::cout << "--+------  --    -" << std::endl; 
     182              cit = errors.begin(); 
     183              for (;cit != errors.end(); ++cit) { 
     184                std::cout << "  | " << *cit << std::endl; 
     185              } 
     186            } else { 
     187              std::list<std::string>::const_iterator cit = status.begin(); 
     188              for (;cit != status.end(); ++cit) { 
     189                std::cout << *cit << ", ";; 
     190              } 
     191              std::cout << std::endl; 
     192            } 
    141193          } 
    142194        } 
  • modules/CheckSystem/PDHCollector.cpp

    raabbd97 r76aafc4  
    120120 
    121121  DWORD waitStatus = 0; 
     122  bool first = true; 
    122123  do { 
    123124    MutexLock mutex(mutexHandler); 
     
    128129        pdh.gatherData(); 
    129130      } catch (const PDH::PDHException &e) { 
    130         NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     131        if (first) {  // If this is the first run an error will be thrown since the data is not yet avalible 
     132                // This is "ok" but perhaps another solution would be better, but this works :) 
     133          first = false; 
     134        } else { 
     135          NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     136        } 
    131137      } 
    132138    }  
Note: See TracChangeset for help on using the changeset viewer.