Mercurial > code > home > repos > infra
changeset 119:51a471fa4d29
metrics on dnsmasq log errors and DHCP commands
author | drewp@bigasterisk.com |
---|---|
date | Wed, 07 Dec 2022 23:03:57 -0800 |
parents | 69058ad170be |
children | 661af5652dfa |
files | dns.py templates/dnsmasq/dnsmasq-mtail.service.j2 templates/dnsmasq/metrics.mtail.j2 templates/dnsmasq/run_mtail.sh |
diffstat | 4 files changed, 68 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dns.py Wed Dec 07 23:02:57 2022 -0800 +++ b/dns.py Wed Dec 07 23:03:57 2022 -0800 @@ -42,6 +42,13 @@ dhcp_range='10.2.0.121,10.2.0.200', router='10.2.0.3', dhcp_hosts_filename='templates/dnsmasq/dhcp_hosts.j2') + out = '/opt/dnsmasq/10.2' + # This mtail is for dhcp command counts and errors. Another monitor in lanscape/ reads the leases file. + files.template(src='templates/dnsmasq/metrics.mtail.j2', dest=f'{out}/metrics.mtail') + files.template(src='templates/dnsmasq/run_mtail.sh', dest=f'{out}/run_mtail.sh') + + files.template(src='templates/dnsmasq/dnsmasq-mtail.service.j2', dest=f'/etc/systemd/system/dnsmasq-mtail.service') + systemd.service(service=f'dnsmasq-mtail', enabled=True, restarted=True, daemon_reload=True) else: pass
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/dnsmasq/dnsmasq-mtail.service.j2 Wed Dec 07 23:03:57 2022 -0800 @@ -0,0 +1,13 @@ +# written by pyinfra + +[Unit] +Description=dnsmasq-mtail for 10.2 network +After=dnsmasq_10.2.service + +[Service] +Type=simple + +ExecStart=zsh /opt/dnsmasq/10.2/run_mtail.sh + +[Install] +WantedBy=multi-user.target
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/dnsmasq/metrics.mtail.j2 Wed Dec 07 23:03:57 2022 -0800 @@ -0,0 +1,37 @@ +counter dnsmasq_no_addr_errors +/no address available/ { + dnsmasq_no_addr_errors++ +} + +counter dnsmasq_dhcp_requests +/DHCPREQUEST/ { + dnsmasq_dhcp_requests++ +} + +counter dnsmasq_dhcp_acks +/DHCPACK/ { + dnsmasq_dhcp_acks++ +} + +counter dnsmasq_dhcp_discovers +/DHCPDISCOVER/ { + dnsmasq_dhcp_discovers++ +} + +counter dnsmasq_dhcp_offers +/DHCPOFFER/ { + dnsmasq_dhcp_offers++ +} + +gauge dnsmasq_dns_queries_answered_locally +gauge dnsmasq_dns_queries_forwarded by server +gauge dnsmasq_dns_queries_retried_or_failed by server + +/queries forwarded (?P<fwd>\d+), queries answered locally (?P<loc>\d+)/ { + dnsmasq_dns_queries_answered_locally = $loc +} + +/server (?P<svr>\S+)#53: queries sent (?P<sent>\d+), retried or failed (?P<fail>\d+)/ { + dnsmasq_dns_queries_forwarded[$svr] = $sent + dnsmasq_dns_queries_retried_or_failed[$svr] = $fail +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/dnsmasq/run_mtail.sh Wed Dec 07 23:03:57 2022 -0800 @@ -0,0 +1,11 @@ +#!/bin/zsh +STATS_PERIOD=2m +while (true) { pkill --signal USR1 --oldest --full /usr/sbin/dnsmasq; sleep ${STATS_PERIOD} } & + +rm -f /tmp/dnsmasq_log_pipe +mkfifo /tmp/dnsmasq_log_pipe + +{ journalctl -fu dnsmasq_10.2.service > /tmp/dnsmasq_log_pipe } & + +mtail -port 9991 -logtostderr -logs /tmp/dnsmasq_log_pipe -progs /opt/dnsmasq/10.2 +#-disable_fsnotify -poll_interval ${STATS_PERIOD} \ No newline at end of file