Révision 365e9932
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
| plugins/lxd/lxd_disk | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/python3 |
| 2 | 2 |
|
| 3 | 3 |
import sys |
| 4 |
from pylxd import api |
|
| 5 | 4 |
|
| 6 |
c=api.API()
|
|
| 5 |
errors=[]
|
|
| 7 | 6 |
|
| 8 |
if len(sys.argv) == 2: |
|
| 9 |
if sys.argv[1]=="autoconf": |
|
| 7 |
HAS_LIB=True |
|
| 8 |
try: |
|
| 9 |
from pylxd import api |
|
| 10 |
except: |
|
| 11 |
HAS_LIB=False |
|
| 12 |
errors.append("no pylxd module")
|
|
| 13 |
|
|
| 14 |
c=None |
|
| 15 |
HAS_ACCESS=True |
|
| 16 |
try: |
|
| 17 |
c=api.API() |
|
| 18 |
c.container_list() |
|
| 19 |
except: |
|
| 20 |
HAS_ACCESS=False |
|
| 21 |
errors.append("no socket access")
|
|
| 22 |
|
|
| 23 |
if len(sys.argv) == 2 and sys.argv[1]=="autoconf": |
|
| 24 |
if HAS_LIB and HAS_ACCESS: |
|
| 10 | 25 |
print("yes")
|
| 11 |
sys.exit(0) |
|
| 12 |
elif sys.argv[1]=="config": |
|
| 13 |
print("graph_title LXD container disk usage")
|
|
| 14 |
print("graph_args --base 1000 --lower-limit 0")
|
|
| 15 |
print("graph_vlabel Bytes")
|
|
| 16 |
print("graph_category lxd")
|
|
| 17 |
print("graph_info This shows the disk usage of storage in containers. Make sure to install pylxd in python3.")
|
|
| 18 |
for name in c.container_list(): |
|
| 19 |
for disk in c.container_info(name)['disk']: |
|
| 20 |
print(name+"-"+disk+".label "+name) |
|
| 21 |
print(name+"-"+disk+".draw LINE2") |
|
| 22 |
sys.exit(0) |
|
| 26 |
else: |
|
| 27 |
print("no ("+" and ".join(errors)+")")
|
|
| 28 |
sys.exit(0) |
|
| 29 |
|
|
| 30 |
if not (HAS_LIB and HAS_ACCESS): |
|
| 31 |
# pylxd not installed or lxd socket not accessible |
|
| 32 |
sys.exit(1) |
|
| 33 |
|
|
| 34 |
if len(sys.argv) == 2 and sys.argv[1]=="config": |
|
| 35 |
print("graph_title LXD container disk usage")
|
|
| 36 |
print("graph_args --base 1000 --lower-limit 0")
|
|
| 37 |
print("graph_vlabel Bytes")
|
|
| 38 |
print("graph_category lxd")
|
|
| 39 |
print("graph_info This shows the disk usage of storage in containers. Make sure to install pylxd in python3.")
|
|
| 40 |
for name in c.container_list(): |
|
| 41 |
for disk in c.container_info(name)['disk']: |
|
| 42 |
print(name+"-"+disk+".label "+name) |
|
| 43 |
print(name+"-"+disk+".draw LINE2") |
|
| 44 |
sys.exit(0) |
|
| 23 | 45 |
|
| 24 | 46 |
for name in c.container_list(): |
| 25 | 47 |
for disk in c.container_info(name)['disk']: |
| plugins/lxd/lxd_mem | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/python3 |
| 2 | 2 |
|
| 3 | 3 |
import sys |
| 4 |
from pylxd import api |
|
| 5 | 4 |
|
| 6 |
c=api.API()
|
|
| 5 |
errors=[]
|
|
| 7 | 6 |
|
| 8 |
if len(sys.argv) == 2: |
|
| 9 |
if sys.argv[1]=="autoconf": |
|
| 7 |
HAS_LIB=True |
|
| 8 |
try: |
|
| 9 |
from pylxd import api |
|
| 10 |
except: |
|
| 11 |
HAS_LIB=False |
|
| 12 |
errors.append("no pylxd module")
|
|
| 13 |
|
|
| 14 |
c=None |
|
| 15 |
HAS_ACCESS=True |
|
| 16 |
try: |
|
| 17 |
c=api.API() |
|
| 18 |
c.container_list() |
|
| 19 |
except: |
|
| 20 |
HAS_ACCESS=False |
|
| 21 |
errors.append("no socket access")
|
|
| 22 |
|
|
| 23 |
if len(sys.argv) == 2 and sys.argv[1]=="autoconf": |
|
| 24 |
if HAS_LIB and HAS_ACCESS: |
|
| 10 | 25 |
print("yes")
|
| 11 |
sys.exit(0) |
|
| 12 |
elif sys.argv[1]=="config": |
|
| 13 |
print("graph_title LXD container memory")
|
|
| 14 |
print("graph_args --base 1024 --lower-limit 0")
|
|
| 15 |
print("graph_vlabel Bytes")
|
|
| 16 |
print("graph_category lxd")
|
|
| 17 |
print("graph_info This shows the memory usage of each container. Make sure to install pylxd in python3.")
|
|
| 18 |
for name in c.container_list(): |
|
| 19 |
print(name+".label "+name) |
|
| 20 |
print(name+".draw AREASTACK") |
|
| 21 |
sys.exit(0) |
|
| 26 |
else: |
|
| 27 |
print("no ("+" and ".join(errors)+")")
|
|
| 28 |
sys.exit(0) |
|
| 29 |
|
|
| 30 |
if not (HAS_LIB and HAS_ACCESS): |
|
| 31 |
# pylxd not installed or lxd socket not accessible |
|
| 32 |
sys.exit(1) |
|
| 33 |
|
|
| 34 |
if len(sys.argv) == 2 and sys.argv[1]=="config": |
|
| 35 |
print("graph_title LXD container memory")
|
|
| 36 |
print("graph_args --base 1024 --lower-limit 0")
|
|
| 37 |
print("graph_vlabel Bytes")
|
|
| 38 |
print("graph_category lxd")
|
|
| 39 |
print("graph_info This shows the memory usage of each container. Make sure to install pylxd in python3.")
|
|
| 40 |
for name in c.container_list(): |
|
| 41 |
print(name+".label "+name) |
|
| 42 |
print(name+".draw AREASTACK") |
|
| 43 |
sys.exit(0) |
|
| 22 | 44 |
|
| 23 | 45 |
for name in c.container_list(): |
| 24 | 46 |
print(name+".value "+str(c.container_info(name)['memory']['usage'])) |
Formats disponibles : Unified diff