Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions script_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/exec"
"regexp"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -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)
Expand All @@ -95,6 +100,8 @@ func runScripts(scripts []*Script) []*Measurement {
}(script)
}

wg.Wait()

for i := 0; i < len(scripts); i++ {
measurements = append(measurements, <-ch)
}
Expand Down Expand Up @@ -177,10 +184,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 +=
`<li><a href="/probe?name=` + script.Name + `">` + script.Name + "</a></li>\n"
}

http.Handle("/metrics", promhttp.Handler())
Expand All @@ -194,6 +204,11 @@ func main() {
<head><title>Script Exporter</title></head>
<body>
<h1>Script Exporter</h1>
<h2>Probes</h2>
<ul>
` + probePathLinks + `
</ul>
<h2>Metrics</h2>
<p><a href="` + *metricsPath + `">Metrics</a></p>
</body>
</html>`))
Expand Down