From e4351b73bd04bf960862949ce1881d459cd6144a Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 19 May 2019 22:23:10 +0200 Subject: [PATCH] Add connected timestamp to connection status API. --- Source/MQTTnet/Server/MqttClientConnection.cs | 7 +++++-- Source/MQTTnet/Server/Status/MqttClientStatus.cs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet/Server/MqttClientConnection.cs b/Source/MQTTnet/Server/MqttClientConnection.cs index d88d973..6cc4bc5 100644 --- a/Source/MQTTnet/Server/MqttClientConnection.cs +++ b/Source/MQTTnet/Server/MqttClientConnection.cs @@ -31,11 +31,12 @@ namespace MQTTnet.Server private readonly IMqttDataConverter _dataConverter; private readonly string _endpoint; private readonly MqttConnectPacket _connectPacket; + private readonly DateTime _connectedTimestamp; private Task _packageReceiverTask; private DateTime _lastPacketReceivedTimestamp; private DateTime _lastNonKeepAlivePacketReceivedTimestamp; - + private long _receivedPacketsCount; private long _sentPacketsCount = 1; // Start with 1 because the CONNECT packet is not counted anywhere. private long _receivedApplicationMessagesCount; @@ -65,7 +66,8 @@ namespace MQTTnet.Server _keepAliveMonitor = new MqttClientKeepAliveMonitor(this, _logger); - _lastPacketReceivedTimestamp = DateTime.UtcNow; + _connectedTimestamp = DateTime.UtcNow; + _lastPacketReceivedTimestamp = _connectedTimestamp; _lastNonKeepAlivePacketReceivedTimestamp = _lastPacketReceivedTimestamp; } @@ -96,6 +98,7 @@ namespace MQTTnet.Server status.ReceivedPacketsCount = Interlocked.Read(ref _receivedPacketsCount); status.SentPacketsCount = Interlocked.Read(ref _sentPacketsCount); + status.ConnectedTimestamp = _connectedTimestamp; status.LastPacketReceivedTimestamp = _lastPacketReceivedTimestamp; status.LastNonKeepAlivePacketReceivedTimestamp = _lastNonKeepAlivePacketReceivedTimestamp; diff --git a/Source/MQTTnet/Server/Status/MqttClientStatus.cs b/Source/MQTTnet/Server/Status/MqttClientStatus.cs index cc6e77d..05cd202 100644 --- a/Source/MQTTnet/Server/Status/MqttClientStatus.cs +++ b/Source/MQTTnet/Server/Status/MqttClientStatus.cs @@ -21,6 +21,8 @@ namespace MQTTnet.Server.Status public DateTime LastPacketReceivedTimestamp { get; set; } + public DateTime ConnectedTimestamp { get; set; } + public DateTime LastNonKeepAlivePacketReceivedTimestamp { get; set; } public long ReceivedApplicationMessagesCount { get; set; }