def create_home_dashboard(grafana_api, dashboards): home_data = load_json_data(settings.HOME_DASHBOARD_LOCATION) panels = home_data['panels'] for panel in panels: if panel['title'] in [ 'new_records_created (in last 24h)', 'time_since_last_record_created' ]: panel['savedOverrides'] = generate_overrides(dashboards) # native polystat logic for column/row auto scalling works strange panel['polystat']['columns'] = get_best_column_count( len(dashboards)) if panel['title'] == 'new_records_created (in last 24h)': update_home_panel_element(panel, HomeLastDayTraffic) if panel['title'] == 'time_since_last_record_created': update_home_panel_element(panel, HomeLastModifiedTime) if panel['title'] == 'recent_alerts': update_home_panel_element(panel, HomeAlerts) response = grafana_api.dashboard.update_dashboard(dashboard={ 'dashboard': home_data, 'folderID': 0, 'overwrite': True }) print(f"Dashboard for home generated:", response) return response
def create_home_dashboard(grafana_api, dashboards): home_data = load_json_data(settings.HOME_DASHBOARD_LOCATION) panels = home_data["panels"] for panel in panels: if panel["title"] in [ "new_records_created (in last 24h)", "time_since_last_record_created", ]: panel["savedOverrides"] = generate_overrides(dashboards) # native polystat logic for column/row auto scalling works strange panel["polystat"]["columns"] = get_best_column_count(len(dashboards)) if panel["title"] == "new_records_created (in last 24h)": update_home_panel_element(panel, HomeLastDayTraffic) if panel["title"] == "time_since_last_record_created": update_home_panel_element(panel, HomeLastModifiedTime) if panel["title"] == "RECENT ALERTS": update_home_panel_element(panel, HomeAlerts) response = grafana_api.dashboard.update_dashboard( dashboard={"dashboard": home_data, "folderID": 0, "overwrite": True} ) print(f"Dashboard for home generated:", response) return response
def generate_overrides(dashboards): override_list = [] for dashboard in dashboards: override = load_json_data(settings.HOME_OVERRIDES_LOCATION) override["clickThrough"] = dashboard["dashboard"]["url"] override["metricName"] = dashboard["table"].table_name override["label"] = dashboard["table"].table_name override_list.append(override) return override_list
def generate_overrides(dashboards): override_list = [] for dashboard in dashboards: override = load_json_data(settings.HOME_OVERRIDES_LOCATION) override['clickThrough'] = dashboard['dashboard']['url'] override['metricName'] = dashboard['table'].table_name override['label'] = dashboard['table'].table_name override_list.append(override) return override_list
def get_dashboard_for_table(db, table): table_data = load_json_data(settings.TABLE_DASHBOARD_LOCATION) panels = table_data['panels'] per_title = dict([(panel.title(), panel) for panel in ALL_PANELS]) table_data[ 'title'] = f"source: {db.name} table: {table.table_name} (generated)" for panel in panels: if per_title.get(panel['title']): panel = update_panel_element(table, panel, per_title[panel['title']]) next_id = 20 y_pos = 20 x_pos = 0 check_per_column = {} checks = [ch for ch in table.checks if ch.name not in Metric.TABLE_METRICS] check_per_column = checks[0].metrics #TODO support for more checks here for column_name in sorted(check_per_column.keys()): if x_pos != 0: x_pos = 0 y_pos += 7 panel = load_json_data(settings.CUSTOM_ROW_LOCATION) panel['title'] = f"{column_name} column" panel['id'] = next_id panel['gridPos']["y"] = y_pos panel['gridPos']["x"] = x_pos next_id += 1 y_pos += 1 panels.append(panel) metrics = check_per_column[column_name] for metric_name in metrics: panel = load_json_data(settings.CUSTOM_PANEL_LOCATION) panel['title'] = f"{metric_name}" panel['id'] = next_id panel['gridPos']["y"] = y_pos panel['gridPos']["x"] = x_pos next_id += 1 if x_pos == 0: x_pos += 12 else: x_pos = 0 y_pos += 7 panel = update_panel_element(table, panel, CheckForColumn, column=column_name, metric=metric_name) panels.append(panel) return table_data
def get_dashboard_for_table(db, table): table_data = load_json_data(settings.TABLE_DASHBOARD_LOCATION) panels = table_data["panels"] per_title = dict([(panel.title(), panel) for panel in ALL_PANELS]) table_data["title"] = f"{db.name.upper()}:{table.full_table_name.upper()}" for panel in panels: if per_title.get(panel["title"]): panel = update_panel_element(table, panel, per_title[panel["title"]]) next_id = 20 y_pos = 20 x_pos = 0 check_per_column = {} metric_per_column = get_all_metrics_for_table(table) for column_name, metrics in metric_per_column.items(): if x_pos != 0: x_pos = 0 y_pos += 7 if column_name == Metric.TABLE_METRIC: # We display those metrics in different places metrics.remove(Metric.COUNT) metrics.remove(Metric.SCHEMA_CHANGE) metrics.remove(Metric.DELAY) title = "CUSTOM TABLE STATS" else: title = f"COL:{column_name.upper()}" if len(metrics) == 0: continue panel = load_json_data(settings.CUSTOM_ROW_LOCATION) panel["title"] = title panel["id"] = next_id panel["gridPos"]["y"] = y_pos panel["gridPos"]["x"] = x_pos next_id += 1 y_pos += 1 panels.append(panel) for metric_name in metrics: panel = load_json_data(settings.CUSTOM_PANEL_LOCATION) panel["title"] = f"{metric_name.upper()}" panel["id"] = next_id panel["gridPos"]["y"] = y_pos panel["gridPos"]["x"] = x_pos next_id += 1 if x_pos == 0: x_pos += 12 else: x_pos = 0 y_pos += 7 panel = update_panel_element(table, panel, CheckForColumn, column=column_name, metric=metric_name) panels.append(panel) return table_data
def get_dashboard_for_table(db, table): table_data = load_json_data(settings.TABLE_DASHBOARD_LOCATION) panels = table_data['panels'] per_title = dict([(panel.title(), panel) for panel in ALL_PANELS]) table_data[ 'title'] = f"source: {db.name} table: {table.table_name} (generated)" for panel in panels: if per_title.get(panel['title']): panel = update_panel_element(table, panel, per_title[panel['title']]) all_checks = metrics_db.execute(f""" SELECT DISTINCT column_name, check_name FROM metrics_data_values WHERE table_id = '{table.id}' """) next_id = 20 y_pos = 20 x_pos = 0 check_per_column = {} for column_name, check_name in all_checks: if column_name not in check_per_column: check_per_column[column_name] = [check_name] else: check_per_column[column_name].append(check_name) for column_name in sorted(check_per_column.keys()): if x_pos != 0: x_pos = 0 y_pos += 7 panel = load_json_data(settings.CUSTOM_ROW_LOCATION) panel['title'] = f"{column_name} column" panel['id'] = next_id panel['gridPos']["y"] = y_pos panel['gridPos']["x"] = x_pos next_id += 1 y_pos += 1 panels.append(panel) checks = check_per_column[column_name] for check_name in checks: panel = load_json_data(settings.CUSTOM_PANEL_LOCATION) panel['title'] = f"{check_name}" panel['id'] = next_id panel['gridPos']["y"] = y_pos panel['gridPos']["x"] = x_pos next_id += 1 if x_pos == 0: x_pos += 12 else: x_pos = 0 y_pos += 7 if check_name != 'check_count_per_value': panel = update_panel_element(table, panel, CheckForColumn, column_name=column_name, check_name=check_name) else: panel = update_panel_element(table, panel, CheckForColumnByValue, column_name=column_name, check_name=check_name, time_interval='1 day') panels.append(panel) return table_data