d83134f7ffd0268eaddbd6d511ca4b7a22ec0949
[pingcheck] / src / host / hoststatus.h
1 /*
2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
4
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
7
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
13
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
16
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
19 */
20 #ifndef HOST_STATUS_H
21 #define HOST_STATUS_H
22
23 #include <string>
24
25 #include "host/pingstatus.h"
26 #include "link/linkstatus.h"
27
28 //-----------------------------------------------------------------------------
29 // HostStatus
30 //-----------------------------------------------------------------------------
31
32 /**
33  * @brief This class analyze the host status (up or down) based on the pings
34  * responses (success or failure). And notifies its status.
35  * Scope: one object per host.
36  */
37 class HostStatus
38 {
39 public:
40     HostStatus(
41             const std::string &host_address,
42             const int ping_fail_limit_percentage,
43             const int ping_congestion_limit_percentage,
44             const int congest_caused_by_fail_limit_percentage,
45             const int ping_duration_congestion_thresh,
46             const int n_parallel_pings,
47             const LinkStatusItem link_analyzer
48     );
49     ~HostStatus();
50
51     void set_resolved_ip_count( const int resolved_ip_count );
52     bool exceeded_ping_failed_limit() const;
53     bool exceeded_ping_congestion_limit() const;
54     void update_ping_statistics( const PingStatus &ping_success,
55                                  const long ping_duration_us );
56     void set_n_parallel_pings(const int n_parallel_pings);
57
58 private:
59     void update_fail_stats( const PingStatus &ping_success,
60                             const bool failed_because_congested );
61     bool update_congestion_stats( const PingStatus &ping_success,
62                                   const long ping_duration_us );
63     bool tried_all_resolved_ip() const;
64     void analyze_ping_statistics();
65     void reset_ping_counters();
66     void increase_ping_performed_count();
67     void increase_ping_failed_count();
68     void increase_ping_congestion_count();
69     void analyze_ping_failed_count();
70     void analyze_ping_congestion_count();
71
72     std::string log_prefix();
73
74 private:
75     /// the DNS address of the host to analyze
76     std::string HostAddress;
77     /// the object responsible to analyze the link
78     const LinkStatusItem LinkAnalyzer;
79     /// the maximum amount of pings that can fail without warning
80     int PingFailLimitPercentage;
81     /// the maximum amount of pings that can be congested without warning
82     int PingCongestionLimitPercentage;
83     /// threshold to decide when congestion is caused by failed connection
84     int CongestCausedByFailLimitPercentage;
85     /// the threshold in micro seconds that ping can take with/out congestion
86     long PingDurationCongestionsThresh;
87     /// the amount of IPs that are aliases to the host DNS
88     int ResolvedIpCount;
89     /// the amount of pings sent until now
90     int PingsPerformedCount;
91     /// the amount of pings sent that failed until now
92     int PingsFailedCount;
93     /// the amount of pings sent that indicate congestion until now
94     int PingCongestionCount;
95     /// boolean flag that indicate if the last set of failed pings exceed the
96     /// limit
97     bool ExceededPingFailedLimit;
98     /// boolean flag that indicate if the last set of congested pings exceed the
99     /// limit
100     bool ExceededPingCongestionLimit;
101     /// number of pingers that ping the same IP in parallel
102     int NParallelPingers;
103     /// flag whether we performed a greater number of pings because line seems
104     /// congested
105     bool InBurstMode;
106
107 };
108
109 #endif // HOST_STATUS_H