7 unstable releases

0.5.1 Feb 22, 2023
0.5.0 Mar 25, 2021
0.4.1 Feb 4, 2021
0.4.0 Dec 24, 2020
0.1.0 Jan 28, 2019

#811 in Filesystem

28 downloads per month

MIT license

21KB
374 lines

Prometheus Folder size Exporter

legal Rust

Crate cratedown cratelastdown

release commitssince

Intro

A Rust Prometheus exporter for folder size. This tool exports the folder size information (optionally including every subdir) in a format that Prometheus can understand.

Prerequisites

  • You need Rust to compile this code. Simply follow the instructions on Rust's website to install the toolchain. If you get wierd errors while compiling please try and update your Rust version first (I have developed it on rustc 1.53.0-nightly (f82664191 2021-03-21)).

Compilation

To compile the latest master version:

git clone https://github.com/MindFlavor/prometheus_folder_size_exporter.git
cd prometheus_folder_size_exporter
cargo install --path .

If you want the latest release you can simply use:

cargo install prometheus_folder_size_exporter

Usage

Start the binary with -h to get the complete syntax. The parameters are:

Parameter Mandatory Valid values Default Description
-v no Enable verbose mode.
-p no any valid port number 9974 Specify the serivce port. This is the port your Prometheus instance should point to.
-i yes a valid config json file - The configuration file. This json is detailed below (you can find an example here: example.json).
-b no Any number > 0 Off Enables the async storage calculation. The value specifies how often (in seconds) the calculation will be done. If not specified, the values will be calculated synchronously at each HTTP Get.

Once started, the tool will listen on the specified port (or the default one, 9974, if not specified) and return a Prometheus valid response at the url /metrics. So to check if the tool is working properly simply browse the http://localhost:9974 (or whichever port you choose).

JSON configuration file

Name Valid values Description
path Any valid path The starting analysis path.
explode_depth Any positive number or -1 This setting controls how deep the folder explosion will go. -1 means no limit. 0 means no explosion.
sum_remaining_subfolders true or false This setting specifies if the last exploded folder size should include the subfolders.

So, for example, to monitor a single folder set explode_depth = 0 and pick sum_remaining_subfolders based on is you want the total folder + subfolder size or not. To monitor a folder and its first level subfolders you specify explode_depth = 1.

Systemd service file

Now add the exporter to the Prometheus exporters as usual. I recommend to start it as a service. My systemd service file is like this one:

[Unit]
Description=Prometheus Folder size Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/prometheus_folder_size_exporter -i /etc/prometheus_folder_size_exporter.json -p 9974

[Install]
WantedBy=multi-user.target

Dependencies

~18–30MB
~545K SLoC