From: Noah Watkins Date: Wed, 18 Jul 2018 21:26:47 +0000 (-0700) Subject: mgr/crash: json report of recent crashes X-Git-Tag: v14.0.1~837^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=caa121b5f07273f5da0fee6625122488d865c5a8;p=ceph.git mgr/crash: json report of recent crashes reports crashes per entity type with hour granularity. primarily for consumption by the insights module. Signed-off-by: Noah Watkins --- diff --git a/src/pybind/mgr/crash/module.py b/src/pybind/mgr/crash/module.py index fb1ba3c8e6ed2..7b5b754421345 100644 --- a/src/pybind/mgr/crash/module.py +++ b/src/pybind/mgr/crash/module.py @@ -3,6 +3,7 @@ import datetime import errno import json import six +from collections import defaultdict DATEFMT = '%Y-%m-%d %H:%M:%S.%f' @@ -146,6 +147,31 @@ class Module(MgrModule): retlines.append(binstr(bindict)) return 0, '\n'.join(retlines), '' + def do_json_report(self, cmd, inbuf): + """ + Return a machine readable summary of recent crashes. + """ + try: + hours = int(cmd['hours']) + except ValueError: + return errno.EINVAL, '', ' argument must be integer' + + report = defaultdict(lambda: 0) + cutoff = datetime.datetime.utcnow() - datetime.timedelta(hours=hours) + for _, meta in self.timestamp_filter(lambda ts: ts >= cutoff): + try: + etype = meta["entity_name"] + etype, _ = etype.split(".") + etype = "unknown" if not etype else etype + except KeyError: + etype = "unknown" + except (ValueError, AttributeError): + etype = str(etype) + pass + report[etype] += 1 + + return 0, '', json.dumps(report) + def do_self_test(self, cmd, inbuf): # test time conversion timestr = '2018-06-22 20:35:38.058818Z' @@ -198,4 +224,10 @@ class Module(MgrModule): 'perm': 'r', 'handler': do_stat, }, + { + 'cmd': 'crash json_report name=hours,type=CephString', + 'desc': 'Crashes in the last hours', + 'perm': 'r', + 'handler': do_json_report, + }, ]