浏览代码

Add connected timestamp to connection status API.

release/3.x.x
Christian Kratky 5 年前
父节点
当前提交
396e0e1697
共有 2 个文件被更改,包括 7 次插入2 次删除
  1. +5
    -2
      Source/MQTTnet/Server/MqttClientConnection.cs
  2. +2
    -0
      Source/MQTTnet/Server/Status/MqttClientStatus.cs

+ 5
- 2
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<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 查看文件

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


正在加载...
取消
保存