Commit c9a76aee authored by Cedric Caffy's avatar Cedric Caffy
Browse files

Added update time variable to the Statistics C++ object

parent 63c2ce95
......@@ -93,14 +93,13 @@ void DatabaseStatisticsService::updateStatisticsPerTape(){
}
void DatabaseStatisticsService::saveStatistics(const cta::statistics::Statistics& statistics) {
//First we save the general FILE statistics, then we go for the per-vo statistics
//First we save the general FILE statistics, then we go for the per-vo statisticss
saveFileStatistics(statistics);
saveStatisticsPerVo(statistics);
}
void DatabaseStatisticsService::saveFileStatistics(const cta::statistics::Statistics& statistics) {
try {
const time_t now = time(nullptr);
const char * const sql =
"INSERT INTO "
"FILE_STATISTICS "
......@@ -130,7 +129,7 @@ void DatabaseStatisticsService::saveFileStatistics(const cta::statistics::Statis
stmt.bindUint64(":NB_COPY_NB_1_IN_BYTES",statistics.getTotalBytesCopyNb1());
stmt.bindUint64(":NB_COPY_NB_GT_1",statistics.getTotalFilesCopyNbGt1());
stmt.bindUint64(":NB_COPY_NB_GT_1_IN_BYTES",statistics.getTotalBytesCopyNbGt1());
stmt.bindUint64(":UPDATE_TIME",now);
stmt.bindUint64(":UPDATE_TIME",statistics.getUpdateTime());
stmt.executeNonQuery();
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
......@@ -140,7 +139,6 @@ void DatabaseStatisticsService::saveFileStatistics(const cta::statistics::Statis
void DatabaseStatisticsService::saveStatisticsPerVo(const cta::statistics::Statistics& statistics) {
try {
const time_t now = time(nullptr);
const char * const sql =
"INSERT INTO "
"VO_STATISTICS "
......@@ -175,7 +173,7 @@ void DatabaseStatisticsService::saveStatisticsPerVo(const cta::statistics::Stati
stmt.bindUint64(":NB_COPY_NB_1_IN_BYTES",voFileStatistics.copyNb1InBytes);
stmt.bindUint64(":NB_COPY_NB_GT_1",voFileStatistics.nbCopyNbGt1);
stmt.bindUint64(":NB_COPY_NB_GT_1_IN_BYTES",voFileStatistics.copyNbGt1InBytes);
stmt.bindUint64(":UPDATE_TIME",now);
stmt.bindUint64(":UPDATE_TIME",statistics.getUpdateTime());
stmt.executeNonQuery();
}
} catch(exception::Exception &ex) {
......
......@@ -35,6 +35,7 @@ Statistics::Statistics(const Statistics& other) {
m_totalBytesCopyNb1 = other.m_totalBytesCopyNb1;
m_totalFilesCopyNbGt1 = other.m_totalFilesCopyNbGt1;
m_totalBytesCopyNbGt1 = other.m_totalBytesCopyNbGt1;
m_updateTime = other.m_updateTime;
}
}
......@@ -47,6 +48,7 @@ Statistics& Statistics::operator=(const Statistics& other) {
m_totalBytesCopyNb1 = other.m_totalBytesCopyNb1;
m_totalFilesCopyNbGt1 = other.m_totalFilesCopyNbGt1;
m_totalBytesCopyNbGt1 = other.m_totalBytesCopyNbGt1;
m_updateTime = other.m_updateTime;
}
return *this;
}
......@@ -89,6 +91,10 @@ uint64_t Statistics::getTotalBytesCopyNbGt1() const {
return m_totalBytesCopyNbGt1;
}
time_t Statistics::getUpdateTime() const {
return m_updateTime;
}
Statistics::Builder::Builder() {}
std::unique_ptr<Statistics> Statistics::Builder::build(cta::rdbms::Rset & rset){
......@@ -106,6 +112,8 @@ std::unique_ptr<Statistics> Statistics::Builder::build(cta::rdbms::Rset & rset){
//insert the perVO file statistics
ret->insertPerVOStatistics(vo,fileStatistics);
}
//Set the statistics update time to now
ret->m_updateTime = time(nullptr);
return ret;
}
......@@ -135,7 +143,8 @@ std::ostream & operator <<(std::ostream& stream, Statistics stats) {
<< "\"totalFilesCopyNb1\": " << stats.getTotalFilesCopyNb1() << ","
<< "\"totalBytesCopyNb1\": " << stats.getTotalBytesCopyNb1() << ","
<< "\"totalFilesCopyNbGt1\": " << stats.getTotalFilesCopyNbGt1() << ","
<< "\"totalBytesCopyNbGt1\": " << stats.getTotalBytesCopyNbGt1()
<< "\"totalBytesCopyNbGt1\": " << stats.getTotalBytesCopyNbGt1() << ","
<< "\"updateTime\": " << stats.getUpdateTime()
<< "}";
return stream;
}
......
......@@ -86,6 +86,12 @@ public:
*/
uint64_t getTotalBytesCopyNbGt1() const;
/**
* Returns the time when the statistics were updated
* @return the time when the statistics were updated
*/
time_t getUpdateTime() const;
/**
* This builder class allows to build the statistics
*/
......@@ -141,6 +147,11 @@ private:
* Total of space used by the MASTER files that are copyNb greater than 1 in CTA
*/
uint64_t m_totalBytesCopyNbGt1 = 0;
/**
* The time when the statistics will be saved
*/
time_t m_updateTime = 0;
};
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment