mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-26 03:17:55 +00:00
StatsManager: updated implementation to handle rate limited dropped stats separately from other drop cases.
This commit is contained in:
@@ -142,7 +142,7 @@ namespace DnsServerCore.Dns
|
|||||||
else
|
else
|
||||||
responseType = (DnsServerResponseType)item._response.Tag;
|
responseType = (DnsServerResponseType)item._response.Tag;
|
||||||
|
|
||||||
statCounter.Update(query, item._response is null ? DnsResponseCode.NoError : item._response.RCODE, responseType, item._remoteEP.Address, item._protocol);
|
statCounter.Update(query, item._response is null ? DnsResponseCode.NoError : item._response.RCODE, responseType, item._remoteEP.Address, item._protocol, item._rateLimited);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((item._request is null) || (item._response is null))
|
if ((item._request is null) || (item._response is null))
|
||||||
@@ -584,9 +584,9 @@ namespace DnsServerCore.Dns
|
|||||||
Flush();
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueueUpdate(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response)
|
public void QueueUpdate(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response, bool rateLimited)
|
||||||
{
|
{
|
||||||
_queue.Add(new StatsQueueItem(request, remoteEP, protocol, response));
|
_queue.Add(new StatsQueueItem(request, remoteEP, protocol, response, rateLimited));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, List<KeyValuePair<string, long>>> GetLastHourMinuteWiseStats(bool utcFormat)
|
public Dictionary<string, List<KeyValuePair<string, long>>> GetLastHourMinuteWiseStats(bool utcFormat)
|
||||||
@@ -1618,7 +1618,7 @@ namespace DnsServerCore.Dns
|
|||||||
_locked = true;
|
_locked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(DnsQuestionRecord query, DnsResponseCode responseCode, DnsServerResponseType responseType, IPAddress clientIpAddress, DnsTransportProtocol protocol)
|
public void Update(DnsQuestionRecord query, DnsResponseCode responseCode, DnsServerResponseType responseType, IPAddress clientIpAddress, DnsTransportProtocol protocol, bool rateLimited)
|
||||||
{
|
{
|
||||||
if (_locked)
|
if (_locked)
|
||||||
return;
|
return;
|
||||||
@@ -1631,6 +1631,12 @@ namespace DnsServerCore.Dns
|
|||||||
if (responseType == DnsServerResponseType.Dropped)
|
if (responseType == DnsServerResponseType.Dropped)
|
||||||
{
|
{
|
||||||
_totalDropped++;
|
_totalDropped++;
|
||||||
|
|
||||||
|
if (rateLimited)
|
||||||
|
{
|
||||||
|
_clientIpAddresses.GetOrAdd(clientIpAddress, GetNewCounter).Increment();
|
||||||
|
_totalClients = _clientIpAddresses.Count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1648,7 +1654,7 @@ namespace DnsServerCore.Dns
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_queryDomains.GetOrAdd(query.Name.ToLower(), GetNewCounter).Increment();
|
_queryDomains.GetOrAdd(query.Name.ToLowerInvariant(), GetNewCounter).Increment();
|
||||||
_queries.GetOrAdd(query, GetNewCounter).Increment();
|
_queries.GetOrAdd(query, GetNewCounter).Increment();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1692,7 +1698,7 @@ namespace DnsServerCore.Dns
|
|||||||
|
|
||||||
case DnsServerResponseType.Blocked:
|
case DnsServerResponseType.Blocked:
|
||||||
if (query is not null)
|
if (query is not null)
|
||||||
_queryBlockedDomains.GetOrAdd(query.Name.ToLower(), GetNewCounter).Increment();
|
_queryBlockedDomains.GetOrAdd(query.Name.ToLowerInvariant(), GetNewCounter).Increment();
|
||||||
|
|
||||||
_totalBlocked++;
|
_totalBlocked++;
|
||||||
break;
|
break;
|
||||||
@@ -1701,7 +1707,7 @@ namespace DnsServerCore.Dns
|
|||||||
_totalRecursive++;
|
_totalRecursive++;
|
||||||
|
|
||||||
if (query is not null)
|
if (query is not null)
|
||||||
_queryBlockedDomains.GetOrAdd(query.Name.ToLower(), GetNewCounter).Increment();
|
_queryBlockedDomains.GetOrAdd(query.Name.ToLowerInvariant(), GetNewCounter).Increment();
|
||||||
|
|
||||||
_totalBlocked++;
|
_totalBlocked++;
|
||||||
break;
|
break;
|
||||||
@@ -1710,7 +1716,7 @@ namespace DnsServerCore.Dns
|
|||||||
_totalCached++;
|
_totalCached++;
|
||||||
|
|
||||||
if (query is not null)
|
if (query is not null)
|
||||||
_queryBlockedDomains.GetOrAdd(query.Name.ToLower(), GetNewCounter).Increment();
|
_queryBlockedDomains.GetOrAdd(query.Name.ToLowerInvariant(), GetNewCounter).Increment();
|
||||||
|
|
||||||
_totalBlocked++;
|
_totalBlocked++;
|
||||||
break;
|
break;
|
||||||
@@ -1718,14 +1724,14 @@ namespace DnsServerCore.Dns
|
|||||||
|
|
||||||
if (query is not null)
|
if (query is not null)
|
||||||
_queryTypes.GetOrAdd(query.Type, GetNewCounter).Increment();
|
_queryTypes.GetOrAdd(query.Type, GetNewCounter).Increment();
|
||||||
}
|
|
||||||
|
|
||||||
_protocolTypes.GetOrAdd(protocol, GetNewCounter).Increment();
|
|
||||||
|
|
||||||
_clientIpAddresses.GetOrAdd(clientIpAddress, GetNewCounter).Increment();
|
_clientIpAddresses.GetOrAdd(clientIpAddress, GetNewCounter).Increment();
|
||||||
_totalClients = _clientIpAddresses.Count;
|
_totalClients = _clientIpAddresses.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_protocolTypes.GetOrAdd(protocol, GetNewCounter).Increment();
|
||||||
|
}
|
||||||
|
|
||||||
public void Merge(StatCounter statCounter, bool isDailyStatCounter = false, bool skipLock = false)
|
public void Merge(StatCounter statCounter, bool isDailyStatCounter = false, bool skipLock = false)
|
||||||
{
|
{
|
||||||
if (!skipLock && (!_locked || !statCounter._locked))
|
if (!skipLock && (!_locked || !statCounter._locked))
|
||||||
@@ -2229,12 +2235,13 @@ namespace DnsServerCore.Dns
|
|||||||
public readonly IPEndPoint _remoteEP;
|
public readonly IPEndPoint _remoteEP;
|
||||||
public readonly DnsTransportProtocol _protocol;
|
public readonly DnsTransportProtocol _protocol;
|
||||||
public readonly DnsDatagram _response;
|
public readonly DnsDatagram _response;
|
||||||
|
public readonly bool _rateLimited;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region constructor
|
#region constructor
|
||||||
|
|
||||||
public StatsQueueItem(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response)
|
public StatsQueueItem(DnsDatagram request, IPEndPoint remoteEP, DnsTransportProtocol protocol, DnsDatagram response, bool rateLimited)
|
||||||
{
|
{
|
||||||
_timestamp = DateTime.UtcNow;
|
_timestamp = DateTime.UtcNow;
|
||||||
|
|
||||||
@@ -2242,6 +2249,7 @@ namespace DnsServerCore.Dns
|
|||||||
_remoteEP = remoteEP;
|
_remoteEP = remoteEP;
|
||||||
_protocol = protocol;
|
_protocol = protocol;
|
||||||
_response = response;
|
_response = response;
|
||||||
|
_rateLimited = rateLimited;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user