Skip to content

Commit

Permalink
Feature: Add output parameter (#3)
Browse files Browse the repository at this point in the history
* Add output parameter

* Adjust documentation for output parameter
  • Loading branch information
ricoberger authored Aug 24, 2018
1 parent 277bb0f commit 2f3b159
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ scripts:
## Prometheus configuration
The script exporter needs to be passed the script name as a parameter (`script`). You can also pass a custom prefix (`prefix`) and additional parameters which should be passed to the script (`params`).
The script exporter needs to be passed the script name as a parameter (`script`). You can also pass a custom prefix (`prefix`) and additional parameters which should be passed to the script (`params`). If the `output` parameter is set to `ignore` then the script exporter only return `script_success{}` and `script_duration_seconds{}`.

Example config:

Expand All @@ -115,6 +115,7 @@ scrape_configs:
script: [ping]
prefix: [script_ping]
params: [target]
output: [ignore]
static_configs:
- targets:
- example.com
Expand Down
7 changes: 7 additions & 0 deletions cmd/script_exporter/script_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func metricsHandler(w http.ResponseWriter, r *http.Request) {
return
}

// Get ignore output parameter and only return success and duration seconds if 'true'
outputParam := params.Get("output")
if outputParam == "ignore" {
fmt.Fprintf(w, "%s\n%s\n%s_success{} %d\n%s\n%s\n%s_duration_seconds{} %f\n", scriptSuccessHelp, scriptSuccessType, namespace, 1, scriptDurationSecondsHelp, scriptDurationSecondsType, namespace, time.Since(scriptStartTime).Seconds())
return
}

// Format output
regex1, _ := regexp.Compile("^" + prefix + "\\w*{.*}\\s+")
regex2, _ := regexp.Compile("^" + prefix + "\\w*{.*}\\s+[0-9|\\.]*")
Expand Down

0 comments on commit 2f3b159

Please sign in to comment.