ricoberger / script_exporter

Prometheus exporter to execute scripts and collect metrics from the output or the exit status.
MIT License
354 stars 82 forks source link

how to get shell command metrics? #62

Closed ysy2025 closed 1 year ago

ysy2025 commented 2 years ago

Mr Rico Berger, I want to use script_exporter to monitor pxf-cli status of greenplum, so I edit the script like

!/bin/sh

result="$(pxf-cli cluster status | grep 'running on [0-9] out of' | cut -b 19)" echo "$result" echo "PXF is running on $result out of 4 hosts"

I want to obtain the result, which equals 4 but in localhost/metrics, I only got

scripts_requests_total{script="pxf_status_check"} 2

pxf_status_check is the name of my shell script.

really thanks to you, expect your response.

ricoberger commented 2 years ago

HI @ysy2025, your script is executed when you call the following url http://localhost:9469/probe?script=pxf_status_check.

If you want a metric for your $result variable, you have to include a line like the following into your script, so that Prometheus is able to parse the metric:

echo "pxf_status_check_running_total{} $result"

Does this help?

ysy2025 commented 1 year ago

Dear Mr Rico Berger: image above is the result of http://localhost:9469/probe?script=pxf_status_check but I can not get metrics from this url: http://localhost:9469/probe?script=pxf_status_check in prometheus;

I tried to config prometheus.yml like:

pxf_status_check

Sincerely Thanks to you.

@.***

From: Rico Berger Date: 2022-11-25 16:41 To: ricoberger/script_exporter CC: ysy2025; Mention Subject: Re: [ricoberger/script_exporter] how to get shell command metrics? (Issue #62) HI @ysy2025, your script is executed when you call the following url http://localhost:9469/probe?script=pxf_status_check. If you want a metric for your $result variable, you have to include a line like the following into your script, so that Prometheus is able to parse the metric: echo "pxf_status_check_running_total{} $result"

Does this help? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

ricoberger commented 1 year ago

Hi @ysy2025, I didn't test it, but I think the Prometheus configuration has to look as follows for your example:

scrape_configs:
  - job_name: 'pxf_status_check'
    metrics_path: /probe
    params:
      script: [pxf_status_check]
    static_configs:
      - targets:
        - 127.0.0.1:9469
ysy2025 commented 1 year ago

Great!

Thanks SO MUCH to Mr Rico Berger!

SINCERELY!

@.***

From: Rico Berger Date: 2022-11-28 15:12 To: ricoberger/script_exporter CC: ysy2025; Mention Subject: Re: [ricoberger/script_exporter] how to get shell command metrics? (Issue #62) Hi @ysy2025, I didn't test it, but I think the Prometheus configuration has to look as follows for your example: scrape_configs:

ricoberger commented 1 year ago

You are welcome 🙂

I would close the issue for now, if you have further questions please let me know.