summaryrefslogtreecommitdiffstats
path: root/kubernetes/contrib
diff options
context:
space:
mode:
authorNicolas Edel <nicolas.edel@orange.com>2018-11-23 08:42:21 +0100
committerNicolas Edel <nicolas.edel@orange.com>2018-11-23 08:46:44 +0100
commita7b2ee30e615a8567d953b644bc37ec07759fcdf (patch)
treeb487c54361b52292337a5b50e18be7daee1075f5 /kubernetes/contrib
parenta991cf5896ff87120d14e049600f72ad132d0265 (diff)
Better handling of wrong root directory spec
Also rename and use a .py extension Change-Id: I98d6820dc21faa27ae3dd88cfbe82a65d62d9ba4 Issue-ID: OOM-1527 Signed-off-by: Nicolas Edel <nicolas.edel@orange.com>
Diffstat (limited to 'kubernetes/contrib')
-rwxr-xr-xkubernetes/contrib/tools/oomstat.py (renamed from kubernetes/contrib/tools/oomstat)25
1 files changed, 18 insertions, 7 deletions
diff --git a/kubernetes/contrib/tools/oomstat b/kubernetes/contrib/tools/oomstat.py
index 82453b0a7c..464290d3f6 100755
--- a/kubernetes/contrib/tools/oomstat
+++ b/kubernetes/contrib/tools/oomstat.py
@@ -26,12 +26,16 @@ import getopt
from fnmatch import fnmatch as match
import yaml
+def info(thing):
+ if thing:
+ sys.stderr.write("{}\n".format(thing))
+
try:
from tabulate import tabulate
except ImportError as e:
- message = "Warning: cannot import tabulate module (): {}\n".format(str(e))
- sys.stderr.write(message)
+ info("Warning: cannot import tabulate module (): {}".format(str(e)))
def tabulate(lines, headers, tablefmt=None):
+ ''' basic tabulate function '''
fmt = ""
nbco = len(headers)
lenco = map(len, headers)
@@ -168,11 +172,11 @@ def usage(status=None):
" You may use wildcard patterns, eg small.*. Implicit\n"
" value is *, ie all available fields will be used\n"
"Examples:\n"
- " # oomstat /opt/oom/kubernetes\n"
- " # oomstat -f small.\\* /opt/oom/kubernetes\n"
- " # oomstat -f '*requests.*' -t fancy_grid /opt/oom/kubernetes\n"
- " # oomstat -f small.requests.cpu,small.requests.memory /opt/oom/kubernetes\n"
- ))
+ " # {0} /opt/oom/kubernetes\n"
+ " # {0} -f small.\\* /opt/oom/kubernetes\n"
+ " # {0} -f '*requests.*' -t fancy_grid /opt/oom/kubernetes\n"
+ " # {0} -f small.requests.cpu,small.requests.memory /opt/oom/kubernetes\n"
+ ).format(arg0))
if status is not None:
sys.exit(status)
@@ -209,10 +213,17 @@ def main():
print("Error: {}".format(e))
usage(1)
+ if not os.path.isdir(root):
+ info("Cannot open {}: Not a directory".format(root))
+ return
+
# find projects
projects = []
for dirname, filename in values(root):
projects.append(Project(dirname, filename))
+ if not projects:
+ info("No projects found in {} directory".format(root))
+ return
# check if we want to use pattern matching (wildcard only)
if fields and reduce(lambda x, y: x or y,