def list_trouble_stat(ns): conf = open_logdag_config(ns) amulog_conf = config.open_config(conf["database_amulog"]["source_conf"]) from . import trouble tm = trouble.init_trouble_manager(conf) from amulog import log_db ld = log_db.LogData(amulog_conf) gid_name = conf.get("database_amulog", "event_gid") from scipy.stats import entropy table = [[ "trouble_id", "group", "messages", "gids", "hosts", "events", "groups", "entropy_events", "entropy_groups" ]] for tr in tm: line = [] d_ev, d_gid, d_host = trouble.event_stat(tr, ld, gid_name) d_group = trouble.event_label(d_gid, ld, gid_name) ent_ev = entropy(list(d_ev.values()), base=2) ent_group = entropy( [sum([d_gid[gid] for gid in l_gid]) for l_gid in d_group.values()], base=2) line.append(tr.tid) line.append(tr.data["group"]) line.append(sum(d_gid.values())) # messages line.append(len(d_gid.keys())) # gids line.append(len(d_host.keys())) # hosts line.append(len(d_ev.keys())) # events line.append(len(d_group.keys())) # groups line.append(ent_ev) # entropy of events line.append(ent_group) # entropy of groups table.append(line) print(common.cli_table(table))
def show(self): table = [["name", "datetime", "area"]] for args in self.l_args: conf, dt_range, area = args temp = [ self.jobname(args), "{0} - {1}".format(dt_range[0], dt_range[1]), area ] table.append(temp) return common.cli_table(table, spl=" | ")
def show_list(ns): from . import showdag conf = open_logdag_config(ns) l_func = [ lambda r: r.graph.number_of_nodes(), lambda r: r.graph.number_of_edges() ] table = [] for key, _, data in showdag.stat_groupby(conf, l_func, groupby=ns.groupby): table.append([key] + list(data)) print(common.cli_table(table))
def show_snmp_stats(ns): conf = open_logdag_config(ns) dt_range = _whole_term(conf) from . import evgen_snmp el = evgen_snmp.SNMPEventLoader(conf) d_host, d_measure = evgen_snmp.survey_snmp_stats(el, dt_range) import numpy as np table = [["measure", "average"]] for measure, l_cnt in sorted(d_measure.items()): avg = int(np.average(l_cnt) + 0.5) table.append([measure, avg]) print(common.cli_table(table))
def list_group(ns): conf = open_logdag_config(ns) from . import trouble tm = trouble.init_trouble_manager(conf) d = defaultdict(list) for tr in tm: group = tr.data["group"] d[group].append(tr) table = [["group", "ticket", "messages"]] num_sum = 0 for group, l_tr in d.items(): num = sum([len(tr.data["message"]) for tr in l_tr]) # l_buf.append("{0}: {1} tickets ({2} messages)".format( # group, len(l_tr), num)) table.append([group, len(l_tr), num]) num_sum += num table.append(["total", sum([len(v) for v in d.values()]), num_sum]) print(common.cli_table(table))
def show_stats(ns): import numpy as np from . import showdag conf = open_logdag_config(ns) msg = [ "number of events (nodes)", "number of directed edges", "number of directed edges across hosts", "number of undirected edges", "number of undirected edges across hosts", "number of all edges" ] l_func = [ lambda r: r.graph.number_of_nodes(), lambda r: showdag.apply_filter(r, ["directed"]).number_of_edges(), lambda r: showdag.apply_filter(r, ["directed", "across_host"] ).number_of_edges(), lambda r: showdag.apply_filter(r, ["undirected"]).number_of_edges(), lambda r: showdag.apply_filter(r, ["undirected", "across_host"]). number_of_edges(), lambda r: r.graph.number_of_edges() ] data = [v for _, _, v in showdag.stat_groupby(conf, l_func)] agg_data = np.sum(data, axis=0) print(common.cli_table(list(zip(msg, agg_data)), align="right"))