From 2c9b57a0a085a215e37888e0e4617aac106dafcb Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Tue, 22 May 2012 12:15:31 +0200 Subject: [PATCH] Detect timeouts and errors in curl (such as resolver failures). --- ykval-munin-ksmlatency.php | 6 ++++++ ykval-munin-vallatency.php | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ykval-munin-ksmlatency.php b/ykval-munin-ksmlatency.php index 929fdf4..e43a88d 100755 --- a/ykval-munin-ksmlatency.php +++ b/ykval-munin-ksmlatency.php @@ -46,6 +46,12 @@ echo "multigraph yk_latency\n"; foreach ($ksms as $ksm) { $shortksm = url2shortname ($ksm); $time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`; + if (preg_match("/^3\./", $time)) { + $time = "timeout"; + } + if (preg_match("/^0\.000/", $time)) { + $time = "error"; + } echo "${shortksm}_avgwait.value $time\n"; } diff --git a/ykval-munin-vallatency.php b/ykval-munin-vallatency.php index dbf45c6..65baaa6 100755 --- a/ykval-munin-vallatency.php +++ b/ykval-munin-vallatency.php @@ -52,10 +52,16 @@ echo "multigraph ykval_latency\n"; foreach ($urls as $url) { $shortname = url2shortname ($url); $cmd = "--user-agent ykval-munin-vallatency/1.0 --silent --write-out '%{time_total}' --max-time 3 '$url' -o /dev/null"; - $ipv4time = `curl --ipv4 $cmd`; - echo "ipv4${shortname}_avgwait.value $ipv4time\n"; - $ipv6time = `curl --ipv6 $cmd`; - echo "ipv6${shortname}_avgwait.value $ipv6time\n"; + foreach (array('ipv4', 'ipv6') as $ipv) { + $time = `curl --$ipv $cmd`; + if (preg_match("/^3\./", $time)) { + $time = "timeout"; + } + if (preg_match("/^0\.000/", $time)) { + $time = "error"; + } + echo "$ipv${shortname}_avgwait.value $time\n"; + } } #%# family=auto