collectd: add dhcpcount for *-gw

This commit is contained in:
Astro 2020-05-15 17:59:32 +02:00
parent c3e3eadfb3
commit 88b011772f
6 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,5 @@
collectd:
network: client
interface: True
conntrack: True
dhcpcount: True

View File

@ -14,10 +14,13 @@ base:
- dhcp
- bird.radv
- bird.ospf
- collectd.gw
'pub-gw or serv-gw or radio-gw':
- dhcp
- bird.radv
- bird.ospf
'pub-gw':
- collectd.gw
'c3d2-gw or c3d2-anon or mgmt-gw':
- bird.ospf
'c3d2-gw':

View File

@ -38,6 +38,12 @@ LoadPlugin ping
Interval 10
</Plugin>
{%- elif plugin == 'dhcpcount' and conf is True %}
LoadPlugin exec
<Plugin exec>
Exec "collectd" "/usr/bin/dhcpcount.rb"
</Plugin>
{%- elif conf is mapping %}
LoadPlugin {{ plugin }}

View File

@ -0,0 +1,31 @@
#!/usr/bin/env ruby
require 'date'
hostname = `hostname`.strip
loop do
starts = nil
ends = nil
count = 0
IO::readlines("/var/lib/dhcp/dhcpd.leases").each do |line|
if line =~ /^lease/
starts = nil
ends = nil
elsif line =~ /starts \d+ (.+?);/
starts = DateTime.parse $1
elsif line =~ /ends \d+ (.+?);/
ends = DateTime.parse $1
elsif line =~ /^\}/
now = DateTime.now
if starts and ends and
starts <= now and ends >= now
count += 1
end
end
end
puts "PUTVAL #{hostname}/dhcpd/leases N:#{count}"
sleep 10
end

View File

@ -15,3 +15,10 @@ collectd:
file.managed:
- source: salt://collectd/collectd.conf
- template: 'jinja'
{%- if pillar['collectd'].get('dhcpcount') %}
/usr/bin/dhcpcount.rb:
file.managed:
- source: salt://collectd/dhcpcount.rb
- mode: 755
{%- endif %}

View File

@ -13,6 +13,7 @@ base:
- forwarding
- bird
- dhcp
- collectd
'priv13-gw':
- firewall.priv-stateful
'pub-gw or serv-gw':
@ -20,6 +21,8 @@ base:
- forwarding
- bird
- dhcp
'pub-gw':
- collectd
'c3d2-gw or c3d2-anon or mgmt-gw':
- no-ssh
- forwarding