项目作者: sandro-h

项目描述 :
Translate arbitrary REST endpoints to metrics for Prometheus using jq syntax
高级语言: Go
项目地址: git://github.com/sandro-h/prom_rest_exporter.git
创建时间: 2018-12-22T11:42:29Z
项目社区:https://github.com/sandro-h/prom_rest_exporter

开源协议:MIT License

下载


prom_rest_exporter

CircleCI
Sonar
Coverage

prom_rest_exporter translates arbitrary REST endpoints to metrics for Prometheus.

It uses the excellent jq to transform JSON responses to numeric metric values.

prom_rest_exporter runs as a separate process exposing one or more /metrics endpoints for Prometheus.

Motivation

Sometimes you want to monitor third-party applications that do not provide Prometheus-compatible metrics.
If they provide other REST endpoints with valuable monitoring information, you can use prom_rest_exporter to make these available to Prometheus.

Note: if possible, it’s preferable to adapt the application to provide Prometheus metrics directly. This avoids operational complexity of running prom_rest_exporter in addition to the application.

Installation

Download one of the released binaries.

Run the binary to start prom_rest_exporter.
It expects a configuration file, see below.

Configuration

To configure what REST endpoints should be exported and how,
create a prom_rest_exporter.yml YAML file.

You can also name it differently and use --config <path/to/config.yml> to load it.

Simple config example:

  1. endpoints:
  2. # Run on localhost:9011/metrics
  3. - port: 9011
  4. targets:
  5. # Get data from this REST endpoint
  6. - url: https://reqres.in/api/users
  7. metrics:
  8. - name: user_count
  9. description: Number of users
  10. type: gauge
  11. # jq program to extract a numeric value from the REST response
  12. selector: ".total"

See config.md for more detailed information.

Logging

prom_rest_exporter will write log output to prom_rest_exporter.log in the working directory.

Log details can be increased with the --debug and --trace command-line flags.

Error handling

Failures during metric collection, such as REST endpoint downtimes or non-matching metric selectors, are logged but the collection continues for the remaining targets and metrics.

Any metrics that could not be extracted due to errors are simply skipped. Thus, Prometheus will show a “No data” gap when errors occur, and appropriate alerts can be set up for this.

If you enable meta_metrics in your configuration, you will also get the number of skipped
metrics (prom_rest_exp_skipped_metrics) per REST endpoint, and can alert on that.

Development

Dependencies are managed with dep.
Fetch all necessary dependencies with:

  1. dep ensure

jq dependency

Building prom_rest_exporter requires compiled
jq libraries in the vendorc/ folder.

  1. cd vendorc
  2. git clone https://github.com/stedolan/jq.git jq-master
  3. cd jq-master
  4. git checkout jq-1.6
  5. git submodule update --init

Required build tools:

  1. sudo apt-get install autoconf make libtool flex bison gcc-mingw-w64-x86-64

Compiling for linux

  1. autoreconf -fi
  2. ./configure --with-oniguruma=builtin --prefix=$PWD/build/linux/usr/local
  3. make -j8
  4. make install
  5. # Remove so files to statically link
  6. rm -f build/linux/usr/local/lib/*.so*

Cross-compiling for Windows

Cf. https://github.com/stedolan/jq/wiki/Cross-compilation

  1. autoreconf -fi
  2. ./configure
  3. make distclean
  4. mkdir build
  5. # Run it twice if first time you get "fatal error: compile.h"
  6. CPPFLAGS=-I$PWD/src scripts/crosscompile win64 \
  7. --disable-shared \
  8. --enable-static \
  9. --enable-all-static \
  10. --target=win64-x86_64 \
  11. --host=x86_64-w64-mingw32 \
  12. --with-oniguruma=builtin

Building and testing

Build

  1. go build

Test

  1. go test ./...

Also see .circleci/config.yml for more information on the build process.