Changeset e93e741 in nscp for trunk/include


Ignore:
Timestamp:
05/29/05 20:58:08 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
24f7192
Parents:
7da80b5
Message:
  • Fixed PROCSTATE and SERVICESTATE return state. + Added support for individual size in CheckDriveSize and CheckFileSize (size has to be specified before a drive/path)
  • Fixed performance data for drives (and possibly other places)
Location:
trunk/include
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/PDHCollectors.h

    r7da80b5 re93e741  
    44 
    55namespace PDHCollectors { 
    6   class StaticPDHCounterListenerInt : public PDH::PDHCounterListener { 
    7     __int64 value_; 
     6  template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 
     7  class StaticPDHCounterListener : public PDH::PDHCounterListener { 
     8    TType value_; 
    89  public: 
    910    virtual void collect(const PDH::PDHCounter &counter) { 
    10       setValue(counter.getInt64Value()); 
     11      switch (TCollectionFormat) { 
     12        case PDH_FMT_LARGE: 
     13          setValue(counter.getInt64Value()); 
     14          break; 
     15        case PDH_FMT_DOUBLE: 
     16          setValue(counter.getDoubleValue()); 
     17          break; 
     18        default: 
     19          return; 
     20      } 
    1121    } 
    1222    void attach(const PDH::PDHCounter &counter){} 
    1323    void detach(const PDH::PDHCounter &counter){} 
    14     void setValue(__int64 value) { 
     24    void setValue(TType value) { 
    1525      value_ = value; 
    1626    } 
    17     __int64 getValue() const { 
     27    TType getValue() const { 
    1828      return value_; 
    1929    } 
    20   }; 
    21   class StaticPDHCounterListenerDouble : public PDH::PDHCounterListener { 
    22     double value_; 
    23   public: 
    24     virtual void collect(const PDH::PDHCounter &counter) { 
    25       setValue(counter.getDoubleValue()); 
    26     } 
    27     void attach(const PDH::PDHCounter &counter){} 
    28     void detach(const PDH::PDHCounter &counter){} 
    29     void setValue(double value) { 
    30       value_ = value; 
    31     } 
    32     double getValue() const { 
    33       return value_; 
     30    DWORD getFormat() const { 
     31      return TCollectionFormat; 
    3432    } 
    3533  }; 
    3634 
    37  
     35  template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 
    3836  class RoundINTPDHBufferListener : public PDH::PDHCounterListener { 
    3937    unsigned int length; 
    40     int *buffer; 
     38    TType *buffer; 
    4139    unsigned int current; 
    4240  public: 
     
    6462      length = newLength; 
    6563 
    66       buffer = new int[length]; 
     64      buffer = new TType[length]; 
    6765      for (unsigned int i=0; i<length;i++) 
    6866        buffer[i] = 0; 
     
    7068    } 
    7169    virtual void collect(const PDH::PDHCounter &counter) { 
    72       pushValue(static_cast<int>(counter.getInt64Value())); 
     70      switch (TCollectionFormat) { 
     71        case PDH_FMT_LONG: 
     72          pushValue(counter.getInt64Value()); 
     73          break; 
     74        case PDH_FMT_DOUBLE: 
     75          pushValue(counter.getInt64Value()); 
     76          break; 
     77        default: 
     78          return; 
     79      } 
    7380    } 
    7481    void attach(const PDH::PDHCounter &counter){} 
    7582    void detach(const PDH::PDHCounter &counter){} 
    76     void pushValue(int value) { 
     83    void pushValue(TType value) { 
    7784      if (buffer == NULL) 
    7885        return; 
     
    8390        current = 0; 
    8491    } 
    85     int getAvrage(unsigned int backItems) const { 
     92    TType getAvrage(unsigned int backItems) const { 
    8693      if ((backItems == 0) || (backItems >= length)) 
    8794        return -1; 
     
    98105          ret += buffer[i]; 
    99106      } 
    100       return static_cast<int>(ret/backItems); 
     107      return (ret/backItems); 
    101108    } 
    102109    inline unsigned int getLength() const { 
    103110      return length; 
    104111    } 
     112    DWORD getFormat() const { 
     113      return TCollectionFormat; 
     114    } 
    105115  }; 
    106116 
  • trunk/include/PDHCounter.h

    r7da80b5 re93e741  
    2323    virtual void attach(const PDHCounter &counter) = 0; 
    2424    virtual void detach(const PDHCounter &counter) = 0; 
     25    virtual DWORD getFormat() const = 0; 
    2526  }; 
    2627 
     
    7273        return; 
    7374      PDH_STATUS status; 
    74       if ((status = PdhGetFormattedCounterValue(hCounter_, PDH_FMT_LARGE , NULL, &data_)) != ERROR_SUCCESS) 
     75      if (!listener_) 
     76        return; 
     77      if ((status = PdhGetFormattedCounterValue(hCounter_, listener_->getFormat(), NULL, &data_)) != ERROR_SUCCESS) 
    7578        throw PDHException("PdhGetFormattedCounterValue failed", status); 
    76       if (listener_) 
    77         listener_->collect(*this); 
     79      listener_->collect(*this); 
    7880    } 
    7981    double getDoubleValue() const { 
  • trunk/include/strEx.h

    rf896cfb re93e741  
    4040  } 
    4141  inline std::string itos(unsigned long i) { 
     42    std::stringstream ss; 
     43    ss << i; 
     44    return ss.str(); 
     45  } 
     46  inline std::string itos(double i) { 
    4247    std::stringstream ss; 
    4348    ss << i; 
  • trunk/include/utils.h

    rf896cfb re93e741  
    2222      return strEx::itos(value) + "%"; 
    2323    } 
     24    static std::string print_unformated(TType value) { 
     25      return strEx::itos(value); 
     26    } 
    2427  }; 
    2528 
     
    3437    } 
    3538    static std::string print(TType value) { 
     39      return strEx::itos(value); 
     40    } 
     41    static std::string print_unformated(TType value) { 
    3642      return strEx::itos(value); 
    3743    } 
     
    5460 
    5561    Size() : bHasBounds_(false), value_(0) {}; 
     62 
     63    Size(const Size & other) { 
     64      bHasBounds_ = other.bHasBounds_; 
     65      value_ = other.value_; 
     66    } 
     67 
    5668    void set(std::string s) { 
    5769      value_ = THandler::parse(s); 
     
    101113 
    102114    SizePercentage() : type_(none), value_(0) {}; 
     115 
     116    SizePercentage(const SizePercentage &other) { 
     117      type_ = other.type_; 
     118      value_ = other.value_; 
     119    }; 
    103120    void set(std::string s) { 
    104121      std::string::size_type p = s.find_first_of('%'); 
     
    159176    typedef SizeMaxMin<TType, THandler, THolder> TMyType; 
    160177 
     178    SizeMaxMin() {} 
     179    SizeMaxMin(const SizeMaxMin &other) { 
     180      max = other.max; 
     181      min = other.min; 
     182    } 
     183 
    161184    std::string printPerfData() 
    162185    { 
    163186      if (max.hasBounds()) { 
    164         return THandler::print(max.value_) + ";"; 
     187        return THandler::print_unformated(max.value_) + ";"; 
    165188      } else if (min.hasBounds()) { 
    166         return THandler::print(min.value_) + ";"; 
     189        return THandler::print_unformated(min.value_) + ";"; 
    167190      } 
    168191      return "0;"; 
     
    180203    THolder min; 
    181204    typedef SizeMaxMinPercentage<TType, THandler, THolder> TMyType; 
     205 
     206    SizeMaxMinPercentage() {} 
     207    SizeMaxMinPercentage(const SizeMaxMinPercentage &other) { 
     208      max = other.max; 
     209      min = other.min; 
     210    } 
    182211 
    183212    bool isPercentage() { 
     
    207236        if (max.hasBounds()) { 
    208237          if (max.isPercentage()) { 
    209             return THandler::print((max.value_*total)/100) + ";"; 
    210           } else { 
    211             return THandler::print(max.value_) + ";"; 
     238            return THandler::print_unformated((max.value_*total)/100) + ";"; 
     239          } else { 
     240            return THandler::print_unformated(max.value_) + ";"; 
    212241          } 
    213242        } else if (min.hasBounds()) { 
    214243          if (min.isPercentage()) { 
    215             return THandler::print((min.value_*total)/100) + ";"; 
    216           } else { 
    217             return THandler::print(min.value_) + ";"; 
     244            return THandler::print_unformated((min.value_*total)/100) + ";"; 
     245          } else { 
     246            return THandler::print_unformated(min.value_) + ";"; 
    218247          } 
    219248        } 
     
    236265 
    237266  }; 
    238 /* 
    239   template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMinPercentage<> >  
    240   class PerformancePrinterPercentage { 
    241   public: 
    242     static std::string printPerf(std::string name, TType value, TType total, THolder &warn, THolder &crit) 
    243     { 
    244       std::string s; 
    245       bool percentage = crit.isPercentage()  || warn.isPercentage(); 
    246       if (percentage) 
    247         s += name + "=" + strEx::itos(value*100/total)+ "% "; 
    248       else 
    249         s+= name + "=" + strEx::itos(value) + ";"; 
    250       s += warn.printPerfData(percentage, value, total); 
    251       s += crit.printPerfData(percentage, value, total); 
    252       s += " "; 
    253       return s; 
    254     } 
    255   }; 
    256   template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMin<> >  
    257   class PerformancePrinter { 
    258   public: 
    259     static std::string printPerf(std::string name, TType value, THolder &warn, THolder &crit) 
    260     { 
    261       return name + "=" + strEx::itos(value) + ";" + warn.printPerfData() + crit.printPerfData(); 
    262     } 
    263   }; 
    264 */ 
    265267} 
    266268void generate_crc32_table(void); 
Note: See TracChangeset for help on using the changeset viewer.