From b30a637dfa4bd37ad808e432cb8201e5b54a9a7e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 2 Sep 2018 19:24:20 -0700 Subject: [PATCH] modules/console: Add cmds to count peers and DNS cache entries. --- modules/console.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index bd5dd442d..a071fc795 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -2196,6 +2196,22 @@ console_cmd__peer(opt &out, const string_view &line) return true; } +bool +console_cmd__peer__count(opt &out, const string_view &line) +{ + size_t i{0}; + for(const auto &pair : ircd::server::peers) + { + assert(bool(pair.second)); + const auto &peer{*pair.second}; + if(!peer.err_has()) + ++i; + } + + out << i << std::endl; + return true; +} + bool console_cmd__peer__error(opt &out, const string_view &line) { @@ -2232,6 +2248,22 @@ console_cmd__peer__error(opt &out, const string_view &line) return true; } +bool +console_cmd__peer__error__count(opt &out, const string_view &line) +{ + size_t i{0}; + for(const auto &pair : ircd::server::peers) + { + assert(bool(pair.second)); + const auto &peer{*pair.second}; + if(peer.err_has()) + ++i; + } + + out << i << std::endl; + return true; +} + bool console_cmd__peer__error__clear__all(opt &out, const string_view &line) { @@ -2483,6 +2515,22 @@ console_cmd__net__host__cache__A(opt &out, const string_view &line) return true; } +bool +console_cmd__net__host__cache__A__count(opt &out, const string_view &line) +{ + size_t count[2] {0}; + for(const auto &pair : net::dns::cache.A) + { + const auto &host{pair.first}; + const auto &record{pair.second}; + ++count[bool(record.ip4)]; + } + + out << "resolved: " << count[1] << std::endl; + out << "error: " << count[0] << std::endl; + return true; +} + bool console_cmd__net__host__cache__SRV(opt &out, const string_view &line) { @@ -2505,6 +2553,22 @@ console_cmd__net__host__cache__SRV(opt &out, const string_view &line) return true; } +bool +console_cmd__net__host__cache__SRV__count(opt &out, const string_view &line) +{ + size_t count[2] {0}; + for(const auto &pair : net::dns::cache.SRV) + { + const auto &host{pair.first}; + const auto &record{pair.second}; + ++count[bool(record.tgt)]; + } + + out << "resolved: " << count[1] << std::endl; + out << "error: " << count[0] << std::endl; + return true; +} + bool console_cmd__net__host__prefetch(opt &out, const string_view &line) {