CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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

Classes

struct  DiskUsage
 
struct  DiskUsageStats
 
struct  Stats
 

Public Types

typedef boost::shared_ptr
< DiskUsageStats
DiskUsageStatsPtr
 
typedef std::vector
< DiskUsageStatsPtr
DiskUsageStatsPtrList
 
- Public Types inherited from stor::MonitorCollection
typedef std::vector< std::pair
< std::string,
xdata::Serializable * > > 
InfoSpaceItems
 

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)
 
- Public Member Functions inherited from stor::MonitorCollection
void appendInfoSpaceItems (InfoSpaceItems &)
 
void calculateStatistics (const utils::TimePoint_t &now)
 
 MonitorCollection (const utils::Duration_t &updateInterval)
 
void reset (const utils::TimePoint_t &now)
 
void updateInfoSpaceItems ()
 
virtual ~MonitorCollection ()
 

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 doStatFs (DiskUsagePtr)
 
void emitDiskAlarm (DiskUsagePtr)
 
void emitDiskSpaceAlarm (DiskUsagePtr)
 
void getDiskStats (Stats &) const
 
int getProcessCount (const std::string &processName, const int &uid=-1)
 
bool getSataBeasts (SATABeasts &sataBeasts)
 
bool isImportantDisk (const std::string &)
 
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
 

Additional Inherited Members

Detailed Description

A collection of MonitoredQuantities related to resource usages

Author:
mommsen
Revision:
1.30
Date:
2011/11/10 10:56:37

Definition at line 44 of file ResourceMonitorCollection.h.

Member Typedef Documentation

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

Definition at line 121 of file ResourceMonitorCollection.h.

Definition at line 122 of file ResourceMonitorCollection.h.

Definition at line 59 of file ResourceMonitorCollection.h.

Definition at line 60 of file ResourceMonitorCollection.h.

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

Definition at line 156 of file ResourceMonitorCollection.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 30 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 72 of file ResourceMonitorCollection.cc.

References diskUsageList_, and retrieveDiskSize().

Referenced by addOtherDisks(), and configureDisks().

73  {
74  if ( pathname.empty() ) return;
75 
76  DiskUsagePtr diskUsage( new DiskUsage(pathname) );
77  retrieveDiskSize(diskUsage);
78  diskUsageList_.push_back(diskUsage);
79  }
boost::shared_ptr< DiskUsage > DiskUsagePtr
void stor::ResourceMonitorCollection::addOtherDisks ( )
private

Definition at line 82 of file ResourceMonitorCollection.cc.

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

Referenced by configureDisks().

83  {
84  for ( DiskWritingParams::OtherDiskPaths::const_iterator
85  it = dwParams_.otherDiskPaths_.begin(),
86  itEnd = dwParams_.otherDiskPaths_.end();
87  it != itEnd;
88  ++it)
89  {
90  addDisk(*it);
91  }
92  }
OtherDiskPaths otherDiskPaths_
Definition: Configuration.h:48
void stor::ResourceMonitorCollection::calcDiskUsage ( )
private

Definition at line 242 of file ResourceMonitorCollection.cc.

References diskUsageList_, diskUsageListMutex_, and retrieveDiskSize().

Referenced by do_calculateStatistics(), and do_updateInfoSpaceItems().

243  {
244  boost::mutex::scoped_lock sl(diskUsageListMutex_);
245 
246  for ( DiskUsagePtrList::iterator it = diskUsageList_.begin(),
247  itEnd = diskUsageList_.end();
248  it != itEnd;
249  ++it)
250  {
251  retrieveDiskSize(*it);
252  }
253  }
void stor::ResourceMonitorCollection::calcNumberOfCopyWorkers ( )
private

Definition at line 370 of file ResourceMonitorCollection.cc.

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

Referenced by do_calculateStatistics().

371  {
372  struct passwd* passwd = getpwnam(rmParams_.copyWorkers_.user_.c_str());
373  if (passwd)
374  {
377  }
378  else
379  {
381  }
382 
384  {
386  }
387  }
int getProcessCount(const std::string &processName, const int &uid=-1)
void stor::ResourceMonitorCollection::calcNumberOfInjectWorkers ( )
private

Definition at line 410 of file ResourceMonitorCollection.cc.

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

Referenced by do_calculateStatistics().

411  {
412  struct passwd* passwd = getpwnam(rmParams_.injectWorkers_.user_.c_str());
413  if (passwd)
414  {
416  }
417  else
418  {
420  }
421 
422  if (
425  )
426  {
428  }
429  }
int getProcessCount(const std::string &processName, const int &uid=-1)
void stor::ResourceMonitorCollection::checkNumberOfCopyWorkers ( )
private

Definition at line 390 of file ResourceMonitorCollection.cc.

References alarmHandler_, stor::ResourceMonitorParams::copyWorkers_, stor::ResourceMonitorParams::WorkerParams::expectedCount_, lumiQueryAPI::msg, numberOfCopyWorkers_, rmParams_, AlCaHLTBitMon_QueryRunRegistry::string, and stor::AlarmHandler::WARNING.

Referenced by calcNumberOfCopyWorkers().

391  {
392  const std::string alarmName = "CopyWorkers";
393 
395  {
396  std::ostringstream msg;
397  msg << "Expected " << rmParams_.copyWorkers_.expectedCount_ <<
398  " running CopyWorkers, but found " <<
399  numberOfCopyWorkers_ << ".";
400  XCEPT_DECLARE(stor::exception::CopyWorkers, ex, msg.str());
401  alarmHandler_->raiseAlarm(alarmName, AlarmHandler::WARNING, ex);
402  }
403  else
404  {
405  alarmHandler_->revokeAlarm(alarmName);
406  }
407  }
void stor::ResourceMonitorCollection::checkNumberOfInjectWorkers ( )
private

Definition at line 432 of file ResourceMonitorCollection.cc.

References alarmHandler_, stor::ResourceMonitorParams::WorkerParams::expectedCount_, stor::ResourceMonitorParams::injectWorkers_, lumiQueryAPI::msg, numberOfInjectWorkers_, rmParams_, AlCaHLTBitMon_QueryRunRegistry::string, and stor::AlarmHandler::WARNING.

Referenced by calcNumberOfInjectWorkers().

433  {
434  const std::string alarmName = "InjectWorkers";
435 
437  {
438  std::ostringstream msg;
439  msg << "Expected " << rmParams_.injectWorkers_.expectedCount_ <<
440  " running InjectWorkers, but found " <<
441  numberOfInjectWorkers_ << ".";
442  XCEPT_DECLARE(stor::exception::InjectWorkers, ex, msg.str());
443  alarmHandler_->raiseAlarm(alarmName, AlarmHandler::WARNING, ex);
444  }
445  else
446  {
447  alarmHandler_->revokeAlarm(alarmName);
448  }
449  }
void stor::ResourceMonitorCollection::checkSataBeast ( const std::string &  sataBeast)
private

Definition at line 503 of file ResourceMonitorCollection.cc.

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

Referenced by checkSataBeasts().

504  {
505  if ( ! (checkSataDisks(sataBeast,"-00.cms") || checkSataDisks(sataBeast,"-10.cms")) )
506  {
507  XCEPT_DECLARE(stor::exception::SataBeast, ex,
508  "Failed to connect to SATA beast " + sataBeast);
509  alarmHandler_->raiseAlarm(sataBeast, AlarmHandler::ERROR, ex);
510 
511  latchedSataBeastStatus_ = 99999;
512  }
513  }
bool checkSataDisks(const std::string &sataBeast, const std::string &hostSuffix)
void stor::ResourceMonitorCollection::checkSataBeasts ( )
private

Definition at line 452 of file ResourceMonitorCollection.cc.

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

Referenced by do_calculateStatistics().

453  {
454  SATABeasts sataBeasts;
455  if ( getSataBeasts(sataBeasts) )
456  {
457  for (
458  SATABeasts::const_iterator it = sataBeasts.begin(),
459  itEnd= sataBeasts.end();
460  it != itEnd;
461  ++it
462  )
463  {
464  checkSataBeast(*it);
465  }
466  }
467  else
468  {
470  }
471  }
void checkSataBeast(const std::string &sataBeast)
bool getSataBeasts(SATABeasts &sataBeasts)
bool stor::ResourceMonitorCollection::checkSataDisks ( const std::string &  sataBeast,
const std::string &  hostSuffix 
)
private

Definition at line 517 of file ResourceMonitorCollection.cc.

References ws_sso_content_reader::content, stor::CurlInterface::getInterface(), lumiQueryAPI::msg, runEdmFileComparison::returnCode, AlCaHLTBitMon_QueryRunRegistry::string, and stor::AlarmHandler::WARNING.

Referenced by checkSataBeast().

521  {
524 
525  // Do not try to connect if we have no user name
526  if ( rmParams_.sataUser_.empty() ) return true;
527 
528  const CURLcode returnCode =
529  curlInterface->getContent(
530  "http://" + sataBeast + hostSuffix + "/status.asp",rmParams_.sataUser_,
531  content
532  );
533 
534  if (returnCode == CURLE_OK)
535  {
536  updateSataBeastStatus(sataBeast, std::string(&content[0]));
537  return true;
538  }
539  else
540  {
541  std::ostringstream msg;
542  msg << "Failed to connect to SATA controller "
543  << sataBeast << hostSuffix
544  << ": " << std::string(&content[0]);
545  XCEPT_DECLARE(stor::exception::SataBeast, ex, msg.str());
546  alarmHandler_->notifySentinel(AlarmHandler::WARNING, ex);
547 
548  return false;
549  }
550  }
static boost::shared_ptr< CurlInterface > getInterface()
boost::shared_ptr< CurlInterface > CurlInterfacePtr
Definition: CurlInterface.h:71
void updateSataBeastStatus(const std::string &sataBeast, const std::string &content)
std::vector< char > Content
Definition: CurlInterface.h:31
void stor::ResourceMonitorCollection::configureAlarms ( AlarmParams const &  alarmParams)

Configures the alarms

Definition at line 105 of file ResourceMonitorCollection.cc.

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

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

Configures the disks used to write events

Definition at line 44 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 EgammaValidation_cff::pathName.

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

45  {
46  boost::mutex::scoped_lock sl(diskUsageListMutex_);
47 
48  dwParams_ = dwParams;
49 
50  nLogicalDisks_ = std::max(dwParams.nLogicalDisk_, 1);
51  diskUsageList_.clear();
52  diskUsageList_.reserve(nLogicalDisks_+dwParams.otherDiskPaths_.size()+1);
53 
54  for (unsigned int i=0; i<nLogicalDisks_; ++i) {
55 
56  std::ostringstream pathName;
57  pathName << dwParams.filePath_;
58  if( dwParams.nLogicalDisk_ > 0 ) {
59  pathName << "/" << std::setfill('0') << std::setw(2) << i;
60  }
61  addDisk(pathName.str());
62  }
63  addDisk(dwParams.dbFilePath_);
64 
66  {
67  addOtherDisks();
68  }
69  }
int i
Definition: DBlmapReader.cc:9
const T & max(const T &a, const T &b)
void stor::ResourceMonitorCollection::configureResources ( ResourceMonitorParams const &  rmParams)

Configures the resources to be monitored

Definition at line 96 of file ResourceMonitorCollection.cc.

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

99  {
100  rmParams_ = rmParams;
101  }
void stor::ResourceMonitorCollection::do_appendInfoSpaceItems ( InfoSpaceItems infoSpaceItems)
privatevirtual

Reimplemented from stor::MonitorCollection.

Definition at line 179 of file ResourceMonitorCollection.cc.

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

180  {
181  infoSpaceItems.push_back(std::make_pair("copyWorkers", &copyWorkers_));
182  infoSpaceItems.push_back(std::make_pair("injectWorkers", &injectWorkers_));
183  infoSpaceItems.push_back(std::make_pair("sataBeastStatus", &sataBeastStatus_));
184  infoSpaceItems.push_back(std::make_pair("numberOfDisks", &numberOfDisks_));
185  infoSpaceItems.push_back(std::make_pair("diskPaths", &diskPaths_));
186  infoSpaceItems.push_back(std::make_pair("totalDiskSpace", &totalDiskSpace_));
187  infoSpaceItems.push_back(std::make_pair("usedDiskSpace", &usedDiskSpace_));
188  }
xdata::Vector< xdata::UnsignedInteger32 > usedDiskSpace_
xdata::Vector< xdata::UnsignedInteger32 > totalDiskSpace_
xdata::Vector< xdata::String > diskPaths_
void stor::ResourceMonitorCollection::do_calculateStatistics ( )
privatevirtual
void stor::ResourceMonitorCollection::do_reset ( )
privatevirtual

Implements stor::MonitorCollection.

Definition at line 155 of file ResourceMonitorCollection.cc.

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

156  {
160 
161  boost::mutex::scoped_lock sl(diskUsageListMutex_);
162  for ( DiskUsagePtrList::const_iterator it = diskUsageList_.begin(),
163  itEnd = diskUsageList_.end();
164  it != itEnd;
165  ++it)
166  {
167  if ( ! (*it)->retrievingDiskSize_ )
168  {
169  (*it)->diskSize_ = -1;
170  (*it)->absDiskUsage_ = -1;
171  (*it)->relDiskUsage_ = -1;
172  (*it)->retVal_ = 0;
173  (*it)->alarmState_ = AlarmHandler::OKAY;
174  }
175  }
176  }
void stor::ResourceMonitorCollection::do_updateInfoSpaceItems ( )
privatevirtual

Reimplemented from stor::MonitorCollection.

Definition at line 191 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_.

192  {
193  Stats stats;
194  getStats(stats);
195 
196  if (stats.numberOfCopyWorkers > 0)
197  copyWorkers_ = static_cast<xdata::UnsignedInteger32>(stats.numberOfCopyWorkers);
198  else
199  copyWorkers_ = 0;
200 
201  if (stats.numberOfInjectWorkers > 0)
202  injectWorkers_ = static_cast<xdata::UnsignedInteger32>(stats.numberOfInjectWorkers);
203  else
204  injectWorkers_ = 0;
205 
206  sataBeastStatus_ = stats.sataBeastStatus;
208 
209  diskPaths_.clear();
210  totalDiskSpace_.clear();
211  usedDiskSpace_.clear();
212 
213  diskPaths_.reserve(stats.diskUsageStatsList.size());
214  totalDiskSpace_.reserve(stats.diskUsageStatsList.size());
215  usedDiskSpace_.reserve(stats.diskUsageStatsList.size());
216 
217  for (DiskUsageStatsPtrList::const_iterator
218  it = stats.diskUsageStatsList.begin(),
219  itEnd = stats.diskUsageStatsList.end();
220  it != itEnd;
221  ++it)
222  {
223  diskPaths_.push_back(
224  static_cast<xdata::String>( (*it)->pathName )
225  );
226  totalDiskSpace_.push_back(
227  static_cast<xdata::UnsignedInteger32>(
228  static_cast<unsigned int>( (*it)->diskSize * 1024 )
229  )
230  );
231  usedDiskSpace_.push_back(
232  static_cast<xdata::UnsignedInteger32>(
233  static_cast<unsigned int>( (*it)->absDiskUsage * 1024 )
234  )
235  );
236  }
237 
238  calcDiskUsage();
239  }
xdata::Vector< xdata::UnsignedInteger32 > usedDiskSpace_
xdata::Vector< xdata::UnsignedInteger32 > totalDiskSpace_
xdata::Vector< xdata::String > diskPaths_
void stor::ResourceMonitorCollection::doStatFs ( DiskUsagePtr  diskUsage)
private

Definition at line 294 of file ResourceMonitorCollection.cc.

References stor::utils::sleep().

Referenced by retrieveDiskSize().

295  {
296  diskUsage->retrievingDiskSize_ = true;
297 
298  #if __APPLE__
299  diskUsage->retVal_ = statfs(diskUsage->pathName_.c_str(), &(diskUsage->statfs_));
300  #else
301  diskUsage->retVal_ = statfs64(diskUsage->pathName_.c_str(), &(diskUsage->statfs_));
302  #endif
303  if (diskUsage->pathName_ == "/aSlowDiskForUnitTests") ::sleep(5);
304 
305  diskUsage->retrievingDiskSize_ = false;
306  }
void sleep(Duration_t)
Definition: Utils.h:163
void stor::ResourceMonitorCollection::emitDiskAlarm ( DiskUsagePtr  diskUsage)
private

Definition at line 309 of file ResourceMonitorCollection.cc.

References alarmHandler_, stor::AlarmHandler::ERROR, stor::AlarmHandler::FATAL, isImportantDisk(), lumiQueryAPI::msg, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by retrieveDiskSize().

310  {
311  const std::string msg = "Cannot access " + diskUsage->pathName_ + ". Is it mounted?";
312 
313  diskUsage->diskSize_ = -1;
314  diskUsage->absDiskUsage_ = -1;
315  diskUsage->relDiskUsage_ = -1;
316 
317  if ( isImportantDisk(diskUsage->pathName_) )
318  {
319  diskUsage->alarmState_ = AlarmHandler::FATAL;
320  XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, msg);
321  alarmHandler_->moveToFailedState(ex);
322  }
323  else
324  {
325  diskUsage->alarmState_ = AlarmHandler::ERROR;
326  XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, msg);
327  alarmHandler_->raiseAlarm(diskUsage->pathName_, diskUsage->alarmState_, ex);
328  }
329  }
void stor::ResourceMonitorCollection::emitDiskSpaceAlarm ( DiskUsagePtr  diskUsage)
private

Definition at line 332 of file ResourceMonitorCollection.cc.

References alarmHandler_, dwParams_, stor::DiskWritingParams::failHighWaterMark_, stor::AlarmHandler::FATAL, isImportantDisk(), and stor::AlarmHandler::WARNING.

Referenced by retrieveDiskSize().

333  {
334  if (
335  isImportantDisk(diskUsage->pathName_) &&
336  (diskUsage->relDiskUsage_ > dwParams_.failHighWaterMark_)
337  )
338  {
339  diskUsage->alarmState_ = AlarmHandler::FATAL;
340  XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, diskUsage->toString());
341  alarmHandler_->moveToFailedState(ex);
342  }
343  else
344  {
345  diskUsage->alarmState_ = AlarmHandler::WARNING;
346  XCEPT_DECLARE(stor::exception::DiskSpaceAlarm, ex, diskUsage->toString());
347  alarmHandler_->raiseAlarm(diskUsage->pathName_, diskUsage->alarmState_, ex);
348  }
349  }
void stor::ResourceMonitorCollection::getDiskStats ( Stats stats) const
private

Definition at line 124 of file ResourceMonitorCollection.cc.

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

Referenced by getStats().

125  {
126  boost::mutex::scoped_lock sl(diskUsageListMutex_);
127 
128  stats.diskUsageStatsList.clear();
129  stats.diskUsageStatsList.reserve(diskUsageList_.size());
130  for ( DiskUsagePtrList::const_iterator it = diskUsageList_.begin(),
131  itEnd = diskUsageList_.end();
132  it != itEnd;
133  ++it)
134  {
135  DiskUsageStatsPtr diskUsageStats(new DiskUsageStats);
136  diskUsageStats->diskSize = (*it)->diskSize_;
137  diskUsageStats->absDiskUsage = (*it)->absDiskUsage_;
138  diskUsageStats->relDiskUsage = (*it)->relDiskUsage_;
139  diskUsageStats->pathName = (*it)->pathName_;
140  diskUsageStats->alarmState = (*it)->alarmState_;
141  stats.diskUsageStatsList.push_back(diskUsageStats);
142  }
143  }
boost::shared_ptr< DiskUsageStats > DiskUsageStatsPtr
int stor::ResourceMonitorCollection::getProcessCount ( const std::string &  processName,
const int &  uid = -1 
)
private

Definition at line 665 of file ResourceMonitorCollection.cc.

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

Referenced by calcNumberOfCopyWorkers(), and calcNumberOfInjectWorkers().

669  {
670  int count(0);
671  struct dirent **namelist;
672  int n;
673 
674  #if __APPLE__
675  return -1;
676  #else
677  n = scandir("/proc", &namelist, filter, 0);
678  #endif
679  if (n < 0) return -1;
680 
681  while(n--)
682  {
683  std::ostringstream cmdline;
684  cmdline << "/proc/" << namelist[n]->d_name << "/cmdline";
685 
686  if ( grep(cmdline.str(), processName) &&
687  (uid < 0 || matchUid(cmdline.str(), uid)) &&
688  isMaster(namelist[n]->d_name) )
689  {
690  ++count;
691  }
692  free(namelist[n]);
693  }
694  free(namelist);
695 
696  return count;
697  }
bool stor::ResourceMonitorCollection::getSataBeasts ( SATABeasts sataBeasts)
private

Definition at line 474 of file ResourceMonitorCollection.cc.

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

Referenced by checkSataBeasts().

475  {
476  if (! alarmParams_.isProductionSystem_) return false;
477 
478  std::ifstream in;
479  in.open( "/proc/mounts" );
480 
481  if ( ! in.is_open() ) return false;
482 
484  while( getline(in,line) )
485  {
486  size_t pos = line.find("sata");
487  if ( pos != std::string::npos )
488  {
489  std::ostringstream host;
490  host << "satab-c2c"
491  << std::setw(2) << std::setfill('0')
492  << line.substr(pos+4,1)
493  << "-"
494  << std::setw(2) << std::setfill('0')
495  << line.substr(pos+5,1);
496  sataBeasts.insert(host.str());
497  }
498  }
499  return !sataBeasts.empty();
500  }
string host
Definition: query.py:114
void stor::ResourceMonitorCollection::getStats ( Stats stats) const
bool stor::ResourceMonitorCollection::isImportantDisk ( const std::string &  pathName)
private

Definition at line 352 of file ResourceMonitorCollection.cc.

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

Referenced by emitDiskAlarm(), and emitDiskSpaceAlarm().

353  {
354  DiskWritingParams::OtherDiskPaths::const_iterator begin =
355  dwParams_.otherDiskPaths_.begin();
356  DiskWritingParams::OtherDiskPaths::const_iterator end =
358  return ( std::find(begin, end, pathName) == end );
359  }
OtherDiskPaths otherDiskPaths_
Definition: Configuration.h:48
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
#define end
Definition: vmac.h:38
#define begin
Definition: vmac.h:31
ResourceMonitorCollection& stor::ResourceMonitorCollection::operator= ( ResourceMonitorCollection const &  )
private
void stor::ResourceMonitorCollection::retrieveDiskSize ( DiskUsagePtr  diskUsage)
private

Definition at line 256 of file ResourceMonitorCollection.cc.

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

Referenced by addDisk(), and calcDiskUsage().

257  {
258  if ( ! diskUsage->retrievingDiskSize_ )
259  // don't start another thread if there's already one
260  {
261  boost::thread thread(
262  boost::bind( &ResourceMonitorCollection::doStatFs, this, diskUsage)
263  );
264  if (
265  ( ! thread.timed_join( boost::posix_time::milliseconds(500) ) )
266  || (diskUsage->retVal_ != 0)
267  )
268  {
269  emitDiskAlarm(diskUsage);
270  }
271  else
272  {
273  const unsigned int blksize = diskUsage->statfs_.f_bsize;
274  diskUsage->diskSize_ =
275  static_cast<double>(diskUsage->statfs_.f_blocks * blksize) / 1024 / 1024 / 1024;
276  diskUsage->absDiskUsage_ =
277  diskUsage->diskSize_ -
278  static_cast<double>(diskUsage->statfs_.f_bavail * blksize) / 1024 / 1024 / 1024;
279  diskUsage->relDiskUsage_ = (100 * (diskUsage->absDiskUsage_ / diskUsage->diskSize_));
280  if ( diskUsage->relDiskUsage_ > dwParams_.highWaterMark_ )
281  {
282  emitDiskSpaceAlarm(diskUsage);
283  }
284  else if ( diskUsage->relDiskUsage_ < dwParams_.highWaterMark_*0.95 )
285  // do not change alarm level if we are close to the high water mark
286  {
287  revokeDiskAlarm(diskUsage);
288  }
289  }
290  }
291  }
void stor::ResourceMonitorCollection::revokeDiskAlarm ( DiskUsagePtr  diskUsage)
private

Definition at line 362 of file ResourceMonitorCollection.cc.

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

Referenced by retrieveDiskSize().

363  {
364  diskUsage->alarmState_ = AlarmHandler::OKAY;
365 
366  alarmHandler_->revokeAlarm(diskUsage->pathName_);
367  }
void stor::ResourceMonitorCollection::updateSataBeastStatus ( const std::string &  sataBeast,
const std::string &  content 
)
private

Definition at line 554 of file ResourceMonitorCollection.cc.

References end, stor::AlarmHandler::ERROR, flags, dqm_diff::start, and AlCaHLTBitMon_QueryRunRegistry::string.

558  {
559  boost::regex failedEntry(">([^<]* has failed[^<]*)");
560  boost::regex failedDisk("Hard disk([[:digit:]]+)");
561  boost::regex failedController("RAID controller ([[:digit:]]+)");
562  boost::match_results<std::string::const_iterator> matchedEntry, matchedCause;
563  boost::match_flag_type flags = boost::match_default;
564 
565  std::string::const_iterator start = content.begin();
566  std::string::const_iterator end = content.end();
567 
568  unsigned int newSataBeastStatus = 0;
569 
570  while( regex_search(start, end, matchedEntry, failedEntry, flags) )
571  {
572  std::string errorMsg = matchedEntry[1];
573  XCEPT_DECLARE(stor::exception::SataBeast, ex, sataBeast+": "+errorMsg);
574  alarmHandler_->raiseAlarm(sataBeast, AlarmHandler::ERROR, ex);
575 
576  // find what failed
577  if ( regex_search(errorMsg, matchedCause, failedDisk) )
578  {
579  // Update the number of failed disks
580  ++newSataBeastStatus;
581  }
582  else if ( regex_search(errorMsg, matchedCause, failedController) )
583  {
584  // Update the number of failed controllers
585  newSataBeastStatus += 100;
586  }
587  else
588  {
589  // Unknown failure
590  newSataBeastStatus += 1000;
591  }
592 
593  // update search position:
594  start = matchedEntry[0].second;
595  // update flags:
596  flags |= boost::match_prev_avail;
597  flags |= boost::match_not_bob;
598  }
599 
600  latchedSataBeastStatus_ = newSataBeastStatus;
601 
602  if (latchedSataBeastStatus_ == 0) // no more problems
603  alarmHandler_->revokeAlarm(sataBeast);
604 
605  }
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
#define end
Definition: vmac.h:38

Friends And Related Function Documentation

friend class testResourceMonitorCollection
friend

Definition at line 49 of file ResourceMonitorCollection.h.

Member Data Documentation

AlarmHandlerPtr stor::ResourceMonitorCollection::alarmHandler_
private
AlarmParams stor::ResourceMonitorCollection::alarmParams_
private
xdata::UnsignedInteger32 stor::ResourceMonitorCollection::copyWorkers_
private
xdata::Vector<xdata::String> stor::ResourceMonitorCollection::diskPaths_
private
DiskUsagePtrList stor::ResourceMonitorCollection::diskUsageList_
private
boost::mutex stor::ResourceMonitorCollection::diskUsageListMutex_
mutableprivate

Definition at line 124 of file ResourceMonitorCollection.h.

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

DiskWritingParams stor::ResourceMonitorCollection::dwParams_
private
xdata::UnsignedInteger32 stor::ResourceMonitorCollection::injectWorkers_
private
int stor::ResourceMonitorCollection::latchedSataBeastStatus_
private

Definition at line 170 of file ResourceMonitorCollection.h.

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

unsigned int stor::ResourceMonitorCollection::nLogicalDisks_
private

Definition at line 169 of file ResourceMonitorCollection.h.

Referenced by configureDisks(), and do_updateInfoSpaceItems().

int stor::ResourceMonitorCollection::numberOfCopyWorkers_
private
xdata::UnsignedInteger32 stor::ResourceMonitorCollection::numberOfDisks_
private
int stor::ResourceMonitorCollection::numberOfInjectWorkers_
private
ResourceMonitorParams stor::ResourceMonitorCollection::rmParams_
private
xdata::Integer32 stor::ResourceMonitorCollection::sataBeastStatus_
private
xdata::Vector<xdata::UnsignedInteger32> stor::ResourceMonitorCollection::totalDiskSpace_
private
const utils::Duration_t stor::ResourceMonitorCollection::updateInterval_
private

Definition at line 126 of file ResourceMonitorCollection.h.

xdata::Vector<xdata::UnsignedInteger32> stor::ResourceMonitorCollection::usedDiskSpace_
private