2016-08-03 12:50:28 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2016-08-03 17:31:15 +02:00
|
|
|
errors=[]
|
2016-08-03 12:50:28 +02:00
|
|
|
|
2016-08-03 17:31:15 +02:00
|
|
|
HAS_LIB=True
|
|
|
|
try:
|
|
|
|
from pylxd import api
|
|
|
|
except:
|
|
|
|
HAS_LIB=False
|
|
|
|
errors.append("no pylxd module")
|
2016-10-17 09:57:02 +02:00
|
|
|
|
2016-08-03 17:31:15 +02:00
|
|
|
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:
|
2016-08-03 12:50:28 +02:00
|
|
|
print("yes")
|
2016-08-03 17:31:15 +02:00
|
|
|
else:
|
|
|
|
print("no ("+" and ".join(errors)+")")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if not (HAS_LIB and HAS_ACCESS):
|
|
|
|
# pylxd not installed or lxd socket not accessible
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1]=="config":
|
|
|
|
print("graph_title LXD container disk usage")
|
|
|
|
print("graph_args --base 1000 --lower-limit 0")
|
|
|
|
print("graph_vlabel Bytes")
|
2017-02-22 16:22:46 +01:00
|
|
|
print("graph_category virtualization")
|
2016-08-03 17:31:15 +02:00
|
|
|
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():
|
2016-08-11 11:56:57 +02:00
|
|
|
info = c.container_info(name)
|
2016-10-17 09:57:02 +02:00
|
|
|
# first check if disk information list is available or None
|
2016-08-11 11:56:57 +02:00
|
|
|
if info['disk']:
|
2016-10-17 09:57:02 +02:00
|
|
|
# if no disk information is present, this would fail to iteration None
|
2016-08-11 11:56:57 +02:00
|
|
|
for disk in info['disk']:
|
|
|
|
print(name+"-"+disk+".label "+name)
|
|
|
|
print(name+"-"+disk+".draw LINE2")
|
2016-08-03 17:31:15 +02:00
|
|
|
sys.exit(0)
|
2016-08-03 12:50:28 +02:00
|
|
|
|
|
|
|
for name in c.container_list():
|
2016-08-11 11:56:57 +02:00
|
|
|
info = c.container_info(name)
|
2016-10-17 09:57:02 +02:00
|
|
|
# first check if disk information list is available or None
|
2016-08-11 11:56:57 +02:00
|
|
|
if info['disk']:
|
2016-10-17 09:57:02 +02:00
|
|
|
# if no disk information is present, this would fail to iteration None
|
2016-08-11 11:56:57 +02:00
|
|
|
for disk in info['disk']:
|
|
|
|
print(name+"-"+disk+".value "+str(info['disk'][disk]['usage']))
|