From f37cf35aa9b28ccc5bc74d0bf9674d86a56ec118 Mon Sep 17 00:00:00 2001 From: Konstantin Kornienko Date: Sun, 11 Jul 2021 19:28:32 +0300 Subject: [PATCH] Added timeout label --- README.md | 23 +++++++++++++---------- script_advanced_exporter.go | 7 +++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index d24e0c4..7eccdb8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Based on GitHub: https://github.com/adhocteam/script_exporter What was changed: - Added new metric `script_exit_code` -- Added labels `nagios_status` and `output` to all merics +- Added labels `nagios_status`, `timeout` and `output` to all merics Prometheus exporter written to execute and collect metrics on script exit status and duration. Designed to allow the execution of probes where support for the @@ -64,15 +64,18 @@ A regular expression may be specified with the `pattern` paremeter: `$ curl http://localhost:9172/probe?pattern=.*` ``` -script_duration_seconds{script="timeout"} 1.005727 -script_success{script="timeout"} 0 -script_exit_code{script="timeout"} 2 -script_duration_seconds{script="failure"} 2.015021 -script_success{script="failure"} 0 -script_exit_code{script="timeout"} 1 -script_duration_seconds{script="success"} 5.013670 -script_success{script="success"} 1 -script_exit_code{script="timeout"} 0 +script_duration_seconds{script="failure",nagios_status="CRITICAL",timeout="false",output="CRITICAL; failure"} 0.000973 +script_success{script="failure",nagios_status="CRITICAL",timeout="false",output="CRITICAL; failure"} 0 +script_exit_code{script="failure",nagios_status="CRITICAL",timeout="false",output="CRITICAL; failure"} 2 +script_duration_seconds{script="timeout",nagios_status="CRITICAL",timeout="true",output="Timeout running command"} 2.000661 +script_success{script="timeout",nagios_status="CRITICAL",timeout="true",output="Timeout running command"} 0 +script_exit_code{script="timeout",nagios_status="CRITICAL",timeout="true",output="Timeout running command"} 2 +script_duration_seconds{script="success_silent",nagios_status="OK"} 3.001741 +script_success{script="success_silent",nagios_status="OK"} 1 +script_exit_code{script="success_silent",nagios_status="OK"} 0 +script_duration_seconds{script="success",nagios_status="OK",output="OK; all is OK"} 3.001713 +script_success{script="success",nagios_status="OK",output="OK; all is OK"} 1 +script_exit_code{script="success",nagios_status="OK",output="OK; all is OK"} 0 ``` ## Design diff --git a/script_advanced_exporter.go b/script_advanced_exporter.go index 890ffbe..f8c3638 100644 --- a/script_advanced_exporter.go +++ b/script_advanced_exporter.go @@ -185,9 +185,8 @@ func scriptRunHandler(w http.ResponseWriter, r *http.Request, config *Config) { measurements := runScripts(scripts) for _, measurement := range measurements { - // prepare status + // prepare vars var status int - if measurement.ScriptResult.ExitCode == 0 { status = 1 } else { @@ -205,6 +204,10 @@ func scriptRunHandler(w http.ResponseWriter, r *http.Request, config *Config) { nagios_status, ) + if status == 0 { + fmt.Fprintf(&labels, ",timeout=\"%t\"", measurement.ScriptResult.Timeout) + } + stdout := formatStdOut(measurement.ScriptResult.Output) if len(stdout) > 0 { fmt.Fprintf(&labels, ",output=\"%s\"", stdout)