def get_graph_data_from_livestatus(only_sites, host_name, service_description): columns = ["perf_data", "metrics", "check_command"] query = livestatus_lql([host_name], columns, service_description) what = "host" if service_description == "_HOST_" else "service" labels = ["site"] + ["%s_%s" % (what, col) for col in columns] with sites.only_sites(only_sites), sites.prepend_site(): info = dict(zip(labels, sites.live().query_row(query))) info["host_name"] = host_name if what == "service": info["service_description"] = service_description return info
def get_graph_data_from_livestatus(only_sites, host_name, service_description): columns = [u'perf_data', u'metrics', u'check_command'] query = livestatus_lql([host_name], columns, service_description) what = 'host' if service_description == "_HOST_" else 'service' labels = [u"site"] + [u"%s_%s" % (what, col) for col in columns] with sites.only_sites(only_sites), sites.prepend_site(): info = dict(zip(labels, sites.live().query_row(query))) info['host_name'] = host_name if what == 'service': info['service_description'] = service_description return info
def fetch_rrd_data(site, host_name, service_description, entries, graph_recipe, graph_data_range): start_time, end_time = graph_data_range["time_range"] step: Union[int, float, str] = graph_data_range["step"] # assumes str step is well formatted, colon separated step length & rrd point count if not isinstance(step, str): step = max(1, step) point_range = ":".join(map(str, (start_time, end_time, step))) lql_columns = list(rrd_columns(entries, graph_recipe["consolidation_function"], point_range)) query = livestatus_lql([host_name], lql_columns, service_description) with sites.only_sites(site): return list(zip(entries, sites.live().query_row(query)))
def livestatus_query_for_rrd_data(host_name, service_description, metric_cols, default_cf, point_range): lql_columns = [] for nr, (perfvar, cf, scale) in enumerate(metric_cols): if default_cf: cf = default_cf else: cf = cf or u"max" rpn = u"%s.%s" % (perfvar, cf) if scale != 1.0: rpn += u",%f,*" % scale lql_columns.append(u"rrddata:m%d:%s:%s" % (nr, rpn, point_range)) return livestatus_lql([host_name], lql_columns, service_description)
def fetch_rrd_data( site: SiteId, host_name: HostName, service_description: ServiceName, metrics: set[MetricProperties], graph_recipe: GraphRecipe, graph_data_range: GraphDataRange, ) -> list[tuple[MetricProperties, TimeSeriesValues]]: start_time, end_time = graph_data_range["time_range"] step = graph_data_range["step"] # assumes str step is well formatted, colon separated step length & rrd point count if not isinstance(step, str): step = max(1, step) point_range = ":".join(map(str, (start_time, end_time, step))) lql_columns = list( rrd_columns(metrics, graph_recipe["consolidation_function"], point_range)) query = livestatus_lql([host_name], lql_columns, service_description) with sites.only_sites(site): return list(zip(metrics, sites.live().query_row(query)))
def test_livestatus_lql(args, result): assert prediction.livestatus_lql(*args) == result