root / plugins / lxd / lxd_mem @ 365e9932
Historique | Voir | Annoter | Télécharger (1,1 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 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) |
| 44 |
|
| 45 |
for name in c.container_list(): |
| 46 |
print(name+".value "+str(c.container_info(name)['memory']['usage'])) |
