0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 04:02:15 +02:00

"last packet received n seconds ago" stat is now provided by core.

This commit is contained in:
James Yonan 2012-09-05 22:03:26 +00:00
parent 8b7b797ef5
commit f31040f059
4 changed files with 59 additions and 30 deletions

View File

@ -562,21 +562,21 @@ namespace openvpn {
// data. Vice versa for TUN_*_IN.
if (stats)
{
ret.bytes_out = stats->stat_count(SessionStats::TUN_BYTES_IN);
ret.bytes_in = stats->stat_count(SessionStats::TUN_BYTES_OUT);
ret.packets_out = stats->stat_count(SessionStats::TUN_PACKETS_IN);
ret.packets_in = stats->stat_count(SessionStats::TUN_PACKETS_OUT);
ret.errors_out = stats->error_count(Error::TUN_READ_ERROR);
ret.errors_in = stats->error_count(Error::TUN_WRITE_ERROR);
ret.bytesOut = stats->stat_count(SessionStats::TUN_BYTES_IN);
ret.bytesIn = stats->stat_count(SessionStats::TUN_BYTES_OUT);
ret.packetsOut = stats->stat_count(SessionStats::TUN_PACKETS_IN);
ret.packetsIn = stats->stat_count(SessionStats::TUN_PACKETS_OUT);
ret.errorsOut = stats->error_count(Error::TUN_READ_ERROR);
ret.errorsIn = stats->error_count(Error::TUN_WRITE_ERROR);
}
else
{
ret.bytes_out = 0;
ret.bytes_in = 0;
ret.packets_out = 0;
ret.packets_in = 0;
ret.errors_out = 0;
ret.errors_in = 0;
ret.bytesOut = 0;
ret.bytesIn = 0;
ret.packetsOut = 0;
ret.packetsIn = 0;
ret.errorsOut = 0;
ret.errorsIn = 0;
}
return ret;
}
@ -586,19 +586,32 @@ namespace openvpn {
MySessionStats::Ptr stats = state->stats;
TransportStats ret;
ret.lastPacketReceived = -1; // undefined
if (stats)
{
ret.bytes_out = stats->stat_count(SessionStats::BYTES_OUT);
ret.bytes_in = stats->stat_count(SessionStats::BYTES_IN);
ret.packets_out = stats->stat_count(SessionStats::PACKETS_OUT);
ret.packets_in = stats->stat_count(SessionStats::PACKETS_IN);
ret.bytesOut = stats->stat_count(SessionStats::BYTES_OUT);
ret.bytesIn = stats->stat_count(SessionStats::BYTES_IN);
ret.packetsOut = stats->stat_count(SessionStats::PACKETS_OUT);
ret.packetsIn = stats->stat_count(SessionStats::PACKETS_IN);
// calculate time since last packet received
{
const Time& lpr = stats->last_packet_received();
if (lpr.defined())
{
const Time::Duration dur = Time::now() - lpr;
const unsigned int delta = dur.to_binary_ms();
if (delta <= 60*60*24*1024) // only define for time periods <= 1 day
ret.lastPacketReceived = delta;
}
}
}
else
{
ret.bytes_out = 0;
ret.bytes_in = 0;
ret.packets_out = 0;
ret.packets_in = 0;
ret.bytesOut = 0;
ret.bytesIn = 0;
ret.packetsOut = 0;
ret.packetsIn = 0;
}
return ret;
}

View File

@ -176,21 +176,25 @@ namespace openvpn {
// used to pass stats for an interface
struct InterfaceStats
{
long long bytes_in;
long long packets_in;
long long errors_in;
long long bytes_out;
long long packets_out;
long long errors_out;
long long bytesIn;
long long packetsIn;
long long errorsIn;
long long bytesOut;
long long packetsOut;
long long errorsOut;
};
// used to pass basic transport stats
struct TransportStats
{
long long bytes_in;
long long bytes_out;
long long packets_in;
long long packets_out;
long long bytesIn;
long long bytesOut;
long long packetsIn;
long long packetsOut;
// number of binary milliseconds (1/1024th of a second) since
// last packet was received, or -1 if undefined
int lastPacketReceived;
};
// base class for External PKI queries

View File

@ -49,6 +49,7 @@ namespace openvpn {
typedef typename Base::PacketType PacketType;
using Base::now;
using Base::stat;
public:
typedef boost::intrusive_ptr<Session> Ptr;
@ -175,6 +176,9 @@ namespace openvpn {
// update current time
Base::update_now();
// update last packet received
stat().update_last_packet_received(now());
// log connecting event (only on first packet received)
if (!first_packet_received_)
{

View File

@ -79,7 +79,15 @@ namespace openvpn {
return "UNKNOWN_STAT_TYPE";
}
void update_last_packet_received(const Time& now)
{
last_packet_received_ = now;
}
const Time& last_packet_received() const { return last_packet_received_; }
private:
Time last_packet_received_;
count_t stats_[N_STATS];
};