def check_for_new_tables(db, conf): results = [] for namespace in db.namespaces: tables = db.table_names(namespace) monitored_tables = Table.get_all_tables_per_namespace( db.dbsource, namespace) monitored_tables_names = set( [table.table_name for table in monitored_tables]) for table_name in tables: if table_name not in monitored_tables_names: table = Table.setup_for_source_table(db, table_name, namespace) if table: create_for_detected_table(db, table) for check in table.checks: if check.name == Metric.SCHEMA_CHANGE: MetricFromCheck.add_metrics( [ schema_changed_record( "table detected", None, None, None, conf) ], check, conf, )
def run_compute_alerts(db, conf): for namespace in db.namespaces: tables = Table.get_monitored_tables_per_namespace(db.name, namespace) for table in tables: run_compute_alerts_for_table(db, table, conf)
def run_checks(db, conf): for namespace in db.namespaces: tables = Table.get_monitored_tables_per_namespace(db.dbsource, namespace) for table in tables: run_checks_for_table(db, table, conf)
def create_dashboards(): grafana_api = GrafanaFace( auth=(settings.GF_SECURITY_ADMIN_USER, settings.GF_SECURITY_ADMIN_PASSWORD), host=f"{settings.GRAFANA_WEB_HOST}:{settings.GRAFANA_WEB_PORT}", ) create_source_in_grafana(grafana_api) create_notifcation_channels(grafana_api) dashboards = [] for db in DataSource.source_dbs(): monitored_tables = Table.get_monitored_tables(db.name) for table in monitored_tables: dash_data = create_dashboard_for_table(grafana_api, db, table) table.grafana_url = dash_data["dashboard"]["url"] dashboards.append(dash_data) metrics_session.commit() home_response = create_home_dashboard(grafana_api, dashboards) star_home_dashboard(grafana_api, home_response)