Catalogue
Writing Custom Queries for node_exporter with Shell Scripts

Writing Custom Queries for node_exporter with Shell Scripts

🌐 日本語で読む

Overview

By placing files with the *.prom extension in the directory specified by node_exporter’s --collector.textfile.directory option,
the Prometheus server will read the metric information written in them.

The idea is that if you update these *.prom files at regular intervals, you can create your own custom metrics.

Procedure

  • For installing and setting up node_exporter itself, please refer to the following.

In the procedure above, node_exporter is placed at the following location.
Adjust it as appropriate for your environment.

1
/usr/local/node_exporter/node_exporter

Create the text_collector directory

1
2
$ cd /usr/local/node_exporter
$ mkdir text_collector

Create the shell script

This time, we will add a metric for the httpd process count.

  • Create /usr/local/node_exporter/text_collector/httpd.sh

Configure cron

1
2
# Update node_exporter httpd every 5 minutes
*/5 * * * * /usr/local/node_exporter/text_collector/httpd.sh

Verify httpd.prom is created

  • /usr/local/node_exporter/text_collector/httpd.prom
1
node_httpd_count 24

The node_httpd_count above becomes the metric name.

Restart node_exporter

Specify the directory as follows.

1
node_expoter --collector.textfile.directory /usr/local/node_exporter/text_collector

Specify and verify the metric you created

It worked!

Using this, you can often get a lot done with shell one-liners ♪

I hope this helps.

kenzo0107

kenzo0107