Browse Source

Add connected timestamp to connection status API.

release/3.x.x
Christian Kratky 5 years ago
parent
commit
396e0e1697
2 changed files with 7 additions and 2 deletions
  1. +5
    -2
      Source/MQTTnet/Server/MqttClientConnection.cs
  2. +2
    -0
      Source/MQTTnet/Server/Status/MqttClientStatus.cs

+ 5
- 2
Source/MQTTnet/Server/MqttClientConnection.cs View File

@@ -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<MqttClientDisconnectType> _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;



+ 2
- 0
Source/MQTTnet/Server/Status/MqttClientStatus.cs View File

@@ -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; }


Loading…
Cancel
Save