generate one that overlaps with a PowerDNS stock metric, you will get double
output and weird results.
+### Statistics
+
+You can retrieve statistics from Lua using the `getStat("name")` call. For example,
+to retrieve the number of cache misses:
+
+```
+cacheMisses = getStat("cache-misses")
+```
+
+Please be aware that retrieving statistics is a relatively costly operation, and as such
+should for example not be done for every query.
+
### Logging
To log messages with the main PowerDNS Recursor process, use `pdnslog(message)`.
pdnslog can also write out to a syslog loglevel if specified.
d_lw->registerFunction("set", &DynMetric::set);
d_lw->registerFunction("get", &DynMetric::get);
+ d_lw->writeFunction("getStat", [](const std::string& str) {
+ uint64_t result = 0;
+ optional<uint64_t> value = getStatByName(str);
+ if (value) {
+ result = *value;
+ }
+ return result;
+ });
+
d_lw->writeFunction("getRecursorThreadId", []() {
return getRecursorThreadId();
});
}
}
+ registerAllStats();
if(!t_id) {
t_fdm->addReadFD(s_rcc.d_fd, handleRCC); // control channel
}
boost::replace_all(hostname, ".", "_");
}
+ registerAllStats();
string msg;
for(const auto& carbonServer: carbonServers) {
- RecursorControlParser rcp; // inits if needed
ComboAddress remote(carbonServer, 2003);
Socket s(remote.sin4.sin_family, SOCK_STREAM);
#ifdef HAVE_NET_SNMP
/* This is done so that the statistics maps are
initialized. */
- RecursorControlParser rcp;
+ registerAllStats();
registerCounter64Stat("questions", questionsOID, OID_LENGTH(questionsOID));
registerCounter64Stat("ipv6-questions", ipv6QuestionsOID, OID_LENGTH(ipv6QuestionsOID));
class RecursorControlParser
{
public:
- RecursorControlParser();
+ RecursorControlParser()
+ {
+ }
static void nop(void){}
typedef void func_t(void);
std::string getAnswer(const std::string& question, func_t** func);
-private:
- static bool s_init;
};
std::map<std::string, std::string> getAllStatsMap();
DNSName getRegisteredName(const DNSName& dom);
std::atomic<unsigned long>* getDynMetric(const std::string& str);
optional<uint64_t> getStatByName(const std::string& name);
+void registerAllStats();
#endif
return ret;
}
-optional<uint64_t> get(const string& name)
+static optional<uint64_t> get(const string& name)
{
optional<uint64_t> ret;
extern ResponseStats g_rs;
-bool RecursorControlParser::s_init;
-RecursorControlParser::RecursorControlParser()
+void registerAllStats()
{
+ static bool s_init = false;
if(s_init)
return;
s_init=true;
RecursorWebServer::RecursorWebServer(FDMultiplexer* fdm)
{
- RecursorControlParser rcp; // inits
+ registerAllStats();
d_ws = new AsyncWebServer(fdm, arg()["webserver-address"], arg().asNum("webserver-port"));
d_ws->bind();