WebServiceDashboardApi: updated GetStats() and GetTopStats() to support minute stats.

This commit is contained in:
Shreyas Zare
2025-01-11 17:48:52 +05:30
parent 634df67bed
commit 2e6741a822

View File

@@ -1,6 +1,6 @@
/* /*
Technitium DNS Server Technitium DNS Server
Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com) Copyright (C) 2025 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -196,7 +196,9 @@ namespace DnsServerCore
if (startDate > endDate) if (startDate > endDate)
throw new DnsWebServiceException("Start date must be less than or equal to end date."); throw new DnsWebServiceException("Start date must be less than or equal to end date.");
if ((Convert.ToInt32((endDate - startDate).TotalDays) + 1) > 7) TimeSpan duration = endDate - startDate;
if ((Convert.ToInt32(duration.TotalDays) + 1) > 7)
{ {
data = _dnsWebService.DnsServer.StatsManager.GetDayWiseStats(startDate, endDate, utcFormat); data = _dnsWebService.DnsServer.StatsManager.GetDayWiseStats(startDate, endDate, utcFormat);
@@ -205,7 +207,7 @@ namespace DnsServerCore
else else
labelFormat = "DD/MM"; labelFormat = "DD/MM";
} }
else else if ((Convert.ToInt32(duration.TotalHours) + 1) > 3)
{ {
data = _dnsWebService.DnsServer.StatsManager.GetHourWiseStats(startDate, endDate, utcFormat); data = _dnsWebService.DnsServer.StatsManager.GetHourWiseStats(startDate, endDate, utcFormat);
@@ -214,6 +216,15 @@ namespace DnsServerCore
else else
labelFormat = "DD/MM HH:00"; labelFormat = "DD/MM HH:00";
} }
else
{
data = _dnsWebService.DnsServer.StatsManager.GetMinuteWiseStats(startDate, endDate, utcFormat);
if (isLanguageEnUs)
labelFormat = "MM/DD HH:mm";
else
labelFormat = "DD/MM HH:mm";
}
break; break;
@@ -595,19 +606,23 @@ namespace DnsServerCore
string strStartDate = request.GetQueryOrForm("start"); string strStartDate = request.GetQueryOrForm("start");
string strEndDate = request.GetQueryOrForm("end"); string strEndDate = request.GetQueryOrForm("end");
if (!DateTime.TryParseExact(strStartDate, "yyyy-M-d", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime startDate)) if (!DateTime.TryParse(strStartDate, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime startDate))
throw new DnsWebServiceException("Invalid start date format."); throw new DnsWebServiceException("Invalid start date format.");
if (!DateTime.TryParseExact(strEndDate, "yyyy-M-d", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime endDate)) if (!DateTime.TryParse(strEndDate, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out DateTime endDate))
throw new DnsWebServiceException("Invalid end date format."); throw new DnsWebServiceException("Invalid end date format.");
if (startDate > endDate) if (startDate > endDate)
throw new DnsWebServiceException("Start date must be less than or equal to end date."); throw new DnsWebServiceException("Start date must be less than or equal to end date.");
if ((Convert.ToInt32((endDate - startDate).TotalDays) + 1) > 7) TimeSpan duration = endDate - startDate;
if ((Convert.ToInt32(duration.TotalDays) + 1) > 7)
topStatsData = _dnsWebService.DnsServer.StatsManager.GetDayWiseTopStats(startDate, endDate, statsType, limit); topStatsData = _dnsWebService.DnsServer.StatsManager.GetDayWiseTopStats(startDate, endDate, statsType, limit);
else else if ((Convert.ToInt32(duration.TotalHours) + 1) > 3)
topStatsData = _dnsWebService.DnsServer.StatsManager.GetHourWiseTopStats(startDate, endDate, statsType, limit); topStatsData = _dnsWebService.DnsServer.StatsManager.GetHourWiseTopStats(startDate, endDate, statsType, limit);
else
topStatsData = _dnsWebService.DnsServer.StatsManager.GetMinuteWiseTopStats(startDate, endDate, statsType, limit);
break; break;