made limits in HostStatus floats; reduce logging
[pingcheck] / src / host / hoststatus.cpp
index b5613bd..3826712 100644 (file)
@@ -20,6 +20,7 @@ on this file might be covered by the GNU General Public License.
 #include "host/hoststatus.h"
 
 #include <iostream>
+#include <iomanip>
 #include <logfunc.hpp>
 
 #include "boost_assert_handler.h"
@@ -90,14 +91,37 @@ void HostStatus::set_n_parallel_pings(const int n_parallel_pings)
         NParallelPingers = n_parallel_pings;
         reset_ping_counters();
     }
-    GlobalLogger.debug() << log_prefix() << "#pingers set";
+
+    log_status_count();
+}
+
+void HostStatus::log_status_count()
+{
+    std::stringstream temp;
+    temp << "Stat(" << HostAddress << "): " << ResolvedIpCount << " IPs"
+        << "*" << NParallelPingers << " (burst=" << InBurstMode << "); "
+        << PingsPerformedCount << " pings; ";
+    temp << std::fixed << std::setprecision(2);
+    float limit = static_cast<float>( PingsPerformedCount
+                                    * PingFailLimitPercentage) / 100.f;
+    temp << PingsFailedCount << " fail (limit " << limit << "), ";
+    limit = static_cast<float>( PingsPerformedCount
+                                    * PingCongestionLimitPercentage) / 100.f;
+    float limitC = static_cast<float>( PingsPerformedCount
+                                    * CongestCausedByFailLimitPercentage)/100.f;
+    temp << PingCongestionCount << " congest (limits " << limit << ","
+        << limitC << ")";
+    GlobalLogger.info() << temp.str();
 }
 
 
 std::string HostStatus::log_prefix()
 {
     std::stringstream temp;
-    temp << "Stat(" << HostAddress << "): "
+    temp << "Stat(" << HostAddress;
+    if (InBurstMode)
+        temp << "!";
+    temp << "): "
         << PingsFailedCount << " fail," << PingCongestionCount << " cong/"
         << PingsPerformedCount << " pings/" << NParallelPingers << "*"
         << ResolvedIpCount << " IPs: ";
@@ -117,7 +141,7 @@ void HostStatus::set_resolved_ip_count( const int resolved_ip_count )
     }
     ResolvedIpCount = resolved_ip_count;
 
-    GlobalLogger.debug() << log_prefix() << "#IPs set";
+    log_status_count();
 }
 
 /**
@@ -149,9 +173,6 @@ void HostStatus::update_ping_statistics( const PingStatus &result,
 {
     float ping_duration_ms = static_cast<float>(ping_duration_us) / 1000.0f;
 
-    GlobalLogger.debug() << log_prefix() << "add ping with result "
-        << to_string(result) << " which took " << ping_duration_ms << " ms";
-
     BOOST_ASSERT( 0 <= ResolvedIpCount );
     BOOST_ASSERT( 0 <= PingsPerformedCount );
     BOOST_ASSERT( PingsFailedCount <= PingsPerformedCount );
@@ -163,6 +184,8 @@ void HostStatus::update_ping_statistics( const PingStatus &result,
                                                              ping_duration_us );
     update_fail_stats( result, failed_because_congested );
 
+    log_status_count();
+
     // after we tried all IPs resolved for this host, we can analyze how many
     // failed
     if ( tried_all_resolved_ip() )
@@ -251,7 +274,7 @@ void HostStatus::analyze_ping_statistics()
     else if (exceeded_ping_congestion_limit() && !InBurstMode)
         // only notify up if will not try burst mode next
         // otherwise will continuously notify up and down if get timeouts
-        GlobalLogger.notice() << log_prefix() << "will not notify up because "
+        GlobalLogger.debug() << log_prefix() << "will not notify up because "
             << " will go into burst mode next";
     else
     {
@@ -297,21 +320,14 @@ void HostStatus::analyze_ping_failed_count()
     BOOST_ASSERT( ( 0 <= PingFailLimitPercentage ) && ( PingFailLimitPercentage <= 100 ) );
     BOOST_ASSERT( ( 0 <= PingsFailedCount ) && ( PingsFailedCount <= PingsPerformedCount ) );
 
-    int limit = ( PingsPerformedCount * PingFailLimitPercentage) / 100;
+    float limit = static_cast<float>( PingsPerformedCount
+                                    * PingFailLimitPercentage) / 100.f;
 
     // keep a boolean variable because the PingsFailedCount can be reseted
     if ( PingsFailedCount > limit )
-    {
         ExceededPingFailedLimit = true;
-
-        GlobalLogger.debug() << log_prefix() << "exceed fail limit=" << limit;
-    }
     else
-    {
         ExceededPingFailedLimit = false;
-
-        GlobalLogger.debug() << log_prefix() << "below fail limit=" << limit;
-    }
 }
 
 void HostStatus::analyze_ping_congestion_count()
@@ -321,21 +337,11 @@ void HostStatus::analyze_ping_congestion_count()
     BOOST_ASSERT( ( 0 <= PingCongestionCount )
                     && ( PingCongestionCount <= PingsPerformedCount ) );
 
-    int limit = ( PingsPerformedCount * PingCongestionLimitPercentage) / 100;
+    float limit = static_cast<float>( PingsPerformedCount
+                                    * PingCongestionLimitPercentage) / 100.f;
 
     // keep a boolean variable because the PingCongestionCount can be reseted
     if ( PingCongestionCount > limit )
-    {
         ExceededPingCongestionLimit = true;
-
-        GlobalLogger.debug() << log_prefix() << "exceed congestion limit="
-                             << limit;
-    }
     else
-    {
-        ExceededPingCongestionLimit = false;
-
-        GlobalLogger.debug() << log_prefix() << "below congestion limit="
-                             << limit;
-    }
 }