These are chat archives for CZ-NIC/knot-resolver

28th
Mar 2017
lanconnected
@lanconnected
Mar 28 2017 13:58
Hello, we would like to create a munin plugin for knot-resolver. I have noticed there is a stats module which provides a lot of information but the documentation is unclear on how to gather this information from outside of knot process (which is running as a daemon). Could you point me to some relevant documentation/examples? Is there a way to bind the interactive command line to a running knot? Do we have to create a separate module for this and populate some file on HDD?
Vladimír Čunát
@vcunat
Mar 28 2017 14:10
@lanconnected: if you run it in non-interactive mode, it creates a socket. You can connect on the socket and give (lua) commands, just as in config file or interactive mode.
Ondřej Surý
@oerdnj
Mar 28 2017 14:10
@lanconnected There's a HTTP/2 interface available as a kresd module.
lanconnected
@lanconnected
Mar 28 2017 14:33

@oerdnj I have tried adding 'http' to modules={} but it complains that http module cannot be found: error: module 'http' not found: error: No such file or directory.
Is it a .lua module? Do we have to recompile the daemon with different flags?

The relevant config part looks like:
modules = {
'policy', -- Block queries to local zones/bad sites
'view', -- Handle requests by source IP
'stats', -- Track internal statistics
'http',
}

Ondřej Surý
@oerdnj
Mar 28 2017 14:34
It's a lua module. How did you install the kresd?
It requires several lua extensions, most notably: https://github.com/daurnimator/lua-http
lanconnected
@lanconnected
Mar 28 2017 14:37

@oerdnj It's a custom rpm package. Now I see, there is a part of the rpm which excludes this module. I'll check it out.

What about the socket Vladimir talked about? Isn't it an easier way if it's already built in? Can I configure where the socket appears? How do I find which socket is meant to be used for this communication?

Vladimír Čunát
@vcunat
Mar 28 2017 14:38
@lanconnected: it's builtin. A named socket (for each process), typically it's created in $PWD/tty/$PID but systemd service can override the location.
lanconnected
@lanconnected
Mar 28 2017 14:39
@vcunat Is there any documentation regarding the syntax?
Ondřej Surý
@oerdnj
Mar 28 2017 14:39
@lanconnected However that would require you to parse lua output
Vladimír Čunát
@vcunat
Mar 28 2017 14:39
Yes, the HTTP interface will be easier to consume.
Ondřej Surý
@oerdnj
Mar 28 2017 14:40
@lanconnected It's a lua console, so everything in the documentation related to the config file, modules, etc. can be used there. And the output is lua
lanconnected
@lanconnected
Mar 28 2017 14:40
I see. Thanks for the tips. I'll try to make it work one way or another.
Marek Vavruša
@vavrusa
Mar 28 2017 15:47
There is a third option - you can just write stats every X to a file like you want from the config. If you write something like local s, f = '', io.open('logs', 'a') for k,v in pairs(stats.list()) do s = s .. string.format('%s = %d\n', k, v) end f:write(s) f:close()(untested, but you get the idea) it will append stats to a logs file. You can schedule to do this every minute for example, like event.recurrent(1 * minute, function () local s, f = '', io.open('logs', 'a') for k,v in pairs(stats.list()) do s = s .. string.format('%s = %d\n', k, v) end f:write(s) f:close() end) (you just put this in the config). See http://knot-resolver.readthedocs.io/en/stable/daemon.html#events-and-services
James Nedila
@krunchyklown
Mar 28 2017 19:18
I'm in the middle of learning the Lua module interface with Knot-Resolver, and I have a question: Where would I find the source IP address of a particular DNS request?
Marek Vavruša
@vavrusa
Mar 28 2017 22:03
Marek Vavruša
@vavrusa
Mar 28 2017 22:09
@mikz this actually supports async DNS in OpenResty https://github.com/vavrusa/ljdns/tree/master/warp#running-in-openresty but there's no backend using libkres yet (just auth and caches/forwarders), it shouldn't be so hard to create it though as libkres already has an ffi abstraction
James Nedila
@krunchyklown
Mar 28 2017 22:21
@vavrusa Great, thanks!
James Nedila
@krunchyklown
Mar 28 2017 22:40
Next question, how do I get this field into presentable format?