CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

stor::ResourceMonitorCollection Class Reference

#include <ResourceMonitorCollection.h>

Inheritance diagram for stor::ResourceMonitorCollection:
stor::MonitorCollection

List of all members.

Classes

struct  DiskUsage
struct  DiskUsageStats
struct  Stats

Public Types

typedef boost::shared_ptr
< DiskUsageStats
DiskUsageStatsPtr
typedef std::vector
< DiskUsageStatsPtr
DiskUsageStatsPtrList

Public Member Functions

void configureAlarms (AlarmParams const &)
void configureDisks (DiskWritingParams const &)
void configureResources (ResourceMonitorParams const &)
void getStats (Stats &) const
 ResourceMonitorCollection (const utils::Duration_t &updateInterval, AlarmHandlerPtr)

Private Types

typedef boost::shared_ptr
< DiskUsage
DiskUsagePtr
typedef std::vector< DiskUsagePtrDiskUsagePtrList
typedef std::set< std::string > SATABeasts

Private Member Functions

void addDisk (const std::string &)
void addOtherDisks ()
void calcDiskUsage ()
void calcNumberOfCopyWorkers ()
void calcNumberOfInjectWorkers ()
void checkNumberOfCopyWorkers ()
void checkNumberOfInjectWorkers ()
void checkSataBeast (const std::string &sataBeast)
void checkSataBeasts ()
bool checkSataDisks (const std::string &sataBeast, const std::string &hostSuffix)
virtual void do_appendInfoSpaceItems (InfoSpaceItems &)
virtual void do_calculateStatistics ()
virtual void do_reset ()
virtual void do_updateInfoSpaceItems ()
void emitDiskAlarm (DiskUsagePtr, error_t)
void emitDiskSpaceAlarm (DiskUsagePtr)
void failIfImportantDisk (DiskUsagePtr)
void getDiskStats (Stats &) const
int getProcessCount (const std::string &processName, const int &uid=-1)
bool getSataBeasts (SATABeasts &sataBeasts)
ResourceMonitorCollectionoperator= (ResourceMonitorCollection const &)
 ResourceMonitorCollection (ResourceMonitorCollection const &)
void retrieveDiskSize (DiskUsagePtr)
void revokeDiskAlarm (DiskUsagePtr)
void updateSataBeastStatus (const std::string &sataBeast, const std::string &content)

Private Attributes

AlarmHandlerPtr alarmHandler_
AlarmParams alarmParams_
xdata::UnsignedInteger32 copyWorkers_
xdata::Vector< xdata::String > diskPaths_
DiskUsagePtrList diskUsageList_
boost::mutex diskUsageListMutex_
DiskWritingParams dwParams_
xdata::UnsignedInteger32 injectWorkers_
int latchedSataBeastStatus_
unsigned int nLogicalDisks_
int numberOfCopyWorkers_
xdata::UnsignedInteger32 numberOfDisks_
int numberOfInjectWorkers_
ResourceMonitorParams rmParams_
xdata::Integer32 sataBeastStatus_
xdata::Vector
< xdata::UnsignedInteger32 > 
totalDiskSpace_
const utils::Duration_t updateInterval_
xdata::Vector
< xdata::UnsignedInteger32 > 
usedDiskSpace_

Friends

class testResourceMonitorCollection

Detailed Description

A collection of MonitoredQuantities related to resource usages

Author:
mommsen
Revision:
1.28
Date:
2011/03/07 15:31:32

Definition at line 40 of file ResourceMonitorCollection.h.


Member Typedef Documentation

typedef boost::shared_ptr<DiskUsage> stor::ResourceMonitorCollection::DiskUsagePtr [private]

Definition at line 109 of file ResourceMonitorCollection.h.

Definition at line 110 of file ResourceMonitorCollection.h.

Definition at line 55 of file ResourceMonitorCollection.h.

Definition at line 56 of file ResourceMonitorCollection.h.

typedef std::set<std::string> stor::ResourceMonitorCollection::SATABeasts [private]

Definition at line 143 of file ResourceMonitorCollection.h.


Constructor & Destructor Documentation

stor::ResourceMonitorCollection::ResourceMonitorCollection ( const utils::Duration_t updateInterval,
AlarmHandlerPtr  ah 
)

Constructor.

Definition at line 35 of file ResourceMonitorCollection.cc.

stor::ResourceMonitorCollection::ResourceMonitorCollection ( ResourceMonitorCollection const &  ) [private]

Member Function Documentation

void stor::ResourceMonitorCollection::addDisk ( const std::string &  pathname) [private]

Definition at line 77 of file ResourceMonitorCollection.cc.

References diskUsageList_, and retrieveDiskSize().

Referenced by addOtherDisks(), and configureDisks().

  {
    if ( pathname.empty() ) return;
    
    DiskUsagePtr diskUsage( new DiskUsage() );
    diskUsage->pathName = pathname;
    retrieveDiskSize(diskUsage);
    diskUsageList_.push_back(diskUsage);
  }
void stor::ResourceMonitorCollection::addOtherDisks ( ) [private]

Definition at line 88 of file ResourceMonitorCollection.cc.

References addDisk(), dwParams_, and stor::DiskWritingParams::otherDiskPaths_.

Referenced by configureDisks().

  {
    for ( DiskWritingParams::OtherDiskPaths::const_iterator
            it = dwParams_.otherDiskPaths_.begin(),
            itEnd =  dwParams_.otherDiskPaths_.end();
          it != itEnd;
          ++it)
    {
      addDisk(*it);
    }
  }
void stor::ResourceMonitorCollection::calcDiskUsage ( ) [private]

Definition at line 243 of file ResourceMonitorCollection.cc.

References diskUsageList_, diskUsageListMutex_, and retrieveDiskSize().

Referenced by do_calculateStatistics(), and do_updateInfoSpaceItems().

  {
    boost::mutex::scoped_lock sl(diskUsageListMutex_);
    
    for ( DiskUsagePtrList::iterator it = diskUsageList_.begin(),
            itEnd = diskUsageList_.end();
          it != itEnd;
          ++it)
    {
      retrieveDiskSize(*it);
    }
  }
void stor::ResourceMonitorCollection::calcNumberOfCopyWorkers ( ) [private]

Definition at line 352 of file ResourceMonitorCollection.cc.

References alarmParams_, checkNumberOfCopyWorkers(), stor::ResourceMonitorParams::copyWorkers_, getProcessCount(), stor::AlarmParams::isProductionSystem_, numberOfCopyWorkers_, and rmParams_.

Referenced by do_calculateStatistics().

  {
    struct passwd* passwd = getpwnam(rmParams_.copyWorkers_.user_.c_str());
    if (passwd)
    {
      numberOfCopyWorkers_ =
        getProcessCount(rmParams_.copyWorkers_.command_, passwd->pw_uid);
    }
    else
    {
      numberOfCopyWorkers_ = 0;
    }
    
    if ( alarmParams_.isProductionSystem_ && rmParams_.copyWorkers_.expectedCount_ >= 0 )
    {
      checkNumberOfCopyWorkers();
    }
  }
void stor::ResourceMonitorCollection::calcNumberOfInjectWorkers ( ) [private]

Definition at line 392 of file ResourceMonitorCollection.cc.

References alarmParams_, checkNumberOfInjectWorkers(), getProcessCount(), stor::ResourceMonitorParams::injectWorkers_, stor::AlarmParams::isProductionSystem_, numberOfInjectWorkers_, and rmParams_.

Referenced by do_calculateStatistics().

  {
    struct passwd* passwd = getpwnam(rmParams_.injectWorkers_.user_.c_str());
    if (passwd)
    {
      numberOfInjectWorkers_ = getProcessCount(rmParams_.injectWorkers_.command_, passwd->pw_uid);
    }
    else
    {
      numberOfInjectWorkers_ = 0;
    }
    
    if (
      alarmParams_.isProductionSystem_ &&
      rmParams_.injectWorkers_.expectedCount_ >= 0
    )
    {
      checkNumberOfInjectWorkers();
    }
  }
void stor::ResourceMonitorCollection::checkNumberOfCopyWorkers ( ) [private]

Definition at line 372 of file ResourceMonitorCollection.cc.

References alarmHandler_, stor::ResourceMonitorParams::copyWorkers_, runTheMatrix::msg, numberOfCopyWorkers_, rmParams_, and stor::AlarmHandler::WARNING.

Referenced by calcNumberOfCopyWorkers().

  {
    const std::string alarmName = "CopyWorkers";
    
    if ( numberOfCopyWorkers_ < rmParams_.copyWorkers_.expectedCount_ )
    {
      std::ostringstream msg;
      msg << "Expected " << rmParams_.copyWorkers_.expectedCount_ <<
        " running CopyWorkers, but found " <<
        numberOfCopyWorkers_ << ".";
      XCEPT_DECLARE(stor::exception::CopyWorkers, ex, msg.str());
      alarmHandler_->raiseAlarm(alarmName, AlarmHandler::WARNING, ex);
    }
    else
    {
      alarmHandler_->revokeAlarm(alarmName);
    }
  }
void stor::ResourceMonitorCollection::checkNumberOfInjectWorkers ( ) [private]

Definition at line 414 of file ResourceMonitorCollection.cc.

References alarmHandler_, stor::ResourceMonitorParams::injectWorkers_, runTheMatrix::msg, numberOfInjectWorkers_, rmParams_, and stor::AlarmHandler::WARNING.

Referenced by calcNumberOfInjectWorkers().

  {
    const std::string alarmName = "InjectWorkers";
    
    if ( numberOfInjectWorkers_ != rmParams_.injectWorkers_.expectedCount_ )
    {
      std::ostringstream msg;
      msg << "Expected " << rmParams_.injectWorkers_.expectedCount_ <<
        " running InjectWorkers, but found " <<
        numberOfInjectWorkers_ << ".";
      XCEPT_DECLARE(stor::exception::InjectWorkers, ex, msg.str());
      alarmHandler_->raiseAlarm(alarmName, AlarmHandler::WARNING, ex);
    }
    else
    {
      alarmHandler_->revokeAlarm(alarmName);
    }
  }
void stor::ResourceMonitorCollection::checkSataBeast ( const std::string &  sataBeast) [private]

Definition at line 485 of file ResourceMonitorCollection.cc.

References alarmHandler_, checkSataDisks(), stor::AlarmHandler::ERROR, and latchedSataBeastStatus_.

Referenced by checkSataBeasts().

  {
    if ( ! (checkSataDisks(sataBeast,"-00.cms") || checkSataDisks(sataBeast,"-10.cms")) )
    {
      XCEPT_DECLARE(stor::exception::SataBeast, ex, 
        "Failed to connect to SATA beast " + sataBeast);
      alarmHandler_->raiseAlarm(sataBeast, AlarmHandler::ERROR, ex);
      
      latchedSataBeastStatus_ = 99999;
    }
  }
void stor::ResourceMonitorCollection::checkSataBeasts ( ) [private]

Definition at line 434 of file ResourceMonitorCollection.cc.

References checkSataBeast(), getSataBeasts(), and latchedSataBeastStatus_.

Referenced by do_calculateStatistics().

  {
    SATABeasts sataBeasts;
    if ( getSataBeasts(sataBeasts) )
    {
      for (
        SATABeasts::const_iterator it = sataBeasts.begin(),
          itEnd= sataBeasts.end();
        it != itEnd;
        ++it
      )
      {
        checkSataBeast(*it);
      }
    }
    else
    {
      latchedSataBeastStatus_ = -1;
    }
  }
bool stor::ResourceMonitorCollection::checkSataDisks ( const std::string &  sataBeast,
const std::string &  hostSuffix 
) [private]

Definition at line 499 of file ResourceMonitorCollection.cc.

References stor::CurlInterface::getContent(), runTheMatrix::msg, runEdmFileComparison::returnCode, and stor::AlarmHandler::WARNING.

Referenced by checkSataBeast().

  {
    CurlInterface curlInterface;
    CurlInterface::Content content;
    
    // Do not try to connect if we have no user name
    if ( rmParams_.sataUser_.empty() ) return true;
    
    const CURLcode returnCode =
      curlInterface.getContent(
        "https://" + sataBeast + hostSuffix + "/status.asp",rmParams_.sataUser_,
        content
      );
    
    if (returnCode == CURLE_OK)
    {
      updateSataBeastStatus(sataBeast, std::string(&content[0]));
      return true;
    }
    else
    {
      std::ostringstream msg;
      msg << "Failed to connect to SATA controller "
        << sataBeast << hostSuffix 
        << ": " << std::string(&content[0]);
      XCEPT_DECLARE(stor::exception::SataBeast, ex, msg.str());
      alarmHandler_->notifySentinel(AlarmHandler::WARNING, ex);
      
      return false;
    }
  }
void stor::ResourceMonitorCollection::configureAlarms ( AlarmParams const &  alarmParams)

Configures the alarms

Definition at line 111 of file ResourceMonitorCollection.cc.

Referenced by stor::Ready::do_entryActionWork().

  {
    alarmParams_ = alarmParams;
  }
void stor::ResourceMonitorCollection::configureDisks ( DiskWritingParams const &  dwParams)

Configures the disks used to write events

Definition at line 49 of file ResourceMonitorCollection.cc.

References addDisk(), addOtherDisks(), alarmParams_, stor::DiskWritingParams::dbFilePath_, diskUsageList_, diskUsageListMutex_, dwParams_, stor::DiskWritingParams::filePath_, i, stor::AlarmParams::isProductionSystem_, max(), stor::DiskWritingParams::nLogicalDisk_, nLogicalDisks_, stor::DiskWritingParams::otherDiskPaths_, and pathName().

Referenced by stor::Ready::do_entryActionWork().

  {
    boost::mutex::scoped_lock sl(diskUsageListMutex_);
    
    dwParams_ = dwParams;
    
    nLogicalDisks_ = std::max(dwParams.nLogicalDisk_, 1);
    diskUsageList_.clear();
    diskUsageList_.reserve(nLogicalDisks_+dwParams.otherDiskPaths_.size()+1);
    
    for (unsigned int i=0; i<nLogicalDisks_; ++i) {
      
      std::ostringstream pathName;
      pathName << dwParams.filePath_;
      if( dwParams.nLogicalDisk_ > 0 ) {
        pathName << "/" << std::setfill('0') << std::setw(2) << i; 
      }
      addDisk(pathName.str());
    }
    addDisk(dwParams.dbFilePath_);
    
    if ( alarmParams_.isProductionSystem_ )
    {
      addOtherDisks();
    }
  }
void stor::ResourceMonitorCollection::configureResources ( ResourceMonitorParams const &  rmParams)

Configures the resources to be monitored

Definition at line 102 of file ResourceMonitorCollection.cc.

Referenced by stor::Ready::do_entryActionWork().

  {
    rmParams_ = rmParams;
  }
void stor::ResourceMonitorCollection::do_appendInfoSpaceItems ( InfoSpaceItems infoSpaceItems) [private, virtual]

Reimplemented from stor::MonitorCollection.

Definition at line 180 of file ResourceMonitorCollection.cc.

References copyWorkers_, diskPaths_, injectWorkers_, numberOfDisks_, sataBeastStatus_, totalDiskSpace_, and usedDiskSpace_.

  {
    infoSpaceItems.push_back(std::make_pair("copyWorkers", &copyWorkers_));
    infoSpaceItems.push_back(std::make_pair("injectWorkers", &injectWorkers_));
    infoSpaceItems.push_back(std::make_pair("sataBeastStatus", &sataBeastStatus_));
    infoSpaceItems.push_back(std::make_pair("numberOfDisks", &numberOfDisks_));
    infoSpaceItems.push_back(std::make_pair("diskPaths", &diskPaths_));
    infoSpaceItems.push_back(std::make_pair("totalDiskSpace", &totalDiskSpace_));
    infoSpaceItems.push_back(std::make_pair("usedDiskSpace", &usedDiskSpace_));
  }
void stor::ResourceMonitorCollection::do_calculateStatistics ( ) [private, virtual]
void stor::ResourceMonitorCollection::do_reset ( ) [private, virtual]

Implements stor::MonitorCollection.

Definition at line 161 of file ResourceMonitorCollection.cc.

References diskUsageList_, diskUsageListMutex_, latchedSataBeastStatus_, numberOfCopyWorkers_, numberOfInjectWorkers_, and stor::AlarmHandler::OKAY.

  {
    numberOfCopyWorkers_ = -1;
    numberOfInjectWorkers_ = -1;
    latchedSataBeastStatus_ = -1;
    
    boost::mutex::scoped_lock sl(diskUsageListMutex_);
    for ( DiskUsagePtrList::const_iterator it = diskUsageList_.begin(),
            itEnd = diskUsageList_.end();
          it != itEnd;
          ++it)
    {
      (*it)->absDiskUsage = -1;
      (*it)->relDiskUsage = -1;
      (*it)->alarmState = AlarmHandler::OKAY;
    }
  }
void stor::ResourceMonitorCollection::do_updateInfoSpaceItems ( ) [private, virtual]

Reimplemented from stor::MonitorCollection.

Definition at line 192 of file ResourceMonitorCollection.cc.

References calcDiskUsage(), copyWorkers_, diskPaths_, stor::ResourceMonitorCollection::Stats::diskUsageStatsList, getStats(), injectWorkers_, nLogicalDisks_, stor::ResourceMonitorCollection::Stats::numberOfCopyWorkers, numberOfDisks_, stor::ResourceMonitorCollection::Stats::numberOfInjectWorkers, stor::ResourceMonitorCollection::Stats::sataBeastStatus, sataBeastStatus_, totalDiskSpace_, and usedDiskSpace_.

  {
    Stats stats;
    getStats(stats);
    
    if (stats.numberOfCopyWorkers > 0)
      copyWorkers_ = static_cast<xdata::UnsignedInteger32>(stats.numberOfCopyWorkers);
    else
      copyWorkers_ = 0;

    if (stats.numberOfInjectWorkers > 0)
      injectWorkers_ = static_cast<xdata::UnsignedInteger32>(stats.numberOfInjectWorkers);
    else
      injectWorkers_ = 0;
    
    sataBeastStatus_ = stats.sataBeastStatus;
    numberOfDisks_ = nLogicalDisks_;
    
    diskPaths_.clear();
    totalDiskSpace_.clear();
    usedDiskSpace_.clear();
    
    diskPaths_.reserve(stats.diskUsageStatsList.size());
    totalDiskSpace_.reserve(stats.diskUsageStatsList.size());
    usedDiskSpace_.reserve(stats.diskUsageStatsList.size());
    
    for (DiskUsageStatsPtrList::const_iterator
           it = stats.diskUsageStatsList.begin(),
           itEnd = stats.diskUsageStatsList.end();
         it != itEnd;
         ++it)
    {
      diskPaths_.push_back(
        static_cast<xdata::String>( (*it)->pathName )
      );
      totalDiskSpace_.push_back(
        static_cast<xdata::UnsignedInteger32>(
          static_cast<unsigned int>( (*it)->diskSize * 1024 )
        )
      );
      usedDiskSpace_.push_back(
        static_cast<xdata::UnsignedInteger32>( 
          static_cast<unsigned int>( (*it)->absDiskUsage * 1024 )
        )
      );
    }
    
    calcDiskUsage();
  }
void stor::ResourceMonitorCollection::emitDiskAlarm ( DiskUsagePtr  diskUsage,
error_t  e 
) [private]

Definition at line 293 of file ResourceMonitorCollection.cc.

References alarmHandler_, dqm::qstatus::ERROR, runTheMatrix::msg, and dqm::qstatus::WARNING.

Referenced by retrieveDiskSize().

  {
    std::string msg;
    
    switch(e)
    {
      case ENOENT :
        diskUsage->alarmState = AlarmHandler::ERROR;
        msg = "Cannot access " + diskUsage->pathName + ". Is it mounted?";
        break;
        
      default :
        diskUsage->alarmState = AlarmHandler::WARNING;
        msg = "Failed to retrieve disk space information for " + diskUsage->pathName + ":"
          + strerror(e);
    }
    
    XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, msg);
    alarmHandler_->notifySentinel(diskUsage->alarmState, ex);
  }
void stor::ResourceMonitorCollection::emitDiskSpaceAlarm ( DiskUsagePtr  diskUsage) [private]

Definition at line 316 of file ResourceMonitorCollection.cc.

References alarmHandler_, dwParams_, stor::DiskWritingParams::failHighWaterMark_, failIfImportantDisk(), and dqm::qstatus::WARNING.

Referenced by retrieveDiskSize().

  {
    if ( diskUsage->relDiskUsage > dwParams_.failHighWaterMark_ )
    {
      failIfImportantDisk(diskUsage);
    }
    
    diskUsage->alarmState = AlarmHandler::WARNING;
    
    XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, diskUsage->toString());
    alarmHandler_->raiseAlarm(diskUsage->pathName, diskUsage->alarmState, ex);
  }
void stor::ResourceMonitorCollection::failIfImportantDisk ( DiskUsagePtr  diskUsage) [private]

Definition at line 330 of file ResourceMonitorCollection.cc.

References begin, dwParams_, end, stor::AlarmHandler::FATAL, spr::find(), and stor::DiskWritingParams::otherDiskPaths_.

Referenced by emitDiskSpaceAlarm().

  {
    // do not fail if the disk is one of the other disks
    DiskWritingParams::OtherDiskPaths::const_iterator begin =
      dwParams_.otherDiskPaths_.begin();
    DiskWritingParams::OtherDiskPaths::const_iterator end =
      dwParams_.otherDiskPaths_.end();
    if ( std::find(begin, end, diskUsage->pathName) != end ) return;
    
    diskUsage->alarmState = AlarmHandler::FATAL;
    XCEPT_RAISE(stor::exception::DiskSpaceAlarm, diskUsage->toString());
  }
void stor::ResourceMonitorCollection::getDiskStats ( Stats stats) const [private]

Definition at line 130 of file ResourceMonitorCollection.cc.

References diskUsageList_, diskUsageListMutex_, and stor::ResourceMonitorCollection::Stats::diskUsageStatsList.

Referenced by getStats().

  {
    boost::mutex::scoped_lock sl(diskUsageListMutex_);
    
    stats.diskUsageStatsList.clear();
    stats.diskUsageStatsList.reserve(diskUsageList_.size());
    for ( DiskUsagePtrList::const_iterator it = diskUsageList_.begin(),
            itEnd = diskUsageList_.end();
          it != itEnd;
          ++it)
    {
      DiskUsageStatsPtr diskUsageStats(new DiskUsageStats);
      diskUsageStats->diskSize = (*it)->diskSize;
      diskUsageStats->absDiskUsage = (*it)->absDiskUsage;
      diskUsageStats->relDiskUsage = (*it)->relDiskUsage;
      diskUsageStats->pathName = (*it)->pathName;
      diskUsageStats->alarmState = (*it)->alarmState;
      stats.diskUsageStatsList.push_back(diskUsageStats);
    }
  }
int stor::ResourceMonitorCollection::getProcessCount ( const std::string &  processName,
const int &  uid = -1 
) [private]

Definition at line 647 of file ResourceMonitorCollection.cc.

References prof2calltree::count, align_tpl::filter, and n.

Referenced by calcNumberOfCopyWorkers(), and calcNumberOfInjectWorkers().

  {
    int count(0);
    struct dirent **namelist;
    int n;
    
    #if __APPLE__
    return -1;
    #else 
    n = scandir("/proc", &namelist, filter, 0);
    #endif
    if (n < 0) return -1;
    
    while(n--)
    {
      std::ostringstream cmdline;
      cmdline << "/proc/" << namelist[n]->d_name << "/cmdline";
      
      if ( grep(cmdline.str(), processName) &&
        (uid < 0 || matchUid(cmdline.str(), uid)) &&
        isMaster(namelist[n]->d_name) )
      {
        ++count;
      }
      free(namelist[n]);
    }
    free(namelist);
    
    return count;
  }
bool stor::ResourceMonitorCollection::getSataBeasts ( SATABeasts sataBeasts) [private]

Definition at line 456 of file ResourceMonitorCollection.cc.

References alarmParams_, query::host, recoMuon::in, stor::AlarmParams::isProductionSystem_, geometryCSVtoXML::line, and pos.

Referenced by checkSataBeasts().

  {
    if (! alarmParams_.isProductionSystem_) return false;
    
    std::ifstream in;
    in.open( "/proc/mounts" );
    
    if ( ! in.is_open() ) return false;
    
    std::string line;
    while( getline(in,line) )
    {
      size_t pos = line.find("sata");
      if ( pos != std::string::npos )
      {
        std::ostringstream host;
        host << "satab-c2c"
          << std::setw(2) << std::setfill('0')
          << line.substr(pos+4,1)
          << "-"
          << std::setw(2) << std::setfill('0')
          << line.substr(pos+5,1);
        sataBeasts.insert(host.str());
      }
    }
    return !sataBeasts.empty();
  }
void stor::ResourceMonitorCollection::getStats ( Stats stats) const
ResourceMonitorCollection& stor::ResourceMonitorCollection::operator= ( ResourceMonitorCollection const &  ) [private]
void stor::ResourceMonitorCollection::retrieveDiskSize ( DiskUsagePtr  diskUsage) [private]

Definition at line 256 of file ResourceMonitorCollection.cc.

References dwParams_, emitDiskAlarm(), emitDiskSpaceAlarm(), stor::DiskWritingParams::highWaterMark_, and revokeDiskAlarm().

Referenced by addDisk(), and calcDiskUsage().

  {
    #if __APPLE__
    struct statfs buf;
    int retVal = statfs(diskUsage->pathName.c_str(), &buf);
    #else
    struct statfs64 buf;
    int retVal = statfs64(diskUsage->pathName.c_str(), &buf);
    #endif
    if(retVal==0) {
      unsigned int blksize = buf.f_bsize;
      diskUsage->diskSize =
        static_cast<double>(buf.f_blocks * blksize) / 1024 / 1024 / 1024;
      diskUsage->absDiskUsage =
        diskUsage->diskSize -
        static_cast<double>(buf.f_bavail * blksize) / 1024 / 1024 / 1024;
      diskUsage->relDiskUsage = (100 * (diskUsage->absDiskUsage / diskUsage->diskSize));
      if ( diskUsage->relDiskUsage > dwParams_.highWaterMark_ )
      {
        emitDiskSpaceAlarm(diskUsage);
      }
      else if ( diskUsage->relDiskUsage < dwParams_.highWaterMark_*0.95 )
        // do not change alarm level if we are close to the high water mark
      {
        revokeDiskAlarm(diskUsage);
      }
    }
    else
    {
      emitDiskAlarm(diskUsage, errno);
      diskUsage->diskSize = -1;
      diskUsage->absDiskUsage = -1;
      diskUsage->relDiskUsage = -1;
    }
  }
void stor::ResourceMonitorCollection::revokeDiskAlarm ( DiskUsagePtr  diskUsage) [private]

Definition at line 344 of file ResourceMonitorCollection.cc.

References alarmHandler_, and stor::AlarmHandler::OKAY.

Referenced by retrieveDiskSize().

  {
    diskUsage->alarmState = AlarmHandler::OKAY;
    
    alarmHandler_->revokeAlarm(diskUsage->pathName);
  }
void stor::ResourceMonitorCollection::updateSataBeastStatus ( const std::string &  sataBeast,
const std::string &  content 
) [private]

Definition at line 536 of file ResourceMonitorCollection.cc.

References end, stor::AlarmHandler::ERROR, and flags.

  {
    boost::regex failedEntry(">([^<]* has failed[^<]*)");
    boost::regex failedDisk("Hard disk([[:digit:]]+)");
    boost::regex failedController("RAID controller ([[:digit:]]+)");
    boost::match_results<std::string::const_iterator> matchedEntry, matchedCause;
    boost::match_flag_type flags = boost::match_default;
    
    std::string::const_iterator start = content.begin();
    std::string::const_iterator end = content.end();
    
    unsigned int newSataBeastStatus = 0;
    
    while( regex_search(start, end, matchedEntry, failedEntry, flags) )
    {
      std::string errorMsg = matchedEntry[1];
      XCEPT_DECLARE(stor::exception::SataBeast, ex, sataBeast+": "+errorMsg);
      alarmHandler_->raiseAlarm(sataBeast, AlarmHandler::ERROR, ex);
      
      // find what failed
      if ( regex_search(errorMsg, matchedCause, failedDisk) )
      {
        // Update the number of failed disks
        ++newSataBeastStatus;
      }
      else if ( regex_search(errorMsg, matchedCause, failedController) )
      {
        // Update the number of failed controllers
        newSataBeastStatus += 100;
      }
      else
      {
        // Unknown failure
        newSataBeastStatus += 1000;
      }
      
      // update search position:
      start = matchedEntry[0].second;
      // update flags:
      flags |= boost::match_prev_avail;
      flags |= boost::match_not_bob;
    }
    
    latchedSataBeastStatus_ = newSataBeastStatus;
    
    if (latchedSataBeastStatus_ == 0) // no more problems
      alarmHandler_->revokeAlarm(sataBeast);
    
  }

Friends And Related Function Documentation

friend class testResourceMonitorCollection [friend]

Definition at line 45 of file ResourceMonitorCollection.h.


Member Data Documentation

xdata::UnsignedInteger32 stor::ResourceMonitorCollection::copyWorkers_ [private]

Definition at line 112 of file ResourceMonitorCollection.h.

Referenced by calcDiskUsage(), configureDisks(), do_reset(), and getDiskStats().

xdata::UnsignedInteger32 stor::ResourceMonitorCollection::injectWorkers_ [private]

Definition at line 157 of file ResourceMonitorCollection.h.

Referenced by checkSataBeast(), checkSataBeasts(), do_reset(), and getStats().

Definition at line 156 of file ResourceMonitorCollection.h.

Referenced by configureDisks(), and do_updateInfoSpaceItems().

xdata::UnsignedInteger32 stor::ResourceMonitorCollection::numberOfDisks_ [private]

Reimplemented from stor::MonitorCollection.

Definition at line 114 of file ResourceMonitorCollection.h.