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()
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: "
#include <boost/shared_ptr.hpp>
#include "dns/dnsresolver.h"
+#include "ping/pinganalyzer.h"
//-----------------------------------------------------------------------------
// PingScheduler
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();
boost::posix_time::ptime TimeSentLastPing;
DnsResolver IpList;
const uint PingIntervalInSec;
+ PingAnalyzer Analyzer;
};