From a400629f3587cbb990e6db1392075b33dd3750a7 Mon Sep 17 00:00:00 2001 From: Claudio Ramirez Date: Fri, 3 Jan 2020 18:09:23 +0100 Subject: [PATCH 1/2] List probes on / page --- script_exporter.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/script_exporter.go b/script_exporter.go index badabcc..2668757 100644 --- a/script_exporter.go +++ b/script_exporter.go @@ -177,10 +177,13 @@ func main() { log.Infof("Loaded %d script configurations", len(config.Scripts)) + var probePathLinks string for _, script := range config.Scripts { if script.Timeout == 0 { script.Timeout = 15 } + probePathLinks += + `
  • `+script.Name+"
  • \n" } http.Handle("/metrics", promhttp.Handler()) @@ -194,6 +197,11 @@ func main() { Script Exporter

    Script Exporter

    +

    Probes

    + +

    Metrics

    Metrics

    `)) From b8154570fd94a0829bceb993113819661df85fcb Mon Sep 17 00:00:00 2001 From: Claudio Ramirez Date: Tue, 31 Mar 2020 17:22:34 +0200 Subject: [PATCH 2/2] wait for tests to finish or timeout before returning a 200 page --- script_exporter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/script_exporter.go b/script_exporter.go index 2668757..c5d0be3 100644 --- a/script_exporter.go +++ b/script_exporter.go @@ -11,6 +11,7 @@ import ( "os" "os/exec" "regexp" + "sync" "time" "github.com/prometheus/client_golang/prometheus" @@ -69,12 +70,16 @@ func runScript(script *Script) error { } func runScripts(scripts []*Script) []*Measurement { + var wg sync.WaitGroup + measurements := make([]*Measurement, 0) ch := make(chan *Measurement) for _, script := range scripts { + wg.Add(1) go func(script *Script) { + defer wg.Done() start := time.Now() success := 0 err := runScript(script) @@ -95,6 +100,8 @@ func runScripts(scripts []*Script) []*Measurement { }(script) } + wg.Wait() + for i := 0; i < len(scripts); i++ { measurements = append(measurements, <-ch) } @@ -183,7 +190,7 @@ func main() { script.Timeout = 15 } probePathLinks += - `
  • `+script.Name+"
  • \n" + `
  • ` + script.Name + "
  • \n" } http.Handle("/metrics", promhttp.Handler())