From 980fe2c9670ac6c66036b41f4eb09ffdbef3ce27 Mon Sep 17 00:00:00 2001 From: andrewm4894 Date: Mon, 30 Dec 2024 13:36:15 +0000 Subject: [PATCH] Add support for additional Netdata instances and improve error handling in ingestion functions --- metrics/examples/netdata/netdata.py | 15 ++++++++++++++- metrics/examples/netdata/netdata.yaml | 2 -- .../netdata_httpcheck/netdata_httpcheck.py | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/metrics/examples/netdata/netdata.py b/metrics/examples/netdata/netdata.py index 87c2241..0571a76 100644 --- a/metrics/examples/netdata/netdata.py +++ b/metrics/examples/netdata/netdata.py @@ -18,6 +18,14 @@ def ingest() -> pd.DataFrame: ("london.my-netdata.io", "system.cpu", "-600", "0"), ("london.my-netdata.io", "system.io", "-600", "0"), ("london.my-netdata.io", "system.ram", "-600", "0"), + ("bangalore.my-netdata.io", "system.net", "-600", "0"), + ("bangalore.my-netdata.io", "system.cpu", "-600", "0"), + ("bangalore.my-netdata.io", "system.io", "-600", "0"), + ("bangalore.my-netdata.io", "system.ram", "-600", "0"), + ("frankfurt.my-netdata.io", "system.net", "-600", "0"), + ("frankfurt.my-netdata.io", "system.cpu", "-600", "0"), + ("frankfurt.my-netdata.io", "system.io", "-600", "0"), + ("frankfurt.my-netdata.io", "system.ram", "-600", "0"), ] urls = [ @@ -26,7 +34,12 @@ def ingest() -> pd.DataFrame: ] df = pd.DataFrame() for url, (host, chart, _, _) in zip(urls, inputs): - res = requests.get(url) + try: + res = requests.get(url, timeout=10) + res.raise_for_status() + except requests.exceptions.RequestException as e: + logger.error(f"Failed to fetch data from {url}: {e}") + continue data = res.text.split("\r\n") cols = data[0].split(",") values = data[1].split(",") diff --git a/metrics/examples/netdata/netdata.yaml b/metrics/examples/netdata/netdata.yaml index 54e78b1..2f0a797 100644 --- a/metrics/examples/netdata/netdata.yaml +++ b/metrics/examples/netdata/netdata.yaml @@ -11,5 +11,3 @@ disable_llmalert: False alert_methods: "email,slack" ingest_fn: > {% include "./examples/netdata/netdata.py" %} -change_exclude_metrics: -- london__system_io_reads diff --git a/metrics/examples/netdata_httpcheck/netdata_httpcheck.py b/metrics/examples/netdata_httpcheck/netdata_httpcheck.py index 651be57..83f6093 100644 --- a/metrics/examples/netdata_httpcheck/netdata_httpcheck.py +++ b/metrics/examples/netdata_httpcheck/netdata_httpcheck.py @@ -64,7 +64,12 @@ def ingest() -> pd.DataFrame: ] df = pd.DataFrame() for url, (host, chart, _, _) in zip(urls, inputs): - res = requests.get(url) + try: + res = requests.get(url, timeout=10) + res.raise_for_status() + except requests.exceptions.RequestException as e: + logger.error(f"Failed to fetch data from {url}: {e}") + continue data = res.text.split("\r\n") cols = data[0].split(",") cols[0] = "metric_timestamp"