├── .gitignore ├── .travis.yml ├── Dockerfile ├── README.md ├── glide.yaml ├── main.go └── main_test.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .idea 3 | 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.dll 7 | *.so 8 | *.dylib 9 | 10 | # Test binary, build with `go test -c` 11 | *.test 12 | 13 | *.out 14 | 15 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 16 | .glide/ 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.7.x 5 | - master 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.8 2 | 3 | WORKDIR /go/src/app 4 | COPY . . 5 | RUN go-wrapper download 6 | RUN go-wrapper install 7 | EXPOSE 9116 8 | CMD ["go-wrapper", "run"] # ["app"] 9 | 10 | # Once 17.05 has arrived 11 | #FROM alpine:latest 12 | #RUN apk --no-cache add ca-certificates 13 | #WORKDIR /root/ 14 | #COPY --from= as builder /go/app . 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Json Exporter 2 |  3 | [](https://hub.docker.com/r/tolleiv/json-exporter/) 4 | 5 | This Prometheus exporter operates similar to the Blackbox exporters. It downloads a JSON file and provides a numerical gauge value from within that file. 6 | Which value to pick is defined through JsonPath. 7 | 8 | ## Parameters 9 | 10 | - `target`: URL / Json-file to download 11 | - `jsonpath`: the field name to read the value from, this follows the syntax provided by [oliveagle/jsonpath](https://github.com/oliveagle/jsonpath) 12 | 13 | ## Docker usage 14 | 15 | docker build -t json_exporter . 16 | docker -d -p 9116:9116 --name json_exporter json_exporter 17 | 18 | The related metrics can then be found under: 19 | 20 | http://localhost:9116/probe?target=http://validate.jsontest.com/?json=%7B%22key%22:%22value%22%7D&jsonpath=$.parse_time_nanoseconds 21 | 22 | ## Prometheus Configuration 23 | 24 | The json exporter needs to be passed the target and the json as a parameter, this can be 25 | done with relabelling. 26 | 27 | Example config: 28 | ```yml 29 | scrape_configs: 30 | - job_name: 'json' 31 | metrics_path: /probe 32 | params: 33 | jsonpath: [$.parse_time_nanoseconds] # Look for the nanoseconds field 34 | static_configs: 35 | - targets: 36 | - http://validate.jsontest.com/?json=%7B%22key%22:%22value%22%7D 37 | relabel_configs: 38 | - source_labels: [__address__] 39 | target_label: __param_target 40 | - source_labels: [__param_target] 41 | target_label: instance 42 | - target_label: __address__ 43 | replacement: 127.0.0.1:9116 # Json exporter. 44 | metric_relabel_configs: 45 | - source_labels: value 46 | target_label: parse_time 47 | 48 | ``` 49 | 50 | ## License 51 | 52 | MIT License 53 | -------------------------------------------------------------------------------- /glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/tolleiv/json-exporter 2 | import: 3 | - package: github.com/prometheus/client_golang 4 | subpackages: 5 | - prometheus/promhttp 6 | - package: github.com/oliveagle/jsonpath 7 | - package: github.com/mohae/utilitybelt 8 | subpackages: 9 | - deepcopy 10 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "log" 6 | "net/http" 7 | 8 | "github.com/prometheus/client_golang/prometheus/promhttp" 9 | "github.com/prometheus/client_golang/prometheus" 10 | "crypto/tls" 11 | "github.com/oliveagle/jsonpath" 12 | "io/ioutil" 13 | "encoding/json" 14 | ) 15 | 16 | var addr = flag.String("listen-address", ":9116", "The address to listen on for HTTP requests.") 17 | 18 | func main() { 19 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 20 | w.Write([]byte(` 21 |