#include "host/hoststatus.h"
#include <iostream>
+#include <iomanip>
#include <logfunc.hpp>
#include "boost_assert_handler.h"
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: ";
}
ResolvedIpCount = resolved_ip_count;
- GlobalLogger.debug() << log_prefix() << "#IPs set";
+ log_status_count();
}
/**
{
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 );
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() )
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
{
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()
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;
- }
}
#include <boost/asio.hpp>
#include <boost/test/unit_test.hpp>
+#include <logfunc.hpp>
+
#include "mock_linkstatus.h"
#include "host/hoststatus.h"
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",
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 );
}
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",
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 );
}
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",
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 );
}