Giter Club home page Giter Club logo

script-exporter's Introduction

script-exporter

Prometheus exporter to invoke scripts and parse their output as metrics.

Release Build Status Powered By: GoReleaser

Usage

script-exporter -script.path /path/to/my/scripts -web.listen-address :9661

Create e.g. /path/to/my/scripts/script1, an executable which emits on stdout metrics in the Prometheus text exposision format.

Then configure your prometheus.yml to add a target like

  - job_name: 'script1'
    metrics_path: /metrics/script1
    static_configs:
      - targets: ['localhost:9661']

If you add another script, you'll need another job, because the metrics path will be different.

You also want to add a job for the script_exporter internal metrics (errors, process stats, etc) as the above job will only yield metrics emitted by script1 itself:

  - job_name: 'script-exporter'
    metrics_path: /metrics
    static_configs:
      - targets: ['localhost:9661']

Docker

Build the image running: docker build . Or just run

docker pull ncabatoff/script-exporter

script-exporter's People

Contributors

ncabatoff 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

Watchers

 avatar  avatar  avatar  avatar

script-exporter's Issues

Ability to send arguments to script-exporter

Hello.
I'm sorry, if it's not the appropriate place to ask you questions but I didn't find any contacts.

My question is - is it possible to send arguments to script via rest?
I mean I've found examples with arguments in metrics_test.go file
runCommand(context.Background(), "echo", "test")
where echo is a command and test is an argument.
But is it possible to send such arguments as rest parameters (e.g. as query params)?
If it hasn't supported yet, my next question is - have you faced some problems implementing this feature or it's just a matter of time?
Thank you.

collected metric was collected before

Hi
I call a script that displays several values. But periodically returns 500 error and such a message.

An error has occurred during metrics gathering:

9 error(s) occurred:
* collected metric test_1 untyped:<value:886 >  was collected before with the same name and label values
* collected metric test_2 untyped:<value:45.799999999999955 >  was collected before with the same name and label values
* collected metric test_3 untyped:<value:329.0999999999999 >  was collected before with the same name and label values
* collected metric test_4 untyped:<value:243.59999999999985 >  was collected before with the same name and label values
* collected metric test_5  untyped:<value:22 >  was collected before with the same name and label values
* collected metric test_6 untyped:<value:24.9 >  was collected before with the same name and label values
* collected metric test_7 untyped:<value:206.74999999999972 >  was collected before with the same name and label values
* collected metric test_8 untyped:<value:29 >  was collected before with the same name and label values
* collected metric test_9  untyped:<value:140 >  was collected before with the same name and label values

Please tell me what this means and how you can solve it.

cannot find package using go1.12.4

I am seeing the same as @hacker-cb. Documentation for 1.12.4 says "This release removes support for the GO15VENDOREXPERIMENT environment variable". Any ideas?
$ go version go1.12.4 linux/amd64

$ go build
metrics.go:4:2: cannot find package "bosun.org/opentsdb" in any of:
/usr/local/go/src/bosun.org/opentsdb (from $GOROOT)
/root/go/src/bosun.org/opentsdb (from $GOPATH)
main.go:17:2: cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
/usr/local/go/src/github.com/prometheus/client_golang/prometheus (from $GOROOT)
/root/go/src/github.com/prometheus/client_golang/prometheus (from $GOPATH)
main.go:18:2: cannot find package "github.com/prometheus/client_golang/prometheus/promhttp" in any of:
/usr/local/go/src/github.com/prometheus/client_golang/prometheus/promhttp (from $GOROOT)
/root/go/src/github.com/prometheus/client_golang/prometheus/promhttp (from $GOPATH)
metrics.go:9:2: cannot find package "github.com/prometheus/client_model/go" in any of:
/usr/local/go/src/github.com/prometheus/client_model/go (from $GOROOT)
/root/go/src/github.com/prometheus/client_model/go (from $GOPATH)
metrics.go:10:2: cannot find package "github.com/prometheus/common/expfmt" in any of:
/usr/local/go/src/github.com/prometheus/common/expfmt (from $GOROOT)
/root/go/src/github.com/prometheus/common/expfmt (from $GOPATH)

Originally posted by @microwl43 in #2 (comment)

Running multiple scripts

Hi ..
New to Prometheus.
Below is my prometheus.yml file.

global:
scrape_interval: 15s

scrape_configs:

  • job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
    • targets: ['localhost:9090']
  • job_name: 'script1'
    metrics_path: /metrics/script1
    static_configs:
    • targets: ['localhost:9661']
  • job_name: 'script2'
    metrics_path: /metrics/script2
    static_configs:
    • targets: ['localhost:9661']
  • job_name: 'script-exporter'
    metrics_path: /metrics
    static_configs:
    • targets: ['localhost:9661']
      Here are the scripts
      /path/to/my/scripts$ ls -ltr
      total 8
      -rwxrwxrwx 1 root root 117 Jul 12 13:29 script1
      -rwxrwxrwx 1 root root 114 Jul 12 15:04 script2
      Getting below error.

/etc/script-exporter$ sudo ./script-exporter -script.path /path/to/my/scripts -web.listen-address :9661
2019/07/12 15:39:34 error parsing output from script 'script2': Error parsing Prometheus TextFormat: text format parsing error in line 1: expected float as value, got ""

How to fix this?

Zero metrics

Hello!
Thank you for this wonderful tool.
But there are some problems.
I am trying to use a python script as a source of metrics. But it returns zero values ​​through the exporter. Although in reality they are not null
Script:

#!/usr/bin/python
import locale
import os
locale.setlocale(locale.LC_ALL, "")
def get_size(state, root, names):
    paths = [os.path.realpath(os.path.join(root, n)) for n in names]
    # handles dangling symlinks
    state[0] += sum(os.stat(p).st_size for p in paths if os.path.exists(p))
def print_sizes(root):
    total = 0
    paths = []
    state = [0]
    n_ind = s_ind = 0
    for name in sorted(os.listdir(root)):
        path = os.path.join(root, name)
        if not os.path.isdir(path):
            continue
        state[0] = 0
        os.path.walk(path, get_size, state)
        total += state[0]
        s_size = locale.format('%15.0f', state[0])
        n_ind = max(n_ind, len(name), 5)
        s_ind = max(s_ind, len(s_size))
        paths.append((name, int(s_size)))
    for name, size in paths:
	print '# TYPE ' + name + ' gauge'
        print'InfluxDB' + name, size
print_sizes('/var/lib/influxdb/data/')

it returns:

# TYPE InfluxDB_internal untyped
InfluxDB_internal 0
# TYPE InfluxDBprometheus untyped
InfluxDBprometheus 0
# TYPE InfluxDBprometheus_scripts untyped
InfluxDBprometheus_scripts 0
# TYPE InfluxDBtest_prometheus untyped
InfluxDBtest_prometheus 0

But in console I have non-zero values:

# TYPE _internal gauge
InfluxDB_internal 50023469
# TYPE prometheus gauge
InfluxDBprometheus 16266030716
# TYPE prometheus_scripts gauge
InfluxDBprometheus_scripts 33569022
# TYPE test_prometheus gauge
InfluxDBtest_prometheus 1701584910

Please help me to understand why exporter display zeros.

Compile problem

It is impossible to compile project now.
Seems that dependencies was moved

$ go build
metrics.go:4:2: cannot find package "bosun.org/opentsdb" in any of:
	/usr/lib/go/src/pkg/bosun.org/opentsdb (from $GOROOT)
	($GOPATH not set)
command.go:5:2: cannot find package "context" in any of:
	/usr/lib/go/src/pkg/context (from $GOROOT)
	($GOPATH not set)
metrics.go:7:2: cannot find package "github.com/prometheus/client_golang/prometheus" in any of:
	/usr/lib/go/src/pkg/github.com/prometheus/client_golang/prometheus (from $GOROOT)
	($GOPATH not set)
metrics.go:8:2: cannot find package "github.com/prometheus/client_golang/prometheus/promhttp" in any of:
	/usr/lib/go/src/pkg/github.com/prometheus/client_golang/prometheus/promhttp (from $GOROOT)
	($GOPATH not set)
metrics.go:9:2: cannot find package "github.com/prometheus/client_model/go" in any of:
	/usr/lib/go/src/pkg/github.com/prometheus/client_model/go (from $GOROOT)
	($GOPATH not set)
metrics.go:10:2: cannot find package "github.com/prometheus/common/expfmt" in any of:
	/usr/lib/go/src/pkg/github.com/prometheus/common/expfmt (from $GOROOT)

failed to start child: fork/exec exec format error

I'm confused by this issue similar to #10 but the solution doesn't seem to apply. I have a script that seems to run fine when run it but i can't work out why script-exporter doesn't like the format...

dvkdbhkx@unycasd20556 bin]$ file ../script/sh/metrics/latency_by_exchange
../script/sh/metrics/latency_by_exchange: ASCII text
[dvkdbhkx@unycasd20556 bin]$ ../script/sh/metrics/latency_by_exchange
latency_by_exchange{Exchange="CBF", host="unycasd20556"} 0.3924732
latency_by_exchange{Exchange="CBT", host="unycasd20556"} 0.3754613
latency_by_exchange{Exchange="CME", host="unycasd20556"} 0.4503092
latency_by_exchange{Exchange="CMX", host="unycasd20556"} 0.3522788
latency_by_exchange{Exchange="CU2", host="unycasd20556"} 0.3575982
latency_by_exchange{Exchange="DTB", host="unycasd20556"} 0.3356151
latency_by_exchange{Exchange="EUX", host="unycasd20556"} 0.3428435
latency_by_exchange{Exchange="ICE", host="unycasd20556"} 0.6322273
latency_by_exchange{Exchange="ICF", host="unycasd20556"} 0.4415982
latency_by_exchange{Exchange="IOM", host="unycasd20556"} 0.4380095
latency_by_exchange{Exchange="LIF", host="unycasd20556"} 0.4606313
latency_by_exchange{Exchange="LME", host="unycasd20556"} 5.157872
latency_by_exchange{Exchange="NYM", host="unycasd20556"} 0.3621488
latency_by_exchange{Exchange="OSA", host="unycasd20556"} 0.5187463
[dvkdbhkx@unycasd20556 bin]$ ./script-exporter -script.path ../script/sh/metrics -web.listen-address :4522
2020/03/17 09:17:47 error running script 'latency_by_exchange': failed to start child: fork/exec ../script/sh/metrics/latency_by_exchange: exec format error

Any clues?

Error: Get http://localhost:9661/metrics/main: EOF

Hi ncabatoff,

Thank you for providing such an awesome exporter. I'm fairly new to Prometheus, so please bear with me :)

I have been using your script-exporter against a python executable file that runs some oracle sql query and output in the Prometheus text exposision format.

Out of the 3 queries, 2 of them are working fine (script duration is less than 5sec) and prometheus did not display any errors. The third one sometimes works fine, and sometimes gives me and EOF error as shown:
eof_error
eof_error2

This script duration runs between 5-60sec. This depends on how busy the database is, the script duration will vary.

To be honest, I dont think this is a script duration issue. Looking at the error, would you be able to tell me what could be the problem and how I could fix it?

Thank you in advance :)

Regards,
Kevin

race condition in HA environment

Having two Prometheus servers scrape script exporter in a HA setup causes a race condition where only one server gets the metrics.

Prometheus version: 2.8
Script exporter version: current build, not running in docker

First binary release

Little suggestion - if it's not difficult to you, please, add compiled binary as release

Feature Request: Run all scripts in a directory

It would be great if you could run all the scripts in a specified directory without needing to change the config to specify each one in turn. This would make the addition of new scripts a trivial exercise and prevent the centralised prometheus config from getting out of hand in large sites.

Thanks

failed to start child: fork/exec

I have a script in a particular directory that outputs metrics to stdout. I am getting a failed to start child error.
$ ./script-exporter -script.path /etc/scripts -web.listen-address :9661
2019/04/17 02:34:44 error running script 'db2_metrics': failed to start child: fork/exec /etc/scripts/db2_metrics: exec format error
2019/04/17 02:34:54 error running script 'db2_metrics': failed to start child: fork/exec /etc/scripts/db2_metrics: exec format error
2019/04/17 02:35:04 error running script 'db2_metrics': failed to start child: fork/exec /etc/scripts/db2_metrics: exec format error

$ ls -la /etc/scripts/
total 20
drwx------ 2 root root 4096 Apr 17 02:49 .
drwxr-xr-x. 102 root root 12288 Apr 16 06:48 ..
-rwx------ 1 db2inst1 db2iadm1 499 Apr 17 02:45 db2_metrics

$ /etc/scripts/db2_metrics
db2_connect_status{dbname=DBNAME,groupname=db2} 1
db2_hadr_status{dbname=DBNAME,groupname=db2} 0

Thanks

Upgrade Dockerfile to use newer golang image

The version that's fixated currently does not have many necessary tools. Eg a simple docker exec -it sh does not work, as there is no shell available and thus you cannot install additional packages (which you might need to run your scripts).

I've removed the version on my local copy and built a new image. Works fine and has a shell, apk, etc.

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.