made limits in HostStatus floats; reduce logging
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 28 May 2015 12:47:15 +0000 (14:47 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 28 May 2015 12:47:15 +0000 (14:47 +0200)
src/host/hoststatus.cpp
src/host/hoststatus.h
test/test_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;
-    }
 }
index d83134f..a236edc 100644 (file)
@@ -68,6 +68,7 @@ private:
     void increase_ping_congestion_count();
     void analyze_ping_failed_count();
     void analyze_ping_congestion_count();
+    void log_status_count();
 
     std::string log_prefix();
 
index 1b46612..607daa1 100644 (file)
@@ -26,6 +26,8 @@ on this file might be covered by the GNU General Public License.
 #include <boost/asio.hpp>
 #include <boost/test/unit_test.hpp>
 
+#include <logfunc.hpp>
+
 #include "mock_linkstatus.h"
 
 #include "host/hoststatus.h"
@@ -35,12 +37,17 @@ BOOST_AUTO_TEST_SUITE( TestHostStatus )
 
 BOOST_AUTO_TEST_CASE( fail_percentage_10 )
 {
+    I2n::Logger::enable_stderr_log( true );
+    I2n::Logger::set_log_level( I2n::Logger::LogLevel::Debug );
+    I2n::Logger::GlobalLogger.info() << "Logging enabled for testing";
+
     int ping_fail_percentage_limit = 10;
     int ping_congestion_percentage_limit = 75;
     int congest_caused_by_fail_percentage_limit = 90;
     int ping_congestion_duration_thresh = 5;
     int n_parallel_pings = 1;
     int resolved_ip_count = 10;
+    long duration = 1000;   // microseconds
 
     LinkStatusItem link_status( new LinkStatus );
     HostStatus host_status( "localhost",
@@ -52,34 +59,34 @@ BOOST_AUTO_TEST_CASE( fail_percentage_10 )
                             link_status );
     host_status.set_resolved_ip_count( resolved_ip_count );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1);
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration);
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 }
 
@@ -91,6 +98,7 @@ BOOST_AUTO_TEST_CASE( fail_percentage_50 )
     int ping_congestion_duration_thresh = 5;
     int n_parallel_pings = 1;
     int resolved_ip_count = 10;
+    long duration = 1000;   // microseconds
 
     LinkStatusItem link_status( new LinkStatus );
     HostStatus host_status( "localhost",
@@ -102,34 +110,34 @@ BOOST_AUTO_TEST_CASE( fail_percentage_50 )
                             link_status );
     host_status.set_resolved_ip_count( resolved_ip_count );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 }
 
@@ -141,6 +149,7 @@ BOOST_AUTO_TEST_CASE( fail_percentage_80 )
     int ping_congestion_duration_thresh = 5;
     int n_parallel_pings = 1;
     int resolved_ip_count = 10;
+    long duration = 1000;   // microseconds
 
     LinkStatusItem link_status( new LinkStatus );
     HostStatus host_status( "localhost",
@@ -152,34 +161,34 @@ BOOST_AUTO_TEST_CASE( fail_percentage_80 )
                             link_status );
     host_status.set_resolved_ip_count( resolved_ip_count );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
 
-    host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
+    host_status.update_ping_statistics( PingStatus_FailureOther, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 
-    host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
+    host_status.update_ping_statistics( PingStatus_SuccessReply, duration );
     BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
 }