mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
olsrd: adjustments for the output format used by olsrd v0.9.5
Changes include: * use short names for "urls" (e.g. "lin" instead of "links") * whitespace instead of semicolon used as separators in "mid" * ignore variable number of header lines
This commit is contained in:
parent
6d758e9fb7
commit
a8d117a3f0
1 changed files with 32 additions and 22 deletions
|
@ -140,16 +140,21 @@ def query_olsrd_txtservice(section=""):
|
||||||
request = bytes("/%s" % section)
|
request = bytes("/%s" % section)
|
||||||
conn.sendall(request)
|
conn.sendall(request)
|
||||||
fconn = conn.makefile()
|
fconn = conn.makefile()
|
||||||
# "enumerate" is not suitable since it reads all lines at once (not a generator in micropython)
|
in_header = True
|
||||||
index = 0
|
in_body_count = 0
|
||||||
for line in fconn.readlines():
|
for line in fconn.readlines():
|
||||||
# skip the first five lines - they are headers
|
if in_header:
|
||||||
if index < 5:
|
if not line.strip():
|
||||||
index += 1
|
# the empty line marks the end of the header
|
||||||
continue
|
in_header = False
|
||||||
|
# ignore header lines (nothing to be done)
|
||||||
|
else:
|
||||||
|
# skip the first two body lines - they are table headers
|
||||||
|
if in_body_count >= 2:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line:
|
if line:
|
||||||
yield line
|
yield line
|
||||||
|
in_body_count += 1
|
||||||
fconn.close()
|
fconn.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@ -159,15 +164,17 @@ def get_address_device_mapping():
|
||||||
for line in query_olsrd_txtservice("mid"):
|
for line in query_olsrd_txtservice("mid"):
|
||||||
# example line content:
|
# example line content:
|
||||||
# 192.168.2.171 192.168.22.171;192.168.12.171
|
# 192.168.2.171 192.168.22.171;192.168.12.171
|
||||||
device_id, mids = line.split()
|
# since olsr v0.9.5:
|
||||||
for mid in mids.split(";"):
|
# 192.168.2.171 192.168.22.171 192.168.12.171
|
||||||
|
device_id, mids = line.split(None, 1)
|
||||||
|
for mid in mids.replace(";", " ").split():
|
||||||
mapping[mid] = device_id
|
mapping[mid] = device_id
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
|
|
||||||
def count_routes_by_neighbour(address_mapping, ignore_list):
|
def count_routes_by_neighbour(address_mapping, ignore_list):
|
||||||
node_count = {}
|
node_count = {}
|
||||||
for line in query_olsrd_txtservice("routes"):
|
for line in query_olsrd_txtservice("rou"):
|
||||||
# example line content:
|
# example line content:
|
||||||
# 192.168.1.79/32 192.168.12.38 4 4.008 wlan0
|
# 192.168.1.79/32 192.168.12.38 4 4.008 wlan0
|
||||||
tokens = line.split()
|
tokens = line.split()
|
||||||
|
@ -192,8 +199,12 @@ def get_olsr_links():
|
||||||
hna_list = [line.split()[0] for line in query_olsrd_txtservice("hna")]
|
hna_list = [line.split()[0] for line in query_olsrd_txtservice("hna")]
|
||||||
route_count = count_routes_by_neighbour(mid_mapping, hna_list)
|
route_count = count_routes_by_neighbour(mid_mapping, hna_list)
|
||||||
result = []
|
result = []
|
||||||
for line in query_olsrd_txtservice("links"):
|
for line in query_olsrd_txtservice("lin"):
|
||||||
tokens = line.split()
|
tokens = line.split()
|
||||||
|
# the "cost" may be infinite
|
||||||
|
if tokens[-1] == "INFINITE":
|
||||||
|
# "inf" is the python keyword for "maximum float number"
|
||||||
|
tokens[-1] = "inf"
|
||||||
link = {}
|
link = {}
|
||||||
link["local"] = tokens.pop(0)
|
link["local"] = tokens.pop(0)
|
||||||
remote = tokens.pop(0)
|
remote = tokens.pop(0)
|
||||||
|
@ -217,7 +228,7 @@ def _read_file(filename):
|
||||||
|
|
||||||
def get_ping_times(hosts):
|
def get_ping_times(hosts):
|
||||||
tempfile = "/tmp/munin-olsrd-{pid}.tmp".format(pid=os.getpid())
|
tempfile = "/tmp/munin-olsrd-{pid}.tmp".format(pid=os.getpid())
|
||||||
command = 'for host in {hosts}; do echo -n "$host "; ping -c 1 -w 1 "$host" | grep /avg/ || true; done >{tempfile}'\
|
command = 'for host in {hosts}; do echo -n "$host "; ping -c 1 -w 1 "$host" | grep /avg/ || echo; done >{tempfile}'\
|
||||||
.format(hosts=" ".join(hosts), tempfile=tempfile)
|
.format(hosts=" ".join(hosts), tempfile=tempfile)
|
||||||
# micropython supports only "os.system" (as of 2015) - thus we need to stick with it for openwrt
|
# micropython supports only "os.system" (as of 2015) - thus we need to stick with it for openwrt
|
||||||
returncode = os.system(command)
|
returncode = os.system(command)
|
||||||
|
@ -331,17 +342,16 @@ if __name__ == "__main__":
|
||||||
ping_times = get_ping_times([link["remote"] for link in links])
|
ping_times = get_ping_times([link["remote"] for link in links])
|
||||||
for link in links:
|
for link in links:
|
||||||
ping_time = ping_times.get(link["remote"], None)
|
ping_time = ping_times.get(link["remote"], None)
|
||||||
if ping_time is not None:
|
value = "{:.4f}".format(ping_time) if ping_time is not None else "U"
|
||||||
print("neighbour_{remote}.value {value:.4f}"
|
print("neighbour_{remote}.value {value}"
|
||||||
.format(value=ping_time,
|
.format(value=value, remote=get_clean_fieldname(link["remote"])))
|
||||||
remote=get_clean_fieldname(link["remote"])))
|
|
||||||
# single detailed graphs for the ping time of each link
|
# single detailed graphs for the ping time of each link
|
||||||
for link in links:
|
for link in links:
|
||||||
ping_time = ping_times.get(link["remote"], None)
|
ping_time = ping_times.get(link["remote"], None)
|
||||||
if ping_time is not None:
|
value = "{:.4f}".format(ping_time) if ping_time is not None else "U"
|
||||||
remote = get_clean_fieldname(link["remote"])
|
remote = get_clean_fieldname(link["remote"])
|
||||||
print("multigraph olsr_neighbour_ping.host_{remote}".format(remote=remote))
|
print("multigraph olsr_neighbour_ping.host_{remote}".format(remote=remote))
|
||||||
print("neighbour_{remote}.value {value:.4f}".format(remote=remote, value=ping_time))
|
print("neighbour_{remote}.value {value}".format(remote=remote, value=value))
|
||||||
|
|
||||||
# final marker for shell / python hybrid script (see "Interpreter Selection")
|
# final marker for shell / python hybrid script (see "Interpreter Selection")
|
||||||
EOF = True
|
EOF = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue