From c42b325d546304480a022db31cedcba39e0cc9f5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 17 Jan 2018 05:00:09 +0100 Subject: [PATCH] Watchdog allows to obtain info string about the statistics --- src/blackcore/application.cpp | 4 ++++ src/blackcore/db/networkwatchdog.cpp | 14 +++++++++++++- src/blackcore/db/networkwatchdog.h | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index b712cba03..d747e94d7 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -1056,6 +1056,10 @@ namespace BlackCore else { CLogMessage(this).warning("swift DB not accessible"); + if (m_networkWatchDog) + { + CLogMessage(this).warning(m_networkWatchDog->getCheckInfo()); + } } } diff --git a/src/blackcore/db/networkwatchdog.cpp b/src/blackcore/db/networkwatchdog.cpp index 0d58db2f9..2bd469ff2 100644 --- a/src/blackcore/db/networkwatchdog.cpp +++ b/src/blackcore/db/networkwatchdog.cpp @@ -42,7 +42,7 @@ namespace BlackCore { m_dbAccessible = accessible; m_internetAccessible = m_internetAccessible && m_networkAccessible; - QTimer::singleShot(0, &m_updateTimer, [this] { m_updateTimer.start(); }); // restart + QTimer::singleShot(0, &m_updateTimer, [this] { m_updateTimer.start(); }); // restart timer } bool CNetworkWatchdog::hasWorkingSharedUrl() const @@ -68,6 +68,14 @@ namespace BlackCore return n; // triggered } + QString CNetworkWatchdog::getCheckInfo() const + { + static const QString info("Internet accessible: %1 (good: %2/ bad: %3), swift DB accessible: %4 (good: %5/bad: %6)"); + return info. + arg(boolToYesNo(this->isInternetAccessible())).arg(m_goodCountInternet).arg(m_badCountInternet). + arg(boolToYesNo(this->isSwiftDbAccessible())).arg(m_goodCountDb).arg(m_badCountDb); + } + void CNetworkWatchdog::setWorkingSharedUrl(const CUrl &workingUrl) { QWriteLocker l(&m_lockSharedUrl); @@ -153,6 +161,8 @@ namespace BlackCore static const QString testHost2("www.microsoft.com"); // secondary test canConnectInternet = CNetworkUtils::canConnect(testHost2, 80, message); // running in background worker } + if (canConnectInternet) { m_goodCountInternet++; } + else { m_badCountInternet++; } } m_internetAccessible = networkAccess && canConnectInternet; @@ -224,6 +234,8 @@ namespace BlackCore nw->close(); if (!sApp || sApp->isShuttingDown()) { return; } m_lastClientPingSuccess = ok; + if (ok) { m_goodCountDb++; } + else { m_badCountDb++; } this->setDbAccessibility(ok); } diff --git a/src/blackcore/db/networkwatchdog.h b/src/blackcore/db/networkwatchdog.h index 88b9835f7..d972b3971 100644 --- a/src/blackcore/db/networkwatchdog.h +++ b/src/blackcore/db/networkwatchdog.h @@ -76,8 +76,13 @@ namespace BlackCore int triggerCheck(); //! Number of completed checks + //! \threadsafe int getCheckCount() const { return m_checkCount; } + //! Number of completed checks + //! \threadsafe + QString getCheckInfo() const; + //! Set working URL from external //! \threadsafe void setWorkingSharedUrl(const BlackMisc::Network::CUrl &workingUrl); @@ -150,6 +155,10 @@ namespace BlackCore std::atomic_bool m_checkSharedUrl { true }; std::atomic_bool m_checkInProgress { false }; //!< a check is currently in progress std::atomic_int m_checkCount { 0 }; //!< counting number of checks + std::atomic_int m_badCountDb { 0 }; //! Total number of DB failing counts (only real responses when tried) + std::atomic_int m_badCountInternet { 0 }; //! Total number of Internet failing count (only when network is accessible) + std::atomic_int m_goodCountDb { 0 }; + std::atomic_int m_goodCountInternet { 0 }; BlackMisc::Network::CUrl m_workingSharedUrl; mutable QReadWriteLock m_lockSharedUrl; };