Giter Site home page Giter Site logo

gree-gorey / bash-exporter Goto Github PK

View Code? Open in Web Editor NEW
63.0 6.0 28.0 21 KB

Simple & minimalistic Prometheus exporter for bash scripts, written in Go

Home Page: https://github.com/gree-gorey/bash-exporter

License: Apache License 2.0

Go 88.48% Dockerfile 11.52%
prometheus prometheus-exporter prometheus-metrics bash golang go metrics

bash-exporter's Introduction

Prometheus bash exporter

Simple & minimalistic Prometheus exporter for bash scripts.

Go Report Card

Installation

Use Docker image or binary file from releases.

Docker quick start

$ docker run -v $PWD/examples:/scripts -p 9300:9300 greegorey/bash-exporter:2.0.0
$ curl -s 127.1:9300/metrics | grep ^bash
bash{env="",hostname="node-1",job="job-2",verb="get"} 0.003
bash{env="",hostname="node-1",job="job-2",verb="put"} 0.13
bash{env="",hostname="node-1",job="job-2",verb="time"} 0.5
bash{env="dev",hostname="",job="job-1",verb="items"} 21

Usage

Usage of ./bash-exporter:
  -debug
    	Debug log level
  -interval int
    	Interval for metrics collection in seconds (default 300)
  -labels string
    	additioanal labels (default "hostname,env")
  -path string
    	path to directory with bash scripts (default "/scripts")
  -prefix string
    	Prefix for metrics (default "bash")
  -web.listen-address string
    	Address on which to expose metrics (default ":9300")

Just point -path flag to the directory with your bash scripts. Names of the files ((.*).sh) will be used as the job label. Bash scripts should return valid json (see examples).

Example output:

# HELP bash bash exporter metrics
# TYPE bash gauge
bash{job="job-1",verb="items"} 21
bash{job="job-2",verb="get"} 0.003
bash{job="job-2",verb="put"} 0.13
bash{job="job-2",verb="time"} 0.5
...

TODO

  • Docker image
  • Several scripts

bash-exporter's People

Contributors

henkjan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bash-exporter's Issues

issue with example scripts

I have the following example script:

#!/bin/sh

echo '{"labels": {"env": "dev"}, "results": {"items": 21} }'

exit 0

The exporter as docker container gives me the following error message:
json: cannot unmarshal object into Go value of type float64

Any suggestions?

Info request: Can execution of the scripts be triggered by a scrape?

Hi,

First of all, thanks for sharing your code!

I have a question: The fact that an interval is defined in the exporter itself tells me that the scripts are possibly not triggered by a scrape... correct?

If so, is it possible to, optionally, have the scripts be executed on each scrape? This would allow for central config management... especially in cases such as ours, where the clients are inaccessible due to network topology, and we use PushProx to proxy the metrics.

Thanks!

Actually does not support string output, can you add string output function, thank you.

{
"crc47": 0,
"crc48": 0,
"crc49": 0,
"crc50": 0,
"crc51": 1,
"crc52": 0,
"crc53": 0,
"crc54": 0,
"crc55": 0,
"crc56": 0,
"cpu": 12,
"memory": 52,
"SystemName": "Quidway S5700 Routing Switch"
}

2020/09/24 17:44:14 json: cannot unmarshal string into Go value of type float64

Actually does not support string output, can you add string output function, thank you.

How to use my custom script

I have my own shell script which gives output "OK" (0) or "NOTOK" (1) that I want to use as a metric value. Also use some metric " my_system_health".

my_system_health {host="hostname"} 1
my_system_health {host="hostname"} 0

#!/bin/bash

hnm=`hostname`

  if [ `command` ]
  then
    result=1
  else
    result=0
  fi

 if [ $result=1 ]
  then
    my_system_health {host=$hnm} 1
  else
    my_system_health {host=$hnm} 0
  fi

Let me know how we can can configure, also Prometheus configuration.

Though it's not a issue but you may treat as use case.

Setup difficulties + remedies

Currently has taken me a few hours to set up and make this exporter work. Two issues with the set up:

  1. It is non-obvious that the image will copy example jobs into the container and try and run them if you use the default script location. This behaviour seems to serve no benefit.

  2. It is non-obvious that having labels is a must, go will throw a vague error if you only return results from your .sh script. Unsure what the behaviour of passing "-labels" without any argument is.

This behaviour should really either be documented properly or should be fixed in the code.

Other than that nice project.

Docker build not working - missing dependencies

Hi,

thanks for your project. I am trying to change the CMD in your Dockerfile with the idea, to add parameters to the docker its (-interval for example).

Now I have cloned your repository and want to build my own docker image. Unfortunately this is failing with this error:

Sending build context to Docker daemon 2.048 kB
Step 1/10 : FROM golang:1.10.1
 ---> 1af690c44028
Step 2/10 : ENV https_proxy "https://proxy/"
 ---> Using cache
 ---> b873a2ddd91e
Step 3/10 : RUN go get -d -v github.com/gree-gorey/bash-exporter/cmd/bash-exporter
 ---> Running in 87be61fbf1ab

github.com/gree-gorey/bash-exporter (download)
github.com/prometheus/client_golang (download)
github.com/beorn7/perks (download)
github.com/cespare/xxhash (download)
package github.com/cespare/xxhash/v2: cannot find package "github.com/cespare/xxhash/v2" in any of:
        /usr/local/go/src/github.com/cespare/xxhash/v2 (from $GOROOT)
        /go/src/github.com/cespare/xxhash/v2 (from $GOPATH)
github.com/golang/protobuf (download)
github.com/prometheus/client_model (download)
github.com/prometheus/common (download)
github.com/matttproud/golang_protobuf_extensions (download)
github.com/prometheus/procfs (download)
The command '/bin/sh -c go get -d -v github.com/gree-gorey/bash-exporter/cmd/bash-exporter' returned a non-zero code: 1

I have checked this and xxhash is a dependency from the client_golang/prometheus repo and is an import from the registry.go file. Do you have an idea, how to solve this?

Thanks very much

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.