ricoberger / script_exporter

Prometheus exporter to execute scripts and collect metrics from the output or the exit status.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Allow to read script entries from separate config files

Napsty opened this issue · comments

Pretty neat exporter, thanks for this!

Right now each external script needs to be defined in the main config file (-config.file config.yaml), as seen in the example:

scripts:
  - name: test
    command: ./examples/test.sh
  - name: ping
    command: ./examples/ping.sh
    cacheDuration: 1m
  - name: helloworld
    command: ./examples/helloworld.sh
    args:
      - test

This means that for additional scripts, the config.yaml needs to be edited. That's no problem if you have a couple of nodes running all the same scripts and therefore have the same config file. But with increasing number of nodes, the use-cases and roles of these nodes differ and hence different scripts need to be configured. Even with automation (e.g. Ansible) the scripts adjustments in the config file are prone to errors (let alone manual configuration).

It would be a nice feature to optionally read scripts entries from external files. Example:

scripts:
  - name: test
    command: ./examples/test.sh
  - name: ping
    command: ./examples/ping.sh
    cacheDuration: 1m
  - name: helloworld
    command: ./examples/helloworld.sh
    args:
      - test

scripts_configs:
  - path: /etc/prometheus_script_exporter/scripts/*.yaml
  - path: /opt/prometheus_scripts/*.yaml

Each yaml file would then contain a single (or even multiple) scripts entry, for example:

$ cat /etc/prometheus_script_exporter/scripts/showtimeout.yaml
  - name: showtimeout
    command: ./examples/showtimeout.sh
    timeout:
      max_timeout: 60

This would allow a dynamic configuration of scripts without having to touch the main config.yaml.

I hope this Feature Request is understandable and makes sense. The names (e.g. script_configs) are just examples and could be named differently.

Thanks for considering it.

Hi @Napsty, I like the idea and created a PR for this feature (#116).

The only difference from your example is that the scripts_configs is just a list of strings.

If you already want to test this, you can find the binaries for the PR here: https://github.com/ricoberger/script_exporter/actions/runs/7836428714?pr=116

This is awesome, thanks for the quick PR! I hope test it next week and let you know.

I created a new release v2.18.0. If you have any problems with it please let me know.