diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index bcfa03ea1a..736c262222 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -370,6 +370,9 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) cache_name = dir = 0; asyncs_pending = 0; + num_requests = 0; + successful = 0; + failed = 0; } DNS_Mgr::~DNS_Mgr() @@ -952,6 +955,8 @@ void DNS_Mgr::IssueAsyncRequests() AsyncRequest* req = asyncs_queued.front(); asyncs_queued.pop_front(); + ++num_requests; + DNS_Mgr_Request* dr; if ( req->IsAddrReq() ) dr = new DNS_Mgr_Request(req->host); @@ -961,6 +966,7 @@ void DNS_Mgr::IssueAsyncRequests() if ( ! dr->MakeRequest(nb_dns) ) { reporter->Warning("can't issue DNS request"); + ++failed; req->Timeout(); continue; } @@ -995,10 +1001,16 @@ void DNS_Mgr::CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout) { const char* name = LookupAddrInCache(addr); if ( name ) + { + ++successful; i->second->Resolved(name); + } else if ( timeout ) + { + ++failed; i->second->Timeout(); + } else return; @@ -1024,12 +1036,16 @@ void DNS_Mgr::CheckAsyncHostRequest(const char* host, bool timeout) if ( addrs ) { + ++successful; i->second->Resolved(addrs); Unref(addrs); } else if ( timeout ) + { + ++failed; i->second->Timeout(); + } else return; @@ -1146,3 +1162,14 @@ int DNS_Mgr::AnswerAvailable(int timeout) return status; } + +void DNS_Mgr::GetStats(Stats* stats) + { + stats->requests = num_requests; + stats->successful = successful; + stats->failed = failed; + stats->pending = asyncs_pending; + stats->cached_hosts = host_mappings.Length(); + stats->cached_addresses = addr_mappings.Length(); + } + diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 6f16d9661d..def608d064 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -1,4 +1,4 @@ -// See the file "COPYING" in the main distribution directory for copyright. + // See the file "COPYING" in the main distribution directory for copyright. #ifndef dnsmgr_h #define dnsmgr_h @@ -81,6 +81,17 @@ public: void AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback); void AsyncLookupName(string name, LookupCallback* callback); + struct Stats { + unsigned long requests; // These count only async requests. + unsigned long successful; + unsigned long failed; + unsigned long pending; + unsigned long cached_hosts; + unsigned long cached_addresses; + }; + + void GetStats(Stats* stats); + protected: friend class LookupCallback; friend class DNS_Mgr_Request; @@ -206,6 +217,10 @@ protected: TimeoutQueue asyncs_timeouts; int asyncs_pending; + + unsigned long num_requests; + unsigned long successful; + unsigned long failed; }; extern DNS_Mgr* dns_mgr; diff --git a/src/Stats.cc b/src/Stats.cc index 4798a789a7..55835613e9 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -7,6 +7,8 @@ #include "Scope.h" #include "cq.h" #include "ConnCompressor.h" +#include "DNS_Mgr.h" +#include "Trigger.h" int killed_by_inactivity = 0; @@ -193,6 +195,19 @@ void ProfileLogger::Log() (timer_mgr->Size() * padded_sizeof(ConnectionTimer))) / 1024, network_time - timer_mgr->LastTimestamp())); + DNS_Mgr::Stats dstats; + dns_mgr->GetStats(&dstats); + + file->Write(fmt("%.06f DNS_Mgr: requests=%lu succesful=%lu failed=%lu pending=%lu cached_hosts=%lu cached_addrs=%lu\n", + network_time, + dstats.requests, dstats.successful, dstats.failed, dstats.pending, + dstats.cached_hosts, dstats.cached_addresses)); + + Trigger::Stats tstats; + Trigger::GetStats(&tstats); + + file->Write(fmt("%.06f Triggers: total=%lu pending=%lu\n", network_time, tstats.total, tstats.pending)); + unsigned int* current_timers = TimerMgr::CurrentTimers(); for ( int i = 0; i < NUM_TIMER_TYPES; ++i ) { diff --git a/src/Trigger.cc b/src/Trigger.cc index 272d03a859..26f80c73d9 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -110,6 +110,8 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, is_return = arg_is_return; location = arg_location; + ++total_triggers; + DBG_LOG(DBG_NOTIFIERS, "%s: instantiating", Name()); if ( is_return ) @@ -165,6 +167,7 @@ void Trigger::Init() } Trigger::TriggerList* Trigger::pending = 0; +unsigned long Trigger::total_triggers = 0; bool Trigger::Eval() { @@ -413,3 +416,9 @@ const char* Trigger::Name() return fmt("%s:%d-%d", location->filename, location->first_line, location->last_line); } + +void Trigger::GetStats(Stats* stats) + { + stats->total = total_triggers; + stats->pending = pending ? pending->size() : 0; + } diff --git a/src/Trigger.h b/src/Trigger.h index 8001308bce..ffec50d7ef 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -67,6 +67,13 @@ public: // Evaluates all queued Triggers. static void EvaluatePending(); + struct Stats { + unsigned long total; + unsigned long pending; + }; + + static void GetStats(Stats* stats); + private: friend class TriggerTraversalCallback; friend class TriggerTimer; @@ -99,6 +106,8 @@ private: typedef list TriggerList; static TriggerList* pending; + + static unsigned long total_triggers; }; #endif diff --git a/src/bro.bif b/src/bro.bif index 8b435686c4..d8cc9d4696 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -560,7 +560,7 @@ function to_addr%(ip: string%): addr function count_to_v4_addr%(ip: count%): addr %{ - if ( ip > 4294967295 ) + if ( ip > 4294967295LU ) { builtin_error("conversion of non-IPv4 count to addr", @ARG@[0]); return new AddrVal(uint32(0));