From da72f062bbfdabaafece6c466df222a23e70b7c6 Mon Sep 17 00:00:00 2001 From: Niklas Yann Wettengel Date: Sun, 22 Jul 2018 13:14:46 +0200 Subject: updated influx-scripts --- .../templates/ffmyk-influx/dhcp.php.j2 | 70 ++++++++++++++++++---- 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2') diff --git a/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 b/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 index 7b81328..4d3773b 100644 --- a/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 +++ b/roles/install_monitoring/templates/ffmyk-influx/dhcp.php.j2 @@ -1,23 +1,73 @@ $dend) $clients++; +while(($line = fgets($lease_file_handle)) !== false) +{ + if(preg_match('/lease ([\d]+\.[\d]+\.[\d]+\.[\d]+)/', $line, $match)) + { + $lease = ip2long($match[1]); + continue; + } + elseif(preg_match('/starts \d ([\d]{4})\/([\d]{2})\/([\d]{2}) ([\d]{2}):([\d]{2}):([\d]{2})/', $line, $match)) + { + $start = mktime($match[4], $match[5], $match[6], $match[2], $match[3], $match[1]); + continue; + } + elseif(preg_match('/ends \d ([\d]{4})\/([\d]{2})\/([\d]{2}) ([\d]{2}):([\d]{2}):([\d]{2})/', $line, $match)) + { + $end = mktime($match[4], $match[5], $match[6], $match[2], $match[3], $match[1]); + if($lease > 0 && $start > 0 && $end > 0) + { + if( $start < time() && $end > time() ) + { + $activeleases[$lease] = $lease; + $lease = -1; + $start = -1; + $end = -1; + } } + } +} - $data = 'clients,host={{ ansible_hostname }},type=backend value='.$clients; - sendflux($data); +$pools = array(); +for($range = 0; $range < $num_ranges; $range++) +{ + $clients = 0; + + $range_start = ip2long($ranges[1][$range]); + $range_end = ip2long($ranges[2][$range]); + foreach($activeleases as $lease) + { + if( $lease > $range_start && $lease < $range_end ) + { + $clients++; + } + } + + $pools[$range_start] = $clients; +} + +$data = ""; + +foreach($pools as $range => $clients) +{ + $data .= 'clients,host={{ ansible_hostname }},pool='.long2ip($range).',type=backend value='.$clients."\n"; +} + +sendflux($data); ?> -- cgit v1.2.3-54-g00ecf