From 502b6af0315fa5e9cec504502705db15f783b82d Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Tue, 15 Mar 2011 11:55:50 +0100 Subject: [PATCH] Uses the ping analyzer to evaluate the ping statistics after each ping. --- src/ping/pingscheduler.cpp | 31 ++++++++++++++++++------------- src/ping/pingscheduler.h | 7 +++++-- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/ping/pingscheduler.cpp b/src/ping/pingscheduler.cpp index 86b2a44..d0956d8 100644 --- a/src/ping/pingscheduler.cpp +++ b/src/ping/pingscheduler.cpp @@ -25,8 +25,11 @@ PingScheduler::PingScheduler( Timer( io_service ), TimeSentLastPing( microsec_clock::universal_time() ), IpList( ping_address ), - PingIntervalInSec( ping_interval_in_sec ) + PingIntervalInSec( ping_interval_in_sec ), + Analyzer( ping_address, 50 ) // 50% max acceptable failure { + uint resolved_ip_count = IpList.get_resolved_ip_count(); + Analyzer.set_resolved_ip_count( resolved_ip_count ); } PingScheduler::~PingScheduler() @@ -35,32 +38,34 @@ PingScheduler::~PingScheduler() void PingScheduler::start_pinging() { - // try cyclic the hosts in the list - // if we get back to the front of the list, analyze the result - // if this X% fail is greater than the threshold, mark the host as down - // otherwise, the host is up - // advice the external system about the host situation - string destination_ip = IpList.get_next_ip(); - ping( destination_ip ); + bool ping_success = ping( destination_ip ); + + update_ping_statistics( ping_success ); + + update_ping_elapsed_time(); + + schedule_next_ping(); } -void PingScheduler::ping( const string &destination ) +bool PingScheduler::ping( const string &destination ) { BOOST_ASSERT( !destination.empty() ); io_service io_service; uint echo_reply_timeout_in_sec = 5; // TODO configurable: this is the timeout to WAIT FOR the ping before considering a timeout BoostPinger pinger( io_service, echo_reply_timeout_in_sec ); - pinger.ping( destination ); - update_ping_statistics(); + return pinger.ping( destination ); +} - schedule_next_ping(); +void PingScheduler::update_ping_statistics( const bool ping_success ) +{ + Analyzer.update_ping_statistics( ping_success ); } -void PingScheduler::update_ping_statistics() +void PingScheduler::update_ping_elapsed_time() { ptime now = microsec_clock::universal_time(); cerr << "- Time elapsed since last ping: " diff --git a/src/ping/pingscheduler.h b/src/ping/pingscheduler.h index c5ed595..e33b977 100644 --- a/src/ping/pingscheduler.h +++ b/src/ping/pingscheduler.h @@ -7,6 +7,7 @@ #include #include "dns/dnsresolver.h" +#include "ping/pinganalyzer.h" //----------------------------------------------------------------------------- // PingScheduler @@ -25,8 +26,9 @@ public: void start_pinging(); private: - void ping( const std::string &destination ); - void update_ping_statistics(); + bool ping( const std::string &destination ); + void update_ping_statistics( const bool ping_success ); + void update_ping_elapsed_time(); void schedule_next_ping(); void handle_next_ping(); @@ -36,6 +38,7 @@ private: boost::posix_time::ptime TimeSentLastPing; DnsResolver IpList; const uint PingIntervalInSec; + PingAnalyzer Analyzer; }; -- 1.7.1