From ca71d12f290f1169a225e70b4418423afcbfc5e4 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Wed, 3 Aug 2016 12:49:53 +0200 Subject: [PATCH 1/3] added lxd memory plugin the lxd deamon provides a REST interface which can be queried by pylxd to get container related information. It stacks all containers, so the total memory footprint of lxd is visible. This plugin depends on python3 pylxd --- plugins/lxd/lxd_mem | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 plugins/lxd/lxd_mem diff --git a/plugins/lxd/lxd_mem b/plugins/lxd/lxd_mem new file mode 100755 index 00000000..9895133f --- /dev/null +++ b/plugins/lxd/lxd_mem @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +import sys +from pylxd import api + +c=api.API() + +if len(sys.argv) == 2: + if sys.argv[1]=="autoconf": + print("yes") + sys.exit(0) + elif sys.argv[1]=="config": + print("graph_title LXD container memory") + 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(): + print(name+".value "+str(c.container_info(name)['memory']['usage'])) From 46983fdc99f530476fd5c9abdf64b3be52ae3a9a Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Wed, 3 Aug 2016 12:50:28 +0200 Subject: [PATCH 2/3] added lxd disk plugin the lxd deamon provides a REST interface which can be queried by pylxd to get container related information. It graphs the disk usage of all disks in all containers. This plugin depends on python3 pylxd --- plugins/lxd/lxd_disk | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 plugins/lxd/lxd_disk diff --git a/plugins/lxd/lxd_disk b/plugins/lxd/lxd_disk new file mode 100755 index 00000000..b0e2671c --- /dev/null +++ b/plugins/lxd/lxd_disk @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import sys +from pylxd import api + +c=api.API() + +if len(sys.argv) == 2: + if sys.argv[1]=="autoconf": + print("yes") + sys.exit(0) + elif sys.argv[1]=="config": + print("graph_title LXD container disk usage") + print("graph_args --base 1000 --lower-limit 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 disk in c.container_info(name)['disk']: + print(name+"-"+disk+".value "+str(c.container_info(name)['disk'][disk]['usage'])) From 365e9932007b282b30fd10135c25e78d39866c83 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Wed, 3 Aug 2016 17:31:15 +0200 Subject: [PATCH 3/3] 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 | 54 +++++++++++++++++++++++++++++++------------- plugins/lxd/lxd_mem | 52 ++++++++++++++++++++++++++++++------------ 2 files changed, 75 insertions(+), 31 deletions(-) diff --git a/plugins/lxd/lxd_disk b/plugins/lxd/lxd_disk index b0e2671c..9e7c04f5 100755 --- a/plugins/lxd/lxd_disk +++ b/plugins/lxd/lxd_disk @@ -1,25 +1,47 @@ #!/usr/bin/python3 import sys -from pylxd import api -c=api.API() +errors=[] -if len(sys.argv) == 2: - if sys.argv[1]=="autoconf": +HAS_LIB=True +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") - sys.exit(0) - elif sys.argv[1]=="config": - print("graph_title LXD container disk usage") - print("graph_args --base 1000 --lower-limit 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) + 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") + 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 disk in c.container_info(name)['disk']: diff --git a/plugins/lxd/lxd_mem b/plugins/lxd/lxd_mem index 9895133f..6c797836 100755 --- a/plugins/lxd/lxd_mem +++ b/plugins/lxd/lxd_mem @@ -1,24 +1,46 @@ #!/usr/bin/python3 import sys -from pylxd import api -c=api.API() +errors=[] -if len(sys.argv) == 2: - if sys.argv[1]=="autoconf": +HAS_LIB=True +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") - sys.exit(0) - elif sys.argv[1]=="config": - print("graph_title LXD container memory") - 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) + 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 memory") + 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(): print(name+".value "+str(c.container_info(name)['memory']['usage']))