10 #include <sys/statvfs.h> 13 #include <boost/filesystem.hpp> 28 fDimService(server +
"/STATS",
"X:1;X:1;X:1;X:1",
29 "Statistics about size written" 30 "|FreeSpace[bytes]:Free space on disk" 31 "|Written[bytes]:Bytes written in total" 32 "|Rate[bytes]:Bytes written since last update" 33 "|Elapsed[ms]:Milliseconds elapsed since last update"),
35 fUpdateInterval(1000),
72 return vfs.f_bsize*vfs.f_bavail;
85 if (!stat(file.c_str(), &st))
89 if (errno == 0 || errno == 2)
93 str <<
"stat() failed for '" << file <<
"': " << strerror(errno) <<
" [errno=" << errno <<
"]";
107 namespace fs = boost::filesystem;
112 const fs::path fullPath = fs::system_complete(fs::path(path));
114 if (!fs::exists(fullPath))
117 if (!fs::is_directory(fullPath))
119 log.
Error(
"Path given for checking '" + path +
"' designate a file name. Please provide a path name only");
123 if (access(path.c_str(), R_OK|W_OK|X_OK) != 0)
125 log.
Error(
"Missing read, write or execute permissions on directory '" + path +
"'");
140 if (statvfs(folder.empty()?
".":folder.c_str(), &vfs))
142 fLog.
Error(
"statvfs() failed for '"+folder+
"'... ignoring it.");
157 uint64_t previousSize = 0;
163 boost::this_thread::interruption_point();
164 boost::this_thread::yield();
178 data.
timeElapsed = (cTime - previousTime).total_milliseconds();
181 previousTime = cTime;
240 if (!finite(duration))
242 fLog.
Error(
"Provided update interval is not a valid float... discarding.");
247 fLog.
Warn(
"Statistics update interval not modified. Supplied value already in use.");
256 str <<
"Statistics update interval is now " << duration <<
" seconds";
uint16_t fUpdateInterval
Current folder being watched for free space.
DimWriteStatistics(const std::string &serverName, MessageImp &log)
Constructor.
int Debug(const std::string &str)
The base implementation of a distributed messaging system.
Adds some functionality to boost::posix_time::ptime for our needs.
DimDescribedService fDimService
bool FileOpened(const std::string &fileName)
static bool DoesPathExist(std::string path, MessageImp &log)
void SetUpdateInterval(const int16_t millisec)
virtual int Write(const Time &time, const std::string &txt, int qos=kMessage)
int64_t GetFreeSpace()
Returns the free space on the disk of the folder being watched (fCurrentFolder)
~DimWriteStatistics()
Default destructor.
void setData(const void *ptr, size_t sz)
void UpdateService()
Main loop.
int Error(const std::string &str)
int Write(const Time &t, const std::string &txt, int qos)
Stats fStats
The data structure holding the stat data.
std::set< std::string > fOpenedFiles
Total base size of all opened files.
int Warn(const std::string &str)
int64_t GetFileSizeOnDisk(const std::string &file)
Returns the size on disk of a given file.
boost::thread fThread
The boost thread used to update the service.
bool SetCurrentFolder(const std::string &folder)
Configures that current folder where files are written to.
std::string fCurrentFolder
bool fDebug
List of all opened files. set is used to easily check for entries.
int Message(const std::string &str)
size_t fBaseSize
Duration, in millisecond between two service updates. 0 means no more updates.