Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rico Berger authored and Rico Berger committed Aug 10, 2018
0 parents commit 0b9fee5
Show file tree
Hide file tree
Showing 31 changed files with 10,458 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 4
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
################################
############ macOS #############
################################

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


################################
####### VisualStudioCode #######
################################

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json


################################
############## Go ##############
################################

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out


################################
############ Custom ############
################################

# Build directory
bin
15 changes: 15 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.1"

[prune]
go-tests = true
unused-packages = true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Rico Berger

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.
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
WHAT := script_exporter
BUILDTIME := $(shell date +%FT%T%Z)
VERSION=`git describe --tags`
BUILDUSER := $(shell id -un)

.PHONY: build build-darwin-amd64 build-linux-amd64 build-windows-amd64

build:
for target in $(WHAT); do \
go build -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${git rev-parse HEAD} \
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \
-o ./bin/$$target ./cmd/$$target; \
done

build-darwin-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${git rev-parse HEAD} \
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \
-o ./bin/$$target-${VERSION}-darwin-amd64 ./cmd/$$target; \
done

build-linux-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${git rev-parse HEAD} \
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \
-o ./bin/$$target-${VERSION}-linux-amd64 ./cmd/$$target; \
done

build-windows-amd64:
for target in $(WHAT); do \
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -a -installsuffix cgo -ldflags "-X github.com/ricoberger/script_exporter/pkg/version.GitCommit=${git rev-parse HEAD} \
-X github.com/ricoberger/script_exporter/pkg/version.Version=${VERSION} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildTime=${BUILDTIME} \
-X github.com/ricoberger/script_exporter/pkg/version.BuildUser=${BUILDUSER}" \
-o ./bin/$$target-${VERSION}-windows-amd64.exe ./cmd/$$target; \
done
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# script_exporter

The script exporter is a [Prometheus](https://prometheus.io) exporter to execute scripts and collect metrics from the output or the exit status. The scripts to be executed are defined via a configuration file. In the configuration file several scripts can be specified. The script which should be executed is indicated by a parameter in the scrap configuration. The output of the script is captured and is provided for Prometheus. Even if the script does not produce any output, the exit status and the duration of the execution are provided.

## Building and running

Prerequisites:

- [Go compiler](https://golang.org/dl/)

Building:

```
git clone https://github.com/ricoberger/script_exporter.git $GOPATH/src/github.com/ricoberger/script_exporter
cd $GOPATH/src/github.com/ricoberger/script_exporter
dep ensure
make build
```

Running:

```
./bin/script_exporter
```

Then visit [http://localhost:9469/metrics?script=test](http://localhost:9469/metrics?script=test) in the browser of your choice. There you should see the following output:

```
test_success{} 1
test_duration_seconds{} 0.005626
# First test
test_first_test{label="test_1_label_1"} 1
# Second test
test_second_test{label="test_2_label_1",label="test_2_label_2"} 2.71828182846
# Third test
test_third_test{} 3.14159265359
```

## Usage and configuration

The script exporter is configured via a configuration file and command-line flags.

```
Usage of ./bin/script_exporter:
-config.file string
Configuration file in YAML format. (default "config.yaml")
-config.shell string
Shell to execute script (default "/bin/sh")
-version
Show version information.
-web.listen-address string
Address to listen on for web interface and telemetry. (default ":9469")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
```

The configuration file is written in YAML format, defined by the scheme described below.

```yaml
scripts:
[ - <script_config> ... ]

# script_config
name: <string>
script: <string>
```
## Prometheus configuration
The script exporter needs to be passed the script name as a parameter (`script`). You can also pass a custom prefix. If the `prefix` parameter is missing `script` will be used as prefix.

Example config:

```yaml
scrape_configs:
- job_name: 'script_test'
metrics_path: /metrics
params:
script: [test]
prefix: [script]
static_configs:
- targets:
- 127.0.0.1
relabel_configs:
- target_label: script
replacement: test
```

## Dependencies

- [yaml.v2 - YAML support for the Go language](gopkg.in/yaml.v2)
Loading

0 comments on commit 0b9fee5

Please sign in to comment.