From dfbd29a7af183cfeb138cf1e6fbdb33ea21a64e1 Mon Sep 17 00:00:00 2001 From: benthompson15 Date: Thu, 8 Aug 2019 12:29:17 -0500 Subject: [PATCH] add Replicator KPIs --- src/Replicator.cpp | 19 ++++++++++++++++++- src/Replicator.h | 6 ++++++ src/main.cpp | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Replicator.cpp b/src/Replicator.cpp index b0f58a922..f6922874a 100644 --- a/src/Replicator.cpp +++ b/src/Replicator.cpp @@ -69,6 +69,7 @@ Replicator::Replicator() mpLogger->log(LOG_CRIT, "Failed to create %s, got: %s", msCachePath.c_str(), e.what()); throw e; } + repUserDataWritten = repHeaderDataWritten = replicatorObjectsCreated = replicatorJournalsCreated = 0; } Replicator::~Replicator() @@ -86,6 +87,16 @@ Replicator * Replicator::get() return rep; } +void Replicator::printKPIs() const +{ + cout << "Replicator" << endl; + cout << "\treplicatorUserDataWritten = " << repUserDataWritten << endl; + cout << "\treplicatorHeaderDataWritten = " << repHeaderDataWritten << endl; + + cout << "\treplicatorObjectsCreated = " << replicatorObjectsCreated << endl; + cout << "\treplicatorJournalsCreated = " << replicatorJournalsCreated << endl; +} + #define OPEN(name, mode) \ fd = ::open(name, mode, 0600); \ if (fd < 0) \ @@ -110,7 +121,8 @@ int Replicator::newObject(const boost::filesystem::path &filename, const uint8_t } count += err; } - + repUserDataWritten += count; + ++replicatorObjectsCreated; return count; } @@ -134,9 +146,11 @@ int Replicator::addJournalEntry(const boost::filesystem::path &filename, const u string header = (boost::format("{ \"version\" : \"%03i\", \"max_offset\" : \"%011u\" }") % version % thisEntryMaxOffset).str(); err = ::write(fd, header.c_str(), header.length() + 1); assert((uint) err == header.length() + 1); + repHeaderDataWritten += (header.length() + 1); if (err <= 0) return err; Cache::get()->newJournalEntry(firstDir, header.length() + 1); + ++replicatorJournalsCreated; } else { @@ -154,6 +168,7 @@ int Replicator::addJournalEntry(const boost::filesystem::path &filename, const u string header = (boost::format("{ \"version\" : \"%03i\", \"max_offset\" : \"%011u\" }") % version % thisEntryMaxOffset).str(); err = ::pwrite(fd, header.c_str(), header.length() + 1,0); assert((uint) err == header.length() + 1); + repHeaderDataWritten += (header.length() + 1); if (err <= 0) return err; } @@ -166,6 +181,7 @@ int Replicator::addJournalEntry(const boost::filesystem::path &filename, const u err = ::write(fd, offlen, JOURNAL_ENTRY_HEADER_SIZE); assert(err == JOURNAL_ENTRY_HEADER_SIZE); + repHeaderDataWritten += JOURNAL_ENTRY_HEADER_SIZE; if (err <= 0) return err; @@ -183,6 +199,7 @@ int Replicator::addJournalEntry(const boost::filesystem::path &filename, const u count += err; } + repUserDataWritten += count; return count; } diff --git a/src/Replicator.h b/src/Replicator.h index c568b13c1..bdca958f9 100644 --- a/src/Replicator.h +++ b/src/Replicator.h @@ -35,6 +35,8 @@ class Replicator int updateMetadata(const boost::filesystem::path &filename, MetadataFile &meta); + void printKPIs() const; + private: Replicator(); Config *mpConfig; @@ -42,6 +44,10 @@ class Replicator std::string msJournalPath; std::string msCachePath; //ThreadPool threadPool; + + size_t repUserDataWritten, repHeaderDataWritten; + size_t replicatorObjectsCreated, replicatorJournalsCreated; + }; } diff --git a/src/main.cpp b/src/main.cpp index ff3172a0a..989fdc1d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ void printKPIs(int sig) Cache::get()->printKPIs(); Synchronizer::get()->printKPIs(); CloudStorage::get()->printKPIs(); + Replicator::get()->printKPIs(); } void shutdownSM(int sig)