Public Repository

Last pushed: 9 months ago
Short Description
Run shell scripts, get prometheus metrics
Full Description

Script Exporter

GitHub: https://github.com/adhocteam/script_exporter

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
probe type wasn't easily configured with the Prometheus blackbox exporter.

Sample Configuration

scripts:
  - name: success
    script: sleep 5

  - name: failure
    script: sleep 2 && exit 1

  - name: timeout
    script: sleep 5
    timeout: 1

Running

You can run via docker with:

docker run -d -p 9172:9172 --name script-exporter \
  -v `pwd`/config.yml:/etc/script-exporter/config.yml:ro \
  -config.file=/etc/script-exporter/config.yml
  -web.listen-address=":9172" \
  -web.telemetry-path="/metrics" \
  -config.shell="/bin/sh" \
  adhocteam/script-exporter:master

You'll need to customize the docker image or use the binary on the host system
to install tools such as curl for certain scenarios.

Output

$ curl http://localhost:9172/metrics

...
# HELP script_failure_duration_seconds Duration for configured scripts with non-zero exit status
# TYPE script_failure_duration_seconds histogram
script_failure_duration_seconds_bucket{script="failure",le="0.005"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.01"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.025"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.05"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.1"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.25"} 0
script_failure_duration_seconds_bucket{script="failure",le="0.5"} 0
script_failure_duration_seconds_bucket{script="failure",le="1"} 0
script_failure_duration_seconds_bucket{script="failure",le="2.5"} 2
script_failure_duration_seconds_bucket{script="failure",le="5"} 2
script_failure_duration_seconds_bucket{script="failure",le="10"} 2
script_failure_duration_seconds_bucket{script="failure",le="+Inf"} 2
script_failure_duration_seconds_sum{script="failure"} 4.023167148
script_failure_duration_seconds_count{script="failure"} 2
script_failure_duration_seconds_bucket{script="timeout",le="0.005"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.01"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.025"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.05"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.1"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.25"} 0
script_failure_duration_seconds_bucket{script="timeout",le="0.5"} 0
script_failure_duration_seconds_bucket{script="timeout",le="1"} 0
script_failure_duration_seconds_bucket{script="timeout",le="2.5"} 2
script_failure_duration_seconds_bucket{script="timeout",le="5"} 2
script_failure_duration_seconds_bucket{script="timeout",le="10"} 2
script_failure_duration_seconds_bucket{script="timeout",le="+Inf"} 2
script_failure_duration_seconds_sum{script="timeout"} 2.003301153
script_failure_duration_seconds_count{script="timeout"} 2
# HELP script_success_duration_seconds Duration for configured scripts with zero exit status
# TYPE script_success_duration_seconds histogram
script_success_duration_seconds_bucket{script="success",le="0.005"} 0
script_success_duration_seconds_bucket{script="success",le="0.01"} 0
script_success_duration_seconds_bucket{script="success",le="0.025"} 0
script_success_duration_seconds_bucket{script="success",le="0.05"} 0
script_success_duration_seconds_bucket{script="success",le="0.1"} 0
script_success_duration_seconds_bucket{script="success",le="0.25"} 0
script_success_duration_seconds_bucket{script="success",le="0.5"} 0
script_success_duration_seconds_bucket{script="success",le="1"} 0
script_success_duration_seconds_bucket{script="success",le="2.5"} 0
script_success_duration_seconds_bucket{script="success",le="5"} 0
script_success_duration_seconds_bucket{script="success",le="10"} 2
script_success_duration_seconds_bucket{script="success",le="+Inf"} 2
script_success_duration_seconds_sum{script="success"} 10.025329418
script_success_duration_seconds_count{script="success"} 2

Design

The script exporter adds script_failure_duration_seconds and
script_success_duration_seconds histograms configured with the default buckets
to the default prometheus handler metrics available at /metrics. When Prometheus
scrapes the target all scripts are executed with sh and the observations are
included in the output.

YMMV if you're attempting to execute a large number of scripts, and you'd be
better off creating an exporter that can handle your protocol without launching
shell processes for each scrape.

Docker Pull Command
Owner
adhocteam

Comments (0)