#include "statnode.hh"
-static std::unordered_map<unsigned int, vector<boost::variant<string,double>>> getGenResponses(unsigned int top, boost::optional<int> labels, std::function<bool(const Rings::Response&)> pred)
+static std::vector<std::pair<int, vector<boost::variant<string,double>>>> getGenResponses(uint64_t top, boost::optional<int> labels, std::function<bool(const Rings::Response&)> pred)
{
setLuaNoSideEffect();
map<DNSName, unsigned int> counts;
return b.first < a.first;
});
- std::unordered_map<unsigned int, vector<boost::variant<string,double>>> ret;
- unsigned int count=1, rest=0;
+ std::vector<std::pair<int, vector<boost::variant<string,double>>>> ret;
+ ret.reserve(std::min(rcounts.size(), top + 1U));
+ uint64_t count = 1;
+ unsigned int rest = 0;
for(const auto& rc : rcounts) {
if(count==top+1)
rest+=rc.first;
else
- ret.insert({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}});
+ ret.push_back({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}});
}
if (total > 0) {
- ret.insert({count, {"Rest", rest, 100.0*rest/total}});
+ ret.push_back({count, {"Rest", rest, 100.0*rest/total}});
}
else {
- ret.insert({count, {"Rest", rest, 100.0 }});
+ ret.push_back({count, {"Rest", rest, 100.0 }});
}
return ret;
}
+#ifndef DISABLE_DEPRECATED_DYNBLOCK
+
typedef std::unordered_map<ComboAddress, unsigned int, ComboAddress::addressOnlyHash, ComboAddress::addressOnlyEqual> counts_t;
static counts_t filterScore(const counts_t& counts,
return ret;
}
-
typedef std::function<void(const StatNode&, const StatNode::Stat&, const StatNode::Stat&)> statvisitor_t;
-static void statNodeRespRing(statvisitor_t visitor, unsigned int seconds)
+static void statNodeRespRing(statvisitor_t visitor, uint64_t seconds)
{
struct timespec cutoff, now;
gettime(&now);
visitor(*node_, self, children);}, node);
}
-static vector<pair<unsigned int, std::unordered_map<string,string> > > getRespRing(boost::optional<int> rcode)
+static vector<pair<int, std::vector<std::pair<string,string> > > > getRespRing(boost::optional<int> rcode)
{
- typedef std::unordered_map<string,string> entry_t;
- vector<pair<unsigned int, entry_t > > ret;
+ typedef std::vector<std::pair<string,string>> entry_t;
+ vector<pair<int, entry_t > > ret;
for (const auto& shard : g_rings.d_shards) {
auto rl = shard->respRing.lock();
- entry_t e;
- unsigned int count=1;
- for(const auto& c : *rl) {
- if(rcode && (rcode.get() != c.dh.rcode))
+ int count = 1;
+ for (const auto& c : *rl) {
+ if (rcode && (rcode.get() != c.dh.rcode)) {
continue;
- e["qname"]=c.name.toString();
- e["rcode"]=std::to_string(c.dh.rcode);
- ret.emplace_back(count, e);
+ }
+ entry_t e;
+ e.push_back({ "qname", c.name.toString() });
+ e.push_back({ "rcode", std::to_string(c.dh.rcode) });
+ ret.emplace_back(count, std::move(e));
count++;
}
}
});
}
+#endif /* DISABLE_DEPRECATED_DYNBLOCK */
+
void setupLuaInspection(LuaContext& luaCtx)
{
- luaCtx.writeFunction("topClients", [](boost::optional<unsigned int> top_) {
+ luaCtx.writeFunction("topClients", [](boost::optional<uint64_t> top_) {
setLuaNoSideEffect();
auto top = top_.get_value_or(10);
map<ComboAddress, unsigned int,ComboAddress::addressOnlyLessThan > counts;
g_outputBuffer += (fmt % (count) % "Rest" % rest % (total > 0 ? 100.0*rest/total : 100.0)).str();
});
- luaCtx.writeFunction("getTopQueries", [](unsigned int top, boost::optional<int> labels) {
+ luaCtx.writeFunction("getTopQueries", [](uint64_t top, boost::optional<int> labels) {
setLuaNoSideEffect();
map<DNSName, unsigned int> counts;
unsigned int total=0;
return ret;
});
- luaCtx.writeFunction("getTopResponses", [](unsigned int top, unsigned int kind, boost::optional<int> labels) {
+ luaCtx.writeFunction("getTopResponses", [](uint64_t top, uint64_t kind, boost::optional<int> labels) {
return getGenResponses(top, labels, [kind](const Rings::Response& r) { return r.dh.rcode == kind; });
});
luaCtx.executeCode(R"(function topResponses(top, kind, labels) top = top or 10; kind = kind or 0; for k,v in ipairs(getTopResponses(top, kind, labels)) do show(string.format("%4d %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
- luaCtx.writeFunction("getSlowResponses", [](unsigned int top, unsigned int msec, boost::optional<int> labels) {
+ luaCtx.writeFunction("getSlowResponses", [](uint64_t top, uint64_t msec, boost::optional<int> labels) {
return getGenResponses(top, labels, [msec](const Rings::Response& r) { return r.usec > msec*1000; });
});
luaCtx.executeCode(R"(function topSlow(top, msec, labels) top = top or 10; msec = msec or 500; for k,v in ipairs(getSlowResponses(top, msec, labels)) do show(string.format("%4d %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)");
- luaCtx.writeFunction("getTopBandwidth", [](unsigned int top) {
+ luaCtx.writeFunction("getTopBandwidth", [](uint64_t top) {
setLuaNoSideEffect();
return g_rings.getTopBandwidth(top);
});
}
});
+#ifndef DISABLE_DEPRECATED_DYNBLOCK
luaCtx.writeFunction("exceedServFails", [](unsigned int rate, int seconds) {
setLuaNoSideEffect();
return exceedRCode(rate, seconds, RCode::ServFail);
luaCtx.registerMember("drops", &StatNode::Stat::drops);
luaCtx.registerMember("bytes", &StatNode::Stat::bytes);
- luaCtx.writeFunction("statNodeRespRing", [](statvisitor_t visitor, boost::optional<unsigned int> seconds) {
- statNodeRespRing(visitor, seconds ? *seconds : 0);
+ luaCtx.writeFunction("statNodeRespRing", [](statvisitor_t visitor, boost::optional<uint64_t> seconds) {
+ statNodeRespRing(visitor, seconds ? *seconds : 0U);
});
+#endif /* DISABLE_DEPRECATED_DYNBLOCK */
/* DynBlockRulesGroup */
luaCtx.writeFunction("dynBlockRulesGroup", []() { return std::make_shared<DynBlockRulesGroup>(); });