root / plugins / lxd / lxd_disk @ 365e9932
Historique | Voir | Annoter | Télécharger (1,24 ko)
| 1 |
#!/usr/bin/python3 |
|---|---|
| 2 |
|
| 3 |
import sys |
| 4 |
|
| 5 |
errors=[] |
| 6 |
|
| 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: |
| 25 |
print("yes")
|
| 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) |
| 45 |
|
| 46 |
for name in c.container_list(): |
| 47 |
for disk in c.container_info(name)['disk']: |
| 48 |
print(name+"-"+disk+".value "+str(c.container_info(name)['disk'][disk]['usage'])) |
