From d66aa45e7adab2e68f07aa387010ce40ab310765 Mon Sep 17 00:00:00 2001 From: Vladimir Kotal Date: Tue, 16 May 2023 17:43:10 +0200 Subject: [PATCH] record duration after which scrape was cancelled --- collector/collector.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/collector/collector.go b/collector/collector.go index f2f09956..09ab0c10 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -162,10 +162,12 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log config.WalkParams.ConfigureSNMP(&snmp) // Do the actual walk. + getInitialStart := time.Now() err := snmp.Connect() if err != nil { if err == context.Canceled { - return results, fmt.Errorf("scrape canceled (possible timeout) connecting to target %s", snmp.Target) + return results, fmt.Errorf("scrape cancelled after %s (possible timeout) connecting to target %s", + time.Since(getInitialStart), snmp.Target) } return results, fmt.Errorf("error connecting to target %s: %s", target, err) } @@ -220,7 +222,8 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log packet, err := snmp.Get(getOids[:oids]) if err != nil { if err == context.Canceled { - return results, fmt.Errorf("scrape canceled (possible timeout) getting target %s", snmp.Target) + return results, fmt.Errorf("scrape cancelled after %s (possible timeout) getting target %s", + time.Since(getInitialStart), snmp.Target) } return results, fmt.Errorf("error getting target %s: %s", snmp.Target, err) } @@ -257,7 +260,8 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log } if err != nil { if err == context.Canceled { - return results, fmt.Errorf("scrape canceled (possible timeout) walking target %s", snmp.Target) + return results, fmt.Errorf("scrape canceled after %s (possible timeout) walking target %s", + time.Since(getInitialStart), snmp.Target) } return results, fmt.Errorf("error walking target %s: %s", snmp.Target, err) }