From dfc77a2f4d9d9d4870d33ee01f747d6aa28113cc Mon Sep 17 00:00:00 2001 From: Cyberes Date: Fri, 21 Apr 2023 23:54:20 -0600 Subject: [PATCH] silence error??? --- check_speedtest.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/check_speedtest.py b/check_speedtest.py index 8903113..c45417d 100755 --- a/check_speedtest.py +++ b/check_speedtest.py @@ -2,6 +2,7 @@ import argparse import sys import traceback +import warnings from cloudflarepycli import cloudflareclass @@ -22,7 +23,16 @@ def main(): parser.add_argument('--critical-latency', type=int, default=100, help='Critical level of latency in ms.') args = parser.parse_args() - speedtest_results = cloudflareclass.cloudflare(printit=False).runalltests() + # Silence this error: + """ + lib/python3.10/site-packages/numpy/core/fromnumeric.py:3464: RuntimeWarning: Mean of empty slice. + return _methods._mean(a, axis=axis, dtype=dtype, + lib/python3.10/site-packages/numpy/core/_methods.py:192: RuntimeWarning: invalid value encountered in scalar divide + ret = ret.dtype.type(ret / rcount) + """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=RuntimeWarning) + speedtest_results = cloudflareclass.cloudflare(printit=False).runalltests() out_str = f"upload: {speedtest_results['90th_percentile_upload_speed']['value']} Mbps, download: {speedtest_results['90th_percentile_download_speed']['value']} Mbps, latency: {speedtest_results['latency_ms']['value']} ms, Jitter: {speedtest_results['Jitter_ms']['value']} ms" perf_data = f"'upload'={speedtest_results['90th_percentile_upload_speed']['value'] * 1e+6}B;{args.warn_up * 1e+6};{args.critical_up * 1e+6};0; 'download'={speedtest_results['90th_percentile_download_speed']['value'] * 1e+6}B;{args.warn_down * 1e+6};{args.critical_down * 1e+6};0; 'latency_ms'={speedtest_results['latency_ms']['value']}ms;{args.warn_latency};{args.critical_latency};0; 'Jitter_ms'={speedtest_results['Jitter_ms']['value']}ms;;;0;"