From 8b010aadbd4922cc81ef0086136767e26bd92c62 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Thu, 11 Aug 2016 11:56:57 +0200 Subject: [PATCH 1/2] fixed lxc_disk with stopped containers stopped containers have no disk space info and the plugin crashed. Now it only shows disk usage for running containers --- plugins/lxd/lxd_disk | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/lxd/lxd_disk b/plugins/lxd/lxd_disk index 9e7c04f5..16366557 100755 --- a/plugins/lxd/lxd_disk +++ b/plugins/lxd/lxd_disk @@ -38,11 +38,15 @@ if len(sys.argv) == 2 and sys.argv[1]=="config": 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") + info = c.container_info(name) + if info['disk']: + for disk in info['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'])) + info = c.container_info(name) + if info['disk']: + for disk in info['disk']: + print(name+"-"+disk+".value "+str(info['disk'][disk]['usage'])) From 3a48fa4eabf0341415b9f5a92ab9461337993390 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Mon, 17 Oct 2016 09:57:02 +0200 Subject: [PATCH 2/2] added explaining comment for extra if If no LXD disk information is present, the field is None instead of an empty list. Iterating over it directly would fail. --- plugins/lxd/lxd_disk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/lxd/lxd_disk b/plugins/lxd/lxd_disk index 16366557..04988bbc 100755 --- a/plugins/lxd/lxd_disk +++ b/plugins/lxd/lxd_disk @@ -10,7 +10,7 @@ try: except: HAS_LIB=False errors.append("no pylxd module") - + c=None HAS_ACCESS=True try: @@ -39,7 +39,9 @@ if len(sys.argv) == 2 and sys.argv[1]=="config": 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(): info = c.container_info(name) + # first check if disk information list is available or None if info['disk']: + # if no disk information is present, this would fail to iteration None for disk in info['disk']: print(name+"-"+disk+".label "+name) print(name+"-"+disk+".draw LINE2") @@ -47,6 +49,8 @@ if len(sys.argv) == 2 and sys.argv[1]=="config": for name in c.container_list(): info = c.container_info(name) + # first check if disk information list is available or None if info['disk']: + # if no disk information is present, this would fail to iteration None for disk in info['disk']: print(name+"-"+disk+".value "+str(info['disk'][disk]['usage']))