Switch ipv6_edge_router to quagga #8
4 changed files with 93 additions and 0 deletions
|
@ -30,4 +30,26 @@
|
||||||
loop:
|
loop:
|
||||||
- bgpd.service
|
- bgpd.service
|
||||||
- zebra.service
|
- zebra.service
|
||||||
|
|
||||||
|
- name: Install quagga prometheus exporter
|
||||||
|
template:
|
||||||
|
src: '{{ item.src }}'
|
||||||
|
dest: '{{ item.dest }}'
|
||||||
|
mode: '{{ item.mode }}'
|
||||||
|
loop:
|
||||||
|
- src: 'quagga.py.j2'
|
||||||
|
dest: '/usr/share/prometheus-node-exporter/quagga.py
|
||||||
|
mode: "0755"
|
||||||
|
- src: prometheus-node-exporter-quagga.service
|
||||||
|
dest: /etc/systemd/system/prometheus-node-exporter-quagga.service
|
||||||
|
mode: "0644"
|
||||||
|
- src: prometheus-node-exporter-quagga.timer
|
||||||
|
dest: /etc/systemd/system/prometheus-node-exporter-quagga.timer
|
||||||
|
mode: "0644"
|
||||||
|
|
||||||
|
- name: Enable node-exporter
|
||||||
|
service:
|
||||||
|
name: prometheus-node-exporter.service
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
...
|
...
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Collect quagga metrics for prometheus-node-exporter
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/bash -c "/usr/share/prometheus-node-exporter/quagga.py | sponge /var/lib/prometheus/node-exporter/quagga.prom"
|
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Run quagga metrics collection every 15 minutes
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=0
|
||||||
|
OnUnitActiveSec=15min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
56
roles/ipv6_edge_router/templates/quagga.py.j2
Executable file
56
roles/ipv6_edge_router/templates/quagga.py.j2
Executable file
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def parse_bgp_summary(summary):
|
||||||
|
header = 'Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd\n'
|
||||||
|
res = {'routes': 0, 'uptime': 0}
|
||||||
|
try:
|
||||||
|
index = summary.index(header) + len(header)
|
||||||
|
except ValueError:
|
||||||
|
return res
|
||||||
|
summary = summary[index:]
|
||||||
|
match = re.match(r'(?P<neighbor>[^\s\n])+\n?\s+(?P<version>4)\s+(?P<as>\d{1,5})\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(?P<uptime>[^\s]+)\s+(?P<routes>\d+)\n', summary)
|
||||||
|
if match is None:
|
||||||
|
return res
|
||||||
|
res['routes'] = int(match.group('routes'))
|
||||||
|
uptime = match.group('uptime')
|
||||||
|
if re.fullmatch(r'[0-9]+:[0-9]+:[0-9]+', uptime) is not None:
|
||||||
|
uptime = line[8].split(':')
|
||||||
|
uptime = int(uptime[0])*3600 + int(uptime[1])*60 + int(uptime[2])
|
||||||
|
else:
|
||||||
|
uptime_match = re.fullmatch(r'([0-9]+)d([0-9]+)h([0-9]+)m', uptime)
|
||||||
|
if uptime_match is not None:
|
||||||
|
uptime = int(uptime_match.group(1))*86400 + int(uptime_match.group(2))*3600 + int(uptime_match.group(3))*60
|
||||||
|
else:
|
||||||
|
uptime_match = re.fullmatch(r'([0-9]+)w([0-9]+)d([0-9]+)h', uptime)
|
||||||
|
if uptime_match is not None:
|
||||||
|
uptime = int(uptime_match.group(1))*604800 + int(uptime_match.group(2))*86400 + int(uptime_match.group(3))*3600
|
||||||
|
else:
|
||||||
|
uptime_match = re.fullmatch(r'([0-9]+)y([0-9]+)w([0-9]+)d', uptime)
|
||||||
|
if uptime_match is not None:
|
||||||
|
uptime = int(uptime_match.group(1))*220752000 + int(uptime_match.group(2))*604800 + int(uptime_match.group(3))*86400
|
||||||
|
else:
|
||||||
|
uptime = 0
|
||||||
|
res['uptime'] = uptime
|
||||||
|
return res
|
||||||
|
|
||||||
|
def prompt(version='ipv4'):
|
||||||
|
summary = subprocess.run(['/usr/bin/vtysh', '-c', f'show bgp {version} unicast summary'], capture_output=True).stdout.decode('utf-8')
|
||||||
|
bgp_routes_uptime = parse_bgp_summary(bgp_ipv4_unicast_summary)
|
||||||
|
routes = bgp_routes_uptime['routes']
|
||||||
|
uptime = bgp_routes_uptime['uptime']
|
||||||
|
print(f'# HELP quagga_bgp_{version}_routes Number of {version} routes added by quagga')
|
||||||
|
print(f'# TYPE quagga_bgp_{version}_routes gauge')
|
||||||
|
print(f'quagga_bgp_{version}_routes {routes}')
|
||||||
|
print(f'# HELP quagga_bgp_{version}_uptime {version} BGP connection uptime')
|
||||||
|
print(f'# TYPE quagga_bgp_{version}_uptime gauge')
|
||||||
|
print(f'quagga_bgp_{version}_uptime {uptime}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
prompt('ipv4')
|
||||||
|
prompt('ipv6')
|
Loading…
Reference in a new issue