00001 // $Id: ResourceMonitorCollection.h,v 1.30 2011/11/10 10:56:37 mommsen Exp $ 00003 00004 #ifndef EventFilter_StorageManager_ResourceMonitorCollection_h 00005 #define EventFilter_StorageManager_ResourceMonitorCollection_h 00006 00007 #include <set> 00008 #include <vector> 00009 #include <string> 00010 #include <errno.h> 00011 00012 #ifdef __APPLE__ 00013 #include <sys/param.h> 00014 #include <sys/mount.h> 00015 #else 00016 #include <sys/statfs.h> 00017 #endif 00018 00019 #include <boost/thread/mutex.hpp> 00020 #include <boost/shared_ptr.hpp> 00021 00022 #include "xdata/Integer32.h" 00023 #include "xdata/String.h" 00024 #include "xdata/UnsignedInteger32.h" 00025 #include "xdata/Vector.h" 00026 00027 #include "EventFilter/StorageManager/interface/AlarmHandler.h" 00028 #include "EventFilter/StorageManager/interface/Configuration.h" 00029 #include "EventFilter/StorageManager/interface/MonitorCollection.h" 00030 00031 00032 namespace stor { 00033 00034 class testResourceMonitorCollection; 00035 00044 class ResourceMonitorCollection : public MonitorCollection 00045 { 00046 public: 00047 00048 // Allow unit test to access the private methods 00049 friend class testResourceMonitorCollection; 00050 00051 struct DiskUsageStats 00052 { 00053 double absDiskUsage; // absolute disk usage in GB 00054 double relDiskUsage; // percentage of disk space occupied 00055 double diskSize; // absolute size of disk in GB 00056 std::string pathName; // path of the disk 00057 AlarmHandler::ALARM_LEVEL alarmState; // alarm level of the disk usage 00058 }; 00059 typedef boost::shared_ptr<DiskUsageStats> DiskUsageStatsPtr; 00060 typedef std::vector<DiskUsageStatsPtr> DiskUsageStatsPtrList; 00061 00062 struct Stats 00063 { 00064 DiskUsageStatsPtrList diskUsageStatsList; 00065 00066 int numberOfCopyWorkers; 00067 int numberOfInjectWorkers; 00068 int sataBeastStatus; // status code of SATA beast 00069 }; 00070 00071 00075 ResourceMonitorCollection 00076 ( 00077 const utils::Duration_t& updateInterval, 00078 AlarmHandlerPtr 00079 ); 00080 00084 void configureDisks(DiskWritingParams const&); 00085 00089 void configureResources(ResourceMonitorParams const&); 00090 00094 void configureAlarms(AlarmParams const&); 00095 00099 void getStats(Stats&) const; 00100 00101 00102 private: 00103 00104 struct DiskUsage 00105 { 00106 const std::string pathName_; 00107 double absDiskUsage_; 00108 double relDiskUsage_; 00109 double diskSize_; 00110 bool retrievingDiskSize_; 00111 AlarmHandler::ALARM_LEVEL alarmState_; 00112 #if __APPLE__ 00113 struct statfs statfs_; 00114 #else 00115 struct statfs64 statfs_; 00116 #endif 00117 int retVal_; 00118 DiskUsage(const std::string& pathName); 00119 std::string toString(); 00120 }; 00121 typedef boost::shared_ptr<DiskUsage> DiskUsagePtr; 00122 typedef std::vector<DiskUsagePtr> DiskUsagePtrList; 00123 DiskUsagePtrList diskUsageList_; 00124 mutable boost::mutex diskUsageListMutex_; 00125 00126 const utils::Duration_t updateInterval_; 00127 AlarmHandlerPtr alarmHandler_; 00128 00129 //Prevent copying of the ResourceMonitorCollection 00130 ResourceMonitorCollection(ResourceMonitorCollection const&); 00131 ResourceMonitorCollection& operator=(ResourceMonitorCollection const&); 00132 00133 virtual void do_calculateStatistics(); 00134 virtual void do_reset(); 00135 virtual void do_appendInfoSpaceItems(InfoSpaceItems&); 00136 virtual void do_updateInfoSpaceItems(); 00137 00138 void addDisk(const std::string&); 00139 void addOtherDisks(); 00140 bool isImportantDisk(const std::string&); 00141 void emitDiskAlarm(DiskUsagePtr); 00142 void emitDiskSpaceAlarm(DiskUsagePtr); 00143 void revokeDiskAlarm(DiskUsagePtr); 00144 00145 void getDiskStats(Stats&) const; 00146 void calcDiskUsage(); 00147 void retrieveDiskSize(DiskUsagePtr); 00148 void doStatFs(DiskUsagePtr); 00149 00150 void calcNumberOfCopyWorkers(); 00151 void calcNumberOfInjectWorkers(); 00152 void checkNumberOfCopyWorkers(); 00153 void checkNumberOfInjectWorkers(); 00154 int getProcessCount(const std::string& processName, const int& uid=-1); 00155 00156 typedef std::set<std::string> SATABeasts; 00157 void checkSataBeasts(); 00158 bool getSataBeasts(SATABeasts& sataBeasts); 00159 void checkSataBeast(const std::string& sataBeast); 00160 bool checkSataDisks(const std::string& sataBeast, const std::string& hostSuffix); 00161 void updateSataBeastStatus(const std::string& sataBeast, const std::string& content); 00162 00163 DiskWritingParams dwParams_; 00164 ResourceMonitorParams rmParams_; 00165 AlarmParams alarmParams_; 00166 00167 int numberOfCopyWorkers_; 00168 int numberOfInjectWorkers_; 00169 unsigned int nLogicalDisks_; 00170 int latchedSataBeastStatus_; 00171 00172 xdata::UnsignedInteger32 copyWorkers_; // number of running copyWorkers 00173 xdata::UnsignedInteger32 injectWorkers_; // number of running injectWorkers 00174 xdata::Integer32 sataBeastStatus_; // status code of SATA beast 00175 xdata::UnsignedInteger32 numberOfDisks_; // number of disks used for writing 00176 xdata::Vector<xdata::String> diskPaths_; // list of disk paths 00177 xdata::Vector<xdata::UnsignedInteger32> totalDiskSpace_; // total disk space 00178 xdata::Vector<xdata::UnsignedInteger32> usedDiskSpace_; // used disk space 00179 00180 }; 00181 00182 } // namespace stor 00183 00184 #endif // EventFilter_StorageManager_ResourceMonitorCollection_h 00185 00186