1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-26 02:48:28 +00:00

corrected lxd_ autoconf with proper checks

the autoconf now checks for availablity of the pylxd module and access
to the lxd socket. this ensures that the module will work properly. On
failure, helpful errors are displayed
This commit is contained in:
Felix Engelmann 2016-08-03 17:31:15 +02:00
parent 46983fdc99
commit 365e993200
2 changed files with 75 additions and 31 deletions

View file

@ -1,25 +1,47 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
from pylxd import api
c=api.API() errors=[]
if len(sys.argv) == 2: HAS_LIB=True
if sys.argv[1]=="autoconf": try:
from pylxd import api
except:
HAS_LIB=False
errors.append("no pylxd module")
c=None
HAS_ACCESS=True
try:
c=api.API()
c.container_list()
except:
HAS_ACCESS=False
errors.append("no socket access")
if len(sys.argv) == 2 and sys.argv[1]=="autoconf":
if HAS_LIB and HAS_ACCESS:
print("yes") print("yes")
sys.exit(0) else:
elif sys.argv[1]=="config": print("no ("+" and ".join(errors)+")")
print("graph_title LXD container disk usage") sys.exit(0)
print("graph_args --base 1000 --lower-limit 0")
print("graph_vlabel Bytes") if not (HAS_LIB and HAS_ACCESS):
print("graph_category lxd") # pylxd not installed or lxd socket not accessible
print("graph_info This shows the disk usage of storage in containers. Make sure to install pylxd in python3.") sys.exit(1)
for name in c.container_list():
for disk in c.container_info(name)['disk']: if len(sys.argv) == 2 and sys.argv[1]=="config":
print(name+"-"+disk+".label "+name) print("graph_title LXD container disk usage")
print(name+"-"+disk+".draw LINE2") print("graph_args --base 1000 --lower-limit 0")
sys.exit(0) print("graph_vlabel Bytes")
print("graph_category lxd")
print("graph_info This shows the disk usage of storage in containers. Make sure to install pylxd in python3.")
for name in c.container_list():
for disk in c.container_info(name)['disk']:
print(name+"-"+disk+".label "+name)
print(name+"-"+disk+".draw LINE2")
sys.exit(0)
for name in c.container_list(): for name in c.container_list():
for disk in c.container_info(name)['disk']: for disk in c.container_info(name)['disk']:

View file

@ -1,24 +1,46 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
from pylxd import api
c=api.API() errors=[]
if len(sys.argv) == 2: HAS_LIB=True
if sys.argv[1]=="autoconf": try:
from pylxd import api
except:
HAS_LIB=False
errors.append("no pylxd module")
c=None
HAS_ACCESS=True
try:
c=api.API()
c.container_list()
except:
HAS_ACCESS=False
errors.append("no socket access")
if len(sys.argv) == 2 and sys.argv[1]=="autoconf":
if HAS_LIB and HAS_ACCESS:
print("yes") print("yes")
sys.exit(0) else:
elif sys.argv[1]=="config": print("no ("+" and ".join(errors)+")")
print("graph_title LXD container memory") sys.exit(0)
print("graph_args --base 1024 --lower-limit 0")
print("graph_vlabel Bytes") if not (HAS_LIB and HAS_ACCESS):
print("graph_category lxd") # pylxd not installed or lxd socket not accessible
print("graph_info This shows the memory usage of each container. Make sure to install pylxd in python3.") sys.exit(1)
for name in c.container_list():
print(name+".label "+name) if len(sys.argv) == 2 and sys.argv[1]=="config":
print(name+".draw AREASTACK") print("graph_title LXD container memory")
sys.exit(0) print("graph_args --base 1024 --lower-limit 0")
print("graph_vlabel Bytes")
print("graph_category lxd")
print("graph_info This shows the memory usage of each container. Make sure to install pylxd in python3.")
for name in c.container_list():
print(name+".label "+name)
print(name+".draw AREASTACK")
sys.exit(0)
for name in c.container_list(): for name in c.container_list():
print(name+".value "+str(c.container_info(name)['memory']['usage'])) print(name+".value "+str(c.container_info(name)['memory']['usage']))