Move DNS stats to core_dns.

This commit is contained in:
Sadie Powell 2021-12-24 11:22:58 +00:00
parent 6282e1f287
commit 723a36ec39
3 changed files with 23 additions and 23 deletions

View File

@ -130,22 +130,6 @@ class serverstats final
*/
unsigned long Collisions = 0;
/** Number of DNS queries sent out
*/
unsigned long Dns = 0;
/** Number of good DNS replies received
* NOTE: This may not tally to the number sent out,
* due to timeouts and other latency issues.
*/
unsigned long DnsGood = 0;
/** Number of bad (negative) DNS replies received
* NOTE: This may not tally to the number sent out,
* due to timeouts and other latency issues.
*/
unsigned long DnsBad = 0;
/** Number of inbound connections seen
*/
unsigned long Connects = 0;

View File

@ -21,6 +21,8 @@
#include "inspircd.h"
#include "modules/dns.h"
#include "modules/stats.h"
#include <iostream>
#include <fstream>
@ -441,6 +443,9 @@ class MyManager final
public:
DNS::Request* requests[MAX_REQUEST_ID+1];
size_t stats_total = 0;
size_t stats_success = 0;
size_t stats_failure = 0;
MyManager(Module* c)
: Manager(c)
@ -671,14 +676,14 @@ class MyManager final
if (!valid)
{
ServerInstance->stats.DnsBad++;
this->stats_failure++;
recv_packet.error = ERROR_MALFORMED;
request->OnError(&recv_packet);
}
else if (recv_packet.flags & QUERYFLAGS_OPCODE)
{
ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Received a nonstandard query");
ServerInstance->stats.DnsBad++;
this->stats_failure++;
recv_packet.error = ERROR_NONSTANDARD_QUERY;
request->OnError(&recv_packet);
}
@ -712,26 +717,26 @@ class MyManager final
break;
}
ServerInstance->stats.DnsBad++;
this->stats_failure++;
recv_packet.error = error;
request->OnError(&recv_packet);
}
else if (recv_packet.answers.empty())
{
ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "No resource records returned");
ServerInstance->stats.DnsBad++;
this->stats_failure++;
recv_packet.error = ERROR_NO_RECORDS;
request->OnError(&recv_packet);
}
else
{
ServerInstance->Logs.Log(MODNAME, LOG_DEBUG, "Lookup complete for " + request->question.name);
ServerInstance->stats.DnsGood++;
this->stats_success++;
request->OnLookupComplete(&recv_packet);
this->AddCache(recv_packet);
}
ServerInstance->stats.Dns++;
this->stats_total++;
/* Request's destructor removes it from the request map */
delete request;
@ -810,6 +815,7 @@ class MyManager final
class ModuleDNS final
: public Module
, public Stats::EventListener
{
MyManager manager;
std::string DNSServer;
@ -877,6 +883,7 @@ class ModuleDNS final
public:
ModuleDNS()
: Module(VF_CORE | VF_VENDOR, "Provides support for DNS lookups")
, Stats::EventListener(this)
, manager(this)
{
}
@ -911,6 +918,16 @@ class ModuleDNS final
this->manager.Rehash(DNSServer, SourceIP, SourcePort);
}
ModResult OnStats(Stats::Context& stats) override
{
if (stats.GetSymbol() == 'T')
{
stats.AddRow(RPL_STATS, stats.GetSymbol(), InspIRCd::Format("DNS requests: %zu (%zu succeeded, %zu failed)",
manager.stats_total, manager.stats_success, manager.stats_failure));
}
return MOD_RES_PASSTHRU;
}
void OnUnloadModule(Module* mod) override
{
for (unsigned int i = 0; i <= MAX_REQUEST_ID; ++i)

View File

@ -307,7 +307,6 @@ void CommandStats::DoStats(Stats::Context& stats)
stats.AddRow(249, "accepts "+ConvToStr(ServerInstance->stats.Accept)+" refused "+ConvToStr(ServerInstance->stats.Refused));
stats.AddRow(249, "unknown commands "+ConvToStr(ServerInstance->stats.Unknown));
stats.AddRow(249, "nick collisions "+ConvToStr(ServerInstance->stats.Collisions));
stats.AddRow(249, "dns requests "+ConvToStr(ServerInstance->stats.DnsGood+ServerInstance->stats.DnsBad)+" succeeded "+ConvToStr(ServerInstance->stats.DnsGood)+" failed "+ConvToStr(ServerInstance->stats.DnsBad));
stats.AddRow(249, "connection count "+ConvToStr(ServerInstance->stats.Connects));
stats.AddRow(249, InspIRCd::Format("bytes sent %5.2fK recv %5.2fK",
ServerInstance->stats.Sent / 1024.0, ServerInstance->stats.Recv / 1024.0));