-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f03116a
Showing
21 changed files
with
482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.build/ | ||
.tarballs/ | ||
|
||
!.build/linux-amd64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
go: | ||
cgo: true | ||
repository: | ||
path: github.com/adhocteam/script_exporter | ||
build: | ||
flags: -a -tags 'netgo static_build' | ||
ldflags: | | ||
-linkmode external -extldflags -static | ||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}} | ||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}} | ||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}} | ||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}} | ||
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}} | ||
tarball: | ||
files: | ||
- LICENSE | ||
crossbuild: | ||
platforms: | ||
- linux/amd64 | ||
# - linux/386 | ||
# - darwin/amd64 | ||
# - darwin/386 | ||
# - windows/amd64 | ||
# - windows/386 | ||
# - netbsd/amd64 | ||
# - netbsd/386 | ||
# - linux/arm | ||
# - linux/arm64 | ||
# - netbsd/arm | ||
# - linux/ppc64 | ||
# - linux/ppc64le |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM quay.io/prometheus/busybox:latest | ||
MAINTAINER James Kassemi (Ad Hoc, LLC) <[email protected]> | ||
|
||
COPY script-exporter /bin/script-exporter | ||
COPY script-exporter.yml /etc/script-exporter/config.yml | ||
|
||
EXPOSE 9172 | ||
ENTRYPOINT [ "/bin/script-exporter" ] | ||
CMD ["-config.file=/etc/script-exporter/config.yml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The MIT License (MIT) | ||
Copyright (c) 2016 Ad Hoc, LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2015 The Prometheus Authors | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
GO := GO15VENDOREXPERIMENT=1 go | ||
PROMU := $(GOPATH)/bin/promu | ||
pkgs = $(shell $(GO) list ./... | grep -v /vendor/) | ||
|
||
PREFIX ?= $(shell pwd) | ||
BIN_DIR ?= $(shell pwd) | ||
DOCKER_IMAGE_NAME ?= adhocteam/script-exporter | ||
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) | ||
|
||
|
||
all: format build test | ||
|
||
style: | ||
@echo ">> checking code style" | ||
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' | ||
|
||
test: | ||
@echo ">> running tests" | ||
@$(GO) test -short $(pkgs) | ||
|
||
format: | ||
@echo ">> formatting code" | ||
@$(GO) fmt $(pkgs) | ||
|
||
vet: | ||
@echo ">> vetting code" | ||
@$(GO) vet $(pkgs) | ||
|
||
build: promu | ||
@echo ">> building binaries" | ||
@$(PROMU) build --prefix $(PREFIX) | ||
|
||
tarball: promu | ||
@echo ">> building release tarball" | ||
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR) | ||
|
||
crossbuild: promu | ||
@echo ">> building" | ||
@$(PROMU) crossbuild | ||
|
||
docker: | ||
@echo ">> building docker image" | ||
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" . | ||
|
||
release: | ||
@$(PROMU) crossbuild tarballs | ||
@$(PROMU) release .tarballs | ||
|
||
promu: | ||
@GOOS=$(shell uname -s | tr A-Z a-z) \ | ||
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \ | ||
$(GO) get -u github.com/prometheus/promu | ||
|
||
|
||
.PHONY: all style format build crossbuild test vet tarball docker promu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# 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 | ||
|
||
```yaml | ||
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_duration_seconds Duration for configured scripts with zero exit status | ||
# TYPE script_duration_seconds histogram | ||
script_duration_seconds_bucket{script="failure",le="0.005"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.01"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.025"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.05"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.1"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.25"} 0 | ||
script_duration_seconds_bucket{script="failure",le="0.5"} 0 | ||
script_duration_seconds_bucket{script="failure",le="1"} 0 | ||
script_duration_seconds_bucket{script="failure",le="2.5"} 1 | ||
script_duration_seconds_bucket{script="failure",le="5"} 1 | ||
script_duration_seconds_bucket{script="failure",le="10"} 1 | ||
script_duration_seconds_bucket{script="failure",le="+Inf"} 1 | ||
script_duration_seconds_sum{script="failure"} 2.014404206 | ||
script_duration_seconds_count{script="failure"} 1 | ||
script_duration_seconds_bucket{script="success",le="0.005"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.01"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.025"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.05"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.1"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.25"} 0 | ||
script_duration_seconds_bucket{script="success",le="0.5"} 0 | ||
script_duration_seconds_bucket{script="success",le="1"} 0 | ||
script_duration_seconds_bucket{script="success",le="2.5"} 0 | ||
script_duration_seconds_bucket{script="success",le="5"} 0 | ||
script_duration_seconds_bucket{script="success",le="10"} 1 | ||
script_duration_seconds_bucket{script="success",le="+Inf"} 1 | ||
script_duration_seconds_sum{script="success"} 5.015765115 | ||
script_duration_seconds_count{script="success"} 1 | ||
script_duration_seconds_bucket{script="timeout",le="0.005"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.01"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.025"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.05"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.1"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.25"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="0.5"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="1"} 0 | ||
script_duration_seconds_bucket{script="timeout",le="2.5"} 1 | ||
script_duration_seconds_bucket{script="timeout",le="5"} 1 | ||
script_duration_seconds_bucket{script="timeout",le="10"} 1 | ||
script_duration_seconds_bucket{script="timeout",le="+Inf"} 1 | ||
script_duration_seconds_sum{script="timeout"} 1.001585331 | ||
script_duration_seconds_count{script="timeout"} 1 | ||
# HELP script_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which script_exporter was built. | ||
# TYPE script_exporter_build_info gauge | ||
script_exporter_build_info{branch="",goversion="go1.7.3",revision="",version=""} 1 | ||
# 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"} 1 | ||
script_failure_duration_seconds_bucket{script="failure",le="5"} 1 | ||
script_failure_duration_seconds_bucket{script="failure",le="10"} 1 | ||
script_failure_duration_seconds_bucket{script="failure",le="+Inf"} 1 | ||
script_failure_duration_seconds_sum{script="failure"} 2.014404206 | ||
script_failure_duration_seconds_count{script="failure"} 1 | ||
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"} 1 | ||
script_failure_duration_seconds_bucket{script="timeout",le="5"} 1 | ||
script_failure_duration_seconds_bucket{script="timeout",le="10"} 1 | ||
script_failure_duration_seconds_bucket{script="timeout",le="+Inf"} 1 | ||
script_failure_duration_seconds_sum{script="timeout"} 1.001585331 | ||
script_failure_duration_seconds_count{script="timeout"} 1 | ||
``` | ||
|
||
## Design | ||
|
||
The script exporter adds `script_failure_duration_seconds` and | ||
`script_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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
scripts: | ||
- name: 'success' | ||
script: sleep 5 | ||
|
||
- name: 'failure' | ||
script: sleep 2 && exit 1 | ||
|
||
- name: 'timeout' | ||
script: sleep 5 | ||
timeout: 1 |
Oops, something went wrong.