diff --git a/DnsServerCore/Dns/StatsManager.cs b/DnsServerCore/Dns/StatsManager.cs index 349ca199..6a0b11a6 100644 --- a/DnsServerCore/Dns/StatsManager.cs +++ b/DnsServerCore/Dns/StatsManager.cs @@ -556,23 +556,23 @@ namespace DnsServerCore.Dns _queue.Add(new StatsQueueItem(request, remoteEP, protocol, response)); } - public Dictionary>> GetLastHourMinuteWiseStats() + public Dictionary>> GetLastHourMinuteWiseStats() { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); - List> totalQueriesPerInterval = new List>(60); - List> totalNoErrorPerInterval = new List>(60); - List> totalServerFailurePerInterval = new List>(60); - List> totalNxDomainPerInterval = new List>(60); - List> totalRefusedPerInterval = new List>(60); + List> totalQueriesPerInterval = new List>(60); + List> totalNoErrorPerInterval = new List>(60); + List> totalServerFailurePerInterval = new List>(60); + List> totalNxDomainPerInterval = new List>(60); + List> totalRefusedPerInterval = new List>(60); - List> totalAuthHitPerInterval = new List>(60); - List> totalRecursionsPerInterval = new List>(60); - List> totalCacheHitPerInterval = new List>(60); - List> totalBlockedPerInterval = new List>(60); + List> totalAuthHitPerInterval = new List>(60); + List> totalRecursionsPerInterval = new List>(60); + List> totalCacheHitPerInterval = new List>(60); + List> totalBlockedPerInterval = new List>(60); - List> totalClientsPerInterval = new List>(60); + List> totalClientsPerInterval = new List>(60); DateTime lastHourDateTime = DateTime.UtcNow.AddMinutes(-60); lastHourDateTime = new DateTime(lastHourDateTime.Year, lastHourDateTime.Month, lastHourDateTime.Day, lastHourDateTime.Hour, lastHourDateTime.Minute, 0, DateTimeKind.Utc); @@ -587,53 +587,53 @@ namespace DnsServerCore.Dns { totalStatCounter.Merge(statCounter); - totalQueriesPerInterval.Add(new KeyValuePair(label, statCounter.TotalQueries)); - totalNoErrorPerInterval.Add(new KeyValuePair(label, statCounter.TotalNoError)); - totalServerFailurePerInterval.Add(new KeyValuePair(label, statCounter.TotalServerFailure)); - totalNxDomainPerInterval.Add(new KeyValuePair(label, statCounter.TotalNxDomain)); - totalRefusedPerInterval.Add(new KeyValuePair(label, statCounter.TotalRefused)); + totalQueriesPerInterval.Add(new KeyValuePair(label, statCounter.TotalQueries)); + totalNoErrorPerInterval.Add(new KeyValuePair(label, statCounter.TotalNoError)); + totalServerFailurePerInterval.Add(new KeyValuePair(label, statCounter.TotalServerFailure)); + totalNxDomainPerInterval.Add(new KeyValuePair(label, statCounter.TotalNxDomain)); + totalRefusedPerInterval.Add(new KeyValuePair(label, statCounter.TotalRefused)); - totalAuthHitPerInterval.Add(new KeyValuePair(label, statCounter.TotalAuthoritative)); - totalRecursionsPerInterval.Add(new KeyValuePair(label, statCounter.TotalRecursive)); - totalCacheHitPerInterval.Add(new KeyValuePair(label, statCounter.TotalCached)); - totalBlockedPerInterval.Add(new KeyValuePair(label, statCounter.TotalBlocked)); + totalAuthHitPerInterval.Add(new KeyValuePair(label, statCounter.TotalAuthoritative)); + totalRecursionsPerInterval.Add(new KeyValuePair(label, statCounter.TotalRecursive)); + totalCacheHitPerInterval.Add(new KeyValuePair(label, statCounter.TotalCached)); + totalBlockedPerInterval.Add(new KeyValuePair(label, statCounter.TotalBlocked)); - totalClientsPerInterval.Add(new KeyValuePair(label, statCounter.TotalClients)); + totalClientsPerInterval.Add(new KeyValuePair(label, statCounter.TotalClients)); } else { - totalQueriesPerInterval.Add(new KeyValuePair(label, 0)); - totalNoErrorPerInterval.Add(new KeyValuePair(label, 0)); - totalServerFailurePerInterval.Add(new KeyValuePair(label, 0)); - totalNxDomainPerInterval.Add(new KeyValuePair(label, 0)); - totalRefusedPerInterval.Add(new KeyValuePair(label, 0)); + totalQueriesPerInterval.Add(new KeyValuePair(label, 0)); + totalNoErrorPerInterval.Add(new KeyValuePair(label, 0)); + totalServerFailurePerInterval.Add(new KeyValuePair(label, 0)); + totalNxDomainPerInterval.Add(new KeyValuePair(label, 0)); + totalRefusedPerInterval.Add(new KeyValuePair(label, 0)); - totalAuthHitPerInterval.Add(new KeyValuePair(label, 0)); - totalRecursionsPerInterval.Add(new KeyValuePair(label, 0)); - totalCacheHitPerInterval.Add(new KeyValuePair(label, 0)); - totalBlockedPerInterval.Add(new KeyValuePair(label, 0)); + totalAuthHitPerInterval.Add(new KeyValuePair(label, 0)); + totalRecursionsPerInterval.Add(new KeyValuePair(label, 0)); + totalCacheHitPerInterval.Add(new KeyValuePair(label, 0)); + totalBlockedPerInterval.Add(new KeyValuePair(label, 0)); - totalClientsPerInterval.Add(new KeyValuePair(label, 0)); + totalClientsPerInterval.Add(new KeyValuePair(label, 0)); } } - Dictionary>> data = new Dictionary>>(); + Dictionary>> data = new Dictionary>>(); { - List> stats = new List>(10); + List> stats = new List>(10); - stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); - stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); - stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); - stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); - stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); + stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); + stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); + stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); + stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); + stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); - stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); - stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); - stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); - stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); + stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); + stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); + stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); + stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); - stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); + stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); data.Add("stats", stats); } @@ -659,38 +659,38 @@ namespace DnsServerCore.Dns return data; } - public Dictionary>> GetLastDayHourWiseStats() + public Dictionary>> GetLastDayHourWiseStats() { return GetHourWiseStats(DateTime.UtcNow.AddHours(-24), 24); } - public Dictionary>> GetLastWeekDayWiseStats() + public Dictionary>> GetLastWeekDayWiseStats() { return GetDayWiseStats(DateTime.UtcNow.AddDays(-7).Date, 7); } - public Dictionary>> GetLastMonthDayWiseStats() + public Dictionary>> GetLastMonthDayWiseStats() { return GetDayWiseStats(DateTime.UtcNow.AddDays(-31).Date, 31); } - public Dictionary>> GetLastYearMonthWiseStats() + public Dictionary>> GetLastYearMonthWiseStats() { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); - List> totalQueriesPerInterval = new List>(); - List> totalNoErrorPerInterval = new List>(); - List> totalServerFailurePerInterval = new List>(); - List> totalNxDomainPerInterval = new List>(); - List> totalRefusedPerInterval = new List>(); + List> totalQueriesPerInterval = new List>(); + List> totalNoErrorPerInterval = new List>(); + List> totalServerFailurePerInterval = new List>(); + List> totalNxDomainPerInterval = new List>(); + List> totalRefusedPerInterval = new List>(); - List> totalAuthHitPerInterval = new List>(); - List> totalRecursionsPerInterval = new List>(); - List> totalCacheHitPerInterval = new List>(); - List> totalBlockedPerInterval = new List>(); + List> totalAuthHitPerInterval = new List>(); + List> totalRecursionsPerInterval = new List>(); + List> totalCacheHitPerInterval = new List>(); + List> totalBlockedPerInterval = new List>(); - List> totalClientsPerInterval = new List>(); + List> totalClientsPerInterval = new List>(); DateTime lastYearDateTime = DateTime.UtcNow.AddMonths(-12); lastYearDateTime = new DateTime(lastYearDateTime.Year, lastYearDateTime.Month, 1, 0, 0, 0, DateTimeKind.Utc); @@ -713,37 +713,37 @@ namespace DnsServerCore.Dns totalStatCounter.Merge(monthlyStatCounter, true); - totalQueriesPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalQueries)); - totalNoErrorPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalNoError)); - totalServerFailurePerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalServerFailure)); - totalNxDomainPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalNxDomain)); - totalRefusedPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalRefused)); + totalQueriesPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalQueries)); + totalNoErrorPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalNoError)); + totalServerFailurePerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalServerFailure)); + totalNxDomainPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalNxDomain)); + totalRefusedPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalRefused)); - totalAuthHitPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalAuthoritative)); - totalRecursionsPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalRecursive)); - totalCacheHitPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalCached)); - totalBlockedPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalBlocked)); + totalAuthHitPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalAuthoritative)); + totalRecursionsPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalRecursive)); + totalCacheHitPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalCached)); + totalBlockedPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalBlocked)); - totalClientsPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalClients)); + totalClientsPerInterval.Add(new KeyValuePair(label, monthlyStatCounter.TotalClients)); } - Dictionary>> data = new Dictionary>>(); + Dictionary>> data = new Dictionary>>(); { - List> stats = new List>(6); + List> stats = new List>(6); - stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); - stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); - stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); - stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); - stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); + stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); + stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); + stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); + stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); + stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); - stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); - stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); - stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); - stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); + stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); + stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); + stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); + stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); - stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); + stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); data.Add("stats", stats); } @@ -769,7 +769,7 @@ namespace DnsServerCore.Dns return data; } - public Dictionary>> GetHourWiseStats(DateTime startDate, DateTime endDate) + public Dictionary>> GetHourWiseStats(DateTime startDate, DateTime endDate) { int hours = Convert.ToInt32((endDate - startDate).TotalHours) + 1; if (hours < 24) @@ -778,23 +778,23 @@ namespace DnsServerCore.Dns return GetHourWiseStats(startDate, hours); } - public Dictionary>> GetHourWiseStats(DateTime startDate, int hours) + public Dictionary>> GetHourWiseStats(DateTime startDate, int hours) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); - List> totalQueriesPerInterval = new List>(); - List> totalNoErrorPerInterval = new List>(); - List> totalServerFailurePerInterval = new List>(); - List> totalNxDomainPerInterval = new List>(); - List> totalRefusedPerInterval = new List>(); + List> totalQueriesPerInterval = new List>(); + List> totalNoErrorPerInterval = new List>(); + List> totalServerFailurePerInterval = new List>(); + List> totalNxDomainPerInterval = new List>(); + List> totalRefusedPerInterval = new List>(); - List> totalAuthHitPerInterval = new List>(); - List> totalRecursionsPerInterval = new List>(); - List> totalCacheHitPerInterval = new List>(); - List> totalBlockedPerInterval = new List>(); + List> totalAuthHitPerInterval = new List>(); + List> totalRecursionsPerInterval = new List>(); + List> totalCacheHitPerInterval = new List>(); + List> totalBlockedPerInterval = new List>(); - List> totalClientsPerInterval = new List>(); + List> totalClientsPerInterval = new List>(); for (int hour = 0; hour < hours; hour++) { @@ -806,37 +806,37 @@ namespace DnsServerCore.Dns totalStatCounter.Merge(hourlyStatCounter); - totalQueriesPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalQueries)); - totalNoErrorPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalNoError)); - totalServerFailurePerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalServerFailure)); - totalNxDomainPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalNxDomain)); - totalRefusedPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalRefused)); + totalQueriesPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalQueries)); + totalNoErrorPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalNoError)); + totalServerFailurePerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalServerFailure)); + totalNxDomainPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalNxDomain)); + totalRefusedPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalRefused)); - totalAuthHitPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalAuthoritative)); - totalRecursionsPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalRecursive)); - totalCacheHitPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalCached)); - totalBlockedPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalBlocked)); + totalAuthHitPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalAuthoritative)); + totalRecursionsPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalRecursive)); + totalCacheHitPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalCached)); + totalBlockedPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalBlocked)); - totalClientsPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalClients)); + totalClientsPerInterval.Add(new KeyValuePair(label, hourlyStatCounter.TotalClients)); } - Dictionary>> data = new Dictionary>>(); + Dictionary>> data = new Dictionary>>(); { - List> stats = new List>(6); + List> stats = new List>(6); - stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); - stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); - stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); - stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); - stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); + stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); + stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); + stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); + stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); + stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); - stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); - stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); - stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); - stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); + stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); + stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); + stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); + stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); - stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); + stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); data.Add("stats", stats); } @@ -862,28 +862,28 @@ namespace DnsServerCore.Dns return data; } - public Dictionary>> GetDayWiseStats(DateTime startDate, DateTime endDate) + public Dictionary>> GetDayWiseStats(DateTime startDate, DateTime endDate) { return GetDayWiseStats(startDate, Convert.ToInt32((endDate - startDate).TotalDays) + 1); } - public Dictionary>> GetDayWiseStats(DateTime startDate, int days) + public Dictionary>> GetDayWiseStats(DateTime startDate, int days) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); - List> totalQueriesPerInterval = new List>(); - List> totalNoErrorPerInterval = new List>(); - List> totalServerFailurePerInterval = new List>(); - List> totalNxDomainPerInterval = new List>(); - List> totalRefusedPerInterval = new List>(); + List> totalQueriesPerInterval = new List>(); + List> totalNoErrorPerInterval = new List>(); + List> totalServerFailurePerInterval = new List>(); + List> totalNxDomainPerInterval = new List>(); + List> totalRefusedPerInterval = new List>(); - List> totalAuthHitPerInterval = new List>(); - List> totalRecursionsPerInterval = new List>(); - List> totalCacheHitPerInterval = new List>(); - List> totalBlockedPerInterval = new List>(); + List> totalAuthHitPerInterval = new List>(); + List> totalRecursionsPerInterval = new List>(); + List> totalCacheHitPerInterval = new List>(); + List> totalBlockedPerInterval = new List>(); - List> totalClientsPerInterval = new List>(); + List> totalClientsPerInterval = new List>(); for (int day = 0; day < days; day++) //days { @@ -893,37 +893,37 @@ namespace DnsServerCore.Dns StatCounter dailyStatCounter = LoadDailyStats(lastDayDateTime); totalStatCounter.Merge(dailyStatCounter, true); - totalQueriesPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalQueries)); - totalNoErrorPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalNoError)); - totalServerFailurePerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalServerFailure)); - totalNxDomainPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalNxDomain)); - totalRefusedPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalRefused)); + totalQueriesPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalQueries)); + totalNoErrorPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalNoError)); + totalServerFailurePerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalServerFailure)); + totalNxDomainPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalNxDomain)); + totalRefusedPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalRefused)); - totalAuthHitPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalAuthoritative)); - totalRecursionsPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalRecursive)); - totalCacheHitPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalCached)); - totalBlockedPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalBlocked)); + totalAuthHitPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalAuthoritative)); + totalRecursionsPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalRecursive)); + totalCacheHitPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalCached)); + totalBlockedPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalBlocked)); - totalClientsPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalClients)); + totalClientsPerInterval.Add(new KeyValuePair(label, dailyStatCounter.TotalClients)); } - Dictionary>> data = new Dictionary>>(); + Dictionary>> data = new Dictionary>>(); { - List> stats = new List>(6); + List> stats = new List>(6); - stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); - stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); - stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); - stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); - stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); + stats.Add(new KeyValuePair("totalQueries", totalStatCounter.TotalQueries)); + stats.Add(new KeyValuePair("totalNoError", totalStatCounter.TotalNoError)); + stats.Add(new KeyValuePair("totalServerFailure", totalStatCounter.TotalServerFailure)); + stats.Add(new KeyValuePair("totalNxDomain", totalStatCounter.TotalNxDomain)); + stats.Add(new KeyValuePair("totalRefused", totalStatCounter.TotalRefused)); - stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); - stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); - stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); - stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); + stats.Add(new KeyValuePair("totalAuthoritative", totalStatCounter.TotalAuthoritative)); + stats.Add(new KeyValuePair("totalRecursive", totalStatCounter.TotalRecursive)); + stats.Add(new KeyValuePair("totalCached", totalStatCounter.TotalCached)); + stats.Add(new KeyValuePair("totalBlocked", totalStatCounter.TotalBlocked)); - stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); + stats.Add(new KeyValuePair("totalClients", totalStatCounter.TotalClients)); data.Add("stats", stats); } @@ -949,7 +949,7 @@ namespace DnsServerCore.Dns return data; } - public List> GetLastHourTopStats(TopStatsType type, int limit) + public List> GetLastHourTopStats(TopStatsType type, int limit) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -982,22 +982,22 @@ namespace DnsServerCore.Dns } } - public List> GetLastDayTopStats(TopStatsType type, int limit) + public List> GetLastDayTopStats(TopStatsType type, int limit) { return GetHourWiseTopStats(DateTime.UtcNow.AddHours(-24), 24, type, limit); } - public List> GetLastWeekTopStats(TopStatsType type, int limit) + public List> GetLastWeekTopStats(TopStatsType type, int limit) { return GetDayWiseTopStats(DateTime.UtcNow.AddDays(-7).Date, 7, type, limit); } - public List> GetLastMonthTopStats(TopStatsType type, int limit) + public List> GetLastMonthTopStats(TopStatsType type, int limit) { return GetDayWiseTopStats(DateTime.UtcNow.AddDays(-31).Date, 31, type, limit); } - public List> GetLastYearTopStats(TopStatsType type, int limit) + public List> GetLastYearTopStats(TopStatsType type, int limit) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -1039,7 +1039,7 @@ namespace DnsServerCore.Dns } } - public List> GetHourWiseTopStats(DateTime startDate, DateTime endDate, TopStatsType type, int limit) + public List> GetHourWiseTopStats(DateTime startDate, DateTime endDate, TopStatsType type, int limit) { int hours = Convert.ToInt32((endDate - startDate).TotalHours) + 1; if (hours < 24) @@ -1048,7 +1048,7 @@ namespace DnsServerCore.Dns return GetHourWiseTopStats(startDate, hours, type, limit); } - public List> GetHourWiseTopStats(DateTime startDate, int hours, TopStatsType type, int limit) + public List> GetHourWiseTopStats(DateTime startDate, int hours, TopStatsType type, int limit) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -1079,12 +1079,12 @@ namespace DnsServerCore.Dns } } - public List> GetDayWiseTopStats(DateTime startDate, DateTime endDate, TopStatsType type, int limit) + public List> GetDayWiseTopStats(DateTime startDate, DateTime endDate, TopStatsType type, int limit) { return GetDayWiseTopStats(startDate, Convert.ToInt32((endDate - startDate).TotalDays) + 1, type, limit); } - public List> GetDayWiseTopStats(DateTime startDate, int days, TopStatsType type, int limit) + public List> GetDayWiseTopStats(DateTime startDate, int days, TopStatsType type, int limit) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -1113,7 +1113,7 @@ namespace DnsServerCore.Dns } } - public List> GetLastHourEligibleQueries(int minimumHitsPerHour) + public List> GetLastHourEligibleQueries(int minimumHitsPerHour) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -1133,7 +1133,7 @@ namespace DnsServerCore.Dns return totalStatCounter.GetEligibleQueries(minimumHitsPerHour); } - public void GetLatestClientSubnetStats(int minutes, int ipv4PrefixLength, int ipv6PrefixLength, out IReadOnlyDictionary clientSubnetStats, out IReadOnlyDictionary errorClientSubnetStats) + public void GetLatestClientSubnetStats(int minutes, int ipv4PrefixLength, int ipv6PrefixLength, out IReadOnlyDictionary clientSubnetStats, out IReadOnlyDictionary errorClientSubnetStats) { StatCounter totalStatCounter = new StatCounter(); totalStatCounter.Lock(); @@ -1264,18 +1264,18 @@ namespace DnsServerCore.Dns volatile bool _locked; - int _totalQueries; - int _totalNoError; - int _totalServerFailure; - int _totalNxDomain; - int _totalRefused; + long _totalQueries; + long _totalNoError; + long _totalServerFailure; + long _totalNxDomain; + long _totalRefused; - int _totalAuthoritative; - int _totalRecursive; - int _totalCached; - int _totalBlocked; + long _totalAuthoritative; + long _totalRecursive; + long _totalCached; + long _totalBlocked; - int _totalClients; + long _totalClients; readonly ConcurrentDictionary _queryDomains; readonly ConcurrentDictionary _queryBlockedDomains; @@ -1285,7 +1285,7 @@ namespace DnsServerCore.Dns readonly ConcurrentDictionary _queries; bool _truncationFoundDuringMerge; - int _totalClientsDailyStatsSummation; + long _totalClientsDailyStatsSummation; #endregion @@ -1402,6 +1402,70 @@ namespace DnsServerCore.Dns break; + case 7: + _totalQueries = bR.ReadInt64(); + _totalNoError = bR.ReadInt64(); + _totalServerFailure = bR.ReadInt64(); + _totalNxDomain = bR.ReadInt64(); + _totalRefused = bR.ReadInt64(); + + _totalAuthoritative = bR.ReadInt64(); + _totalRecursive = bR.ReadInt64(); + _totalCached = bR.ReadInt64(); + _totalBlocked = bR.ReadInt64(); + + _totalClients = bR.ReadInt64(); + + { + int count = bR.ReadInt32(); + _queryDomains = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _queryDomains.TryAdd(bR.ReadShortString(), new Counter(bR.ReadInt64())); + } + + { + int count = bR.ReadInt32(); + _queryBlockedDomains = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _queryBlockedDomains.TryAdd(bR.ReadShortString(), new Counter(bR.ReadInt64())); + } + + { + int count = bR.ReadInt32(); + _queryTypes = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _queryTypes.TryAdd((DnsResourceRecordType)bR.ReadUInt16(), new Counter(bR.ReadInt64())); + } + + { + int count = bR.ReadInt32(); + _clientIpAddresses = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _clientIpAddresses.TryAdd(IPAddressExtension.Parse(bR), new Counter(bR.ReadInt64())); + } + + { + int count = bR.ReadInt32(); + _queries = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _queries.TryAdd(new DnsQuestionRecord(bR.BaseStream), new Counter(bR.ReadInt64())); + } + + { + int count = bR.ReadInt32(); + _errorIpAddresses = new ConcurrentDictionary(1, count); + + for (int i = 0; i < count; i++) + _errorIpAddresses.TryAdd(IPAddressExtension.Parse(bR), new Counter(bR.ReadInt64())); + } + + break; + default: throw new InvalidDataException("StatCounter version not supported."); } @@ -1413,9 +1477,9 @@ namespace DnsServerCore.Dns #region private - private static List> GetTopList(List> list, int limit) + private static List> GetTopList(List> list, int limit) { - list.Sort(delegate (KeyValuePair item1, KeyValuePair item2) + list.Sort(delegate (KeyValuePair item1, KeyValuePair item2) { return item2.Value.CompareTo(item1.Value); }); @@ -1608,7 +1672,7 @@ namespace DnsServerCore.Dns if (queryTypes.Count > limit) { - int othersCount = 0; + long othersCount = 0; for (int i = limit; i < queryTypes.Count; i++) othersCount += queryTypes[i].Value.Count; @@ -1680,7 +1744,7 @@ namespace DnsServerCore.Dns throw new DnsServerException("StatCounter must be locked."); bW.Write(Encoding.ASCII.GetBytes("SC")); //format - bW.Write((byte)6); //version + bW.Write((byte)7); //version bW.Write(_totalQueries); bW.Write(_totalNoError); @@ -1750,78 +1814,78 @@ namespace DnsServerCore.Dns } } - public List> GetTopDomains(int limit) + public List> GetTopDomains(int limit) { - List> topDomains = new List>(_queryDomains.Count); + List> topDomains = new List>(_queryDomains.Count); foreach (KeyValuePair item in _queryDomains) - topDomains.Add(new KeyValuePair(item.Key, item.Value.Count)); + topDomains.Add(new KeyValuePair(item.Key, item.Value.Count)); return GetTopList(topDomains, limit); } - public List> GetTopBlockedDomains(int limit) + public List> GetTopBlockedDomains(int limit) { - List> topBlockedDomains = new List>(_queryBlockedDomains.Count); + List> topBlockedDomains = new List>(_queryBlockedDomains.Count); foreach (KeyValuePair item in _queryBlockedDomains) - topBlockedDomains.Add(new KeyValuePair(item.Key, item.Value.Count)); + topBlockedDomains.Add(new KeyValuePair(item.Key, item.Value.Count)); return GetTopList(topBlockedDomains, limit); } - public List> GetTopClients(int limit) + public List> GetTopClients(int limit) { - List> topClients = new List>(_clientIpAddresses.Count); + List> topClients = new List>(_clientIpAddresses.Count); foreach (KeyValuePair item in _clientIpAddresses) - topClients.Add(new KeyValuePair(item.Key.ToString(), item.Value.Count)); + topClients.Add(new KeyValuePair(item.Key.ToString(), item.Value.Count)); return GetTopList(topClients, limit); } - public List> GetTopQueryTypes(int limit) + public List> GetTopQueryTypes(int limit) { - List> queryTypes = new List>(_queryTypes.Count); + List> queryTypes = new List>(_queryTypes.Count); foreach (KeyValuePair item in _queryTypes) - queryTypes.Add(new KeyValuePair(item.Key.ToString(), item.Value.Count)); + queryTypes.Add(new KeyValuePair(item.Key.ToString(), item.Value.Count)); - queryTypes.Sort(delegate (KeyValuePair item1, KeyValuePair item2) + queryTypes.Sort(delegate (KeyValuePair item1, KeyValuePair item2) { return item2.Value.CompareTo(item1.Value); }); if (queryTypes.Count > limit) { - int othersCount = 0; + long othersCount = 0; for (int i = limit; i < queryTypes.Count; i++) othersCount += queryTypes[i].Value; queryTypes.RemoveRange((limit - 1), queryTypes.Count - (limit - 1)); - queryTypes.Add(new KeyValuePair("Others", othersCount)); + queryTypes.Add(new KeyValuePair("Others", othersCount)); } return queryTypes; } - public List> GetEligibleQueries(int minimumHits) + public List> GetEligibleQueries(int minimumHits) { - List> eligibleQueries = new List>(Convert.ToInt32(_queries.Count * 0.1)); + List> eligibleQueries = new List>(Convert.ToInt32(_queries.Count * 0.1)); foreach (KeyValuePair item in _queries) { if (item.Value.Count >= minimumHits) - eligibleQueries.Add(new KeyValuePair(item.Key, item.Value.Count)); + eligibleQueries.Add(new KeyValuePair(item.Key, item.Value.Count)); } return eligibleQueries; } - public IReadOnlyDictionary GetClientSubnetStats(int ipv4PrefixLength, int ipv6PrefixLength) + public IReadOnlyDictionary GetClientSubnetStats(int ipv4PrefixLength, int ipv6PrefixLength) { - Dictionary clientSubnetStats = new Dictionary(_clientIpAddresses.Count); + Dictionary clientSubnetStats = new Dictionary(_clientIpAddresses.Count); foreach (KeyValuePair item in _clientIpAddresses) { @@ -1841,7 +1905,7 @@ namespace DnsServerCore.Dns throw new NotSupportedException("AddressFamily not supported."); } - if (clientSubnetStats.TryGetValue(clientSubnet, out int existingValue)) + if (clientSubnetStats.TryGetValue(clientSubnet, out long existingValue)) clientSubnetStats[clientSubnet] = existingValue + item.Value.Count; else clientSubnetStats.Add(clientSubnet, item.Value.Count); @@ -1850,9 +1914,9 @@ namespace DnsServerCore.Dns return clientSubnetStats; } - public IReadOnlyDictionary GetErrorClientSubnetStats(int ipv4PrefixLength, int ipv6PrefixLength) + public IReadOnlyDictionary GetErrorClientSubnetStats(int ipv4PrefixLength, int ipv6PrefixLength) { - Dictionary errorClientSubnetStats = new Dictionary(_errorIpAddresses.Count); + Dictionary errorClientSubnetStats = new Dictionary(_errorIpAddresses.Count); foreach (KeyValuePair item in _errorIpAddresses) { @@ -1872,7 +1936,7 @@ namespace DnsServerCore.Dns throw new NotSupportedException("AddressFamily not supported."); } - if (errorClientSubnetStats.TryGetValue(clientSubnet, out int existingValue)) + if (errorClientSubnetStats.TryGetValue(clientSubnet, out long existingValue)) errorClientSubnetStats[clientSubnet] = existingValue + item.Value.Count; else errorClientSubnetStats.Add(clientSubnet, item.Value.Count); @@ -1888,34 +1952,34 @@ namespace DnsServerCore.Dns public bool IsLocked { get { return _locked; } } - public int TotalQueries + public long TotalQueries { get { return _totalQueries; } } - public int TotalNoError + public long TotalNoError { get { return _totalNoError; } } - public int TotalServerFailure + public long TotalServerFailure { get { return _totalServerFailure; } } - public int TotalNxDomain + public long TotalNxDomain { get { return _totalNxDomain; } } - public int TotalRefused + public long TotalRefused { get { return _totalRefused; } } - public int TotalAuthoritative + public long TotalAuthoritative { get { return _totalAuthoritative; } } - public int TotalRecursive + public long TotalRecursive { get { return _totalRecursive; } } - public int TotalCached + public long TotalCached { get { return _totalCached; } } - public int TotalBlocked + public long TotalBlocked { get { return _totalBlocked; } } - public int TotalClients + public long TotalClients { get { @@ -1932,7 +1996,7 @@ namespace DnsServerCore.Dns { #region variables - int _count; + long _count; #endregion @@ -1941,7 +2005,7 @@ namespace DnsServerCore.Dns public Counter() { } - public Counter(int count) + public Counter(long count) { _count = count; } @@ -1964,7 +2028,7 @@ namespace DnsServerCore.Dns #region properties - public int Count + public long Count { get { return _count; } } #endregion