Skip to main content

Exporter for disk usage metrics

Project description

disk_usage_exporter

Exporter for disk usage metrics.

Metrics example
# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 187734.0
python_gc_objects_collected_total{generation="1"} 74395.0
python_gc_objects_collected_total{generation="2"} 6222.0
# HELP python_gc_objects_uncollectable_total Uncollectable objects found during GC
# TYPE python_gc_objects_uncollectable_total counter
python_gc_objects_uncollectable_total{generation="0"} 0.0
python_gc_objects_uncollectable_total{generation="1"} 0.0
python_gc_objects_uncollectable_total{generation="2"} 0.0
# HELP python_gc_collections_total Number of times this generation was collected
# TYPE python_gc_collections_total counter
python_gc_collections_total{generation="0"} 363.0
python_gc_collections_total{generation="1"} 33.0
python_gc_collections_total{generation="2"} 2.0
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="3",minor="9",patchlevel="21",version="3.9.21"} 1.0
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 5.58657536e+08
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 2.072576e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.73804800503e+09
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 7.79
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 8.0
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 1024.0
# HELP disk_usage_by_directories Directory size
# TYPE disk_usage_by_directories gauge
disk_usage_by_directories{path="/media"} 4.0
disk_usage_by_directories{path="/tmp"} 78660.0
disk_usage_by_directories{path="/var"} 6.9855712e+07
disk_usage_by_directories{path="/sys"} 0.0
disk_usage_by_directories{path="/etc"} 25232.0
disk_usage_by_directories{path="/lost+found"} 16.0
disk_usage_by_directories{path="/boot"} 274220.0
disk_usage_by_directories{path="/lib64"} 0.0
disk_usage_by_directories{path="/srv"} 4.0
disk_usage_by_directories{path="/opt"} 35116.0
disk_usage_by_directories{path="/sbin"} 0.0
disk_usage_by_directories{path="/data"} 2.7009988e+07
disk_usage_by_directories{path="/bin"} 0.0
disk_usage_by_directories{path="/mnt"} 4.0
disk_usage_by_directories{path="/run"} 1.3066156e+07
disk_usage_by_directories{path="/afs"} 4.0
disk_usage_by_directories{path="/lib"} 0.0
disk_usage_by_directories{path="/dev"} 16.0
disk_usage_by_directories{path="/proc"} 0.0
disk_usage_by_directories{path="/usr"} 4.38558e+06
disk_usage_by_directories{path="/home"} 5.203604e+06
disk_usage_by_directories{path="/root"} 2324.0

Installation

From PyPI

sudo -H pip install disk_usage_exporter

From source

  1. Install build package
python -m pip install build
  1. Build package
python -m build
  1. Install package
VERSION=0.0.2
sudo -H pip install dist/disk_usage_exporter-$VERSION-py3-none-any.whl

Usage

usage: disk_usage_exporter [-h] [--addr ADDR] [--port PORT] [--search-root SEARCH_ROOT] [-d] [-v]

options:
  -h, --help            show this help message and exit
  --addr ADDR           specify metrics host
  --port PORT           specify metrics port
  --search-root SEARCH_ROOT
                        specify the directory that will be used to search for subdirectories to analyze
  -d, --debug           enable debug logs
  -v, --version         show program's version number and exit

Prometheus configuration

  1. Add a new job to Prometheus configuration: /etc/prometheus/prometheus.yml
...
scrape_configs:
  - job_name: "disk_usage_exporter"
    static_configs:
      - targets: ["localhost:8100"] 
  1. Restart Prometheus:
PROMETHEUS_HOST=localhost
PROMETHEUS_PORT=9091
curl -XPOST $PROMETHEUS_HOST:$PROMETHEUS_PORT/-/reload

Systemd unit

  1. Create a file named /etc/systemd/system/disk_usage_exporter.service and include the following:
[Unit]
Description=disk_usage_exporter service

[Service]
ExecStart=disk_usage_exporter

[Install]
WantedBy=multi-user.target
  1. Reload the service files to include a new service:
sudo systemctl daemon-reload
  1. Start service:
sudo systemctl start disk_usage_exporter

ToDo:

  • Rename constants.py to const.py
  • Add default host and port to const.py
  • Add --host option
  • Add --host description to README.md
  • Add --max-depth option
  • Make getting values asynchronous
  • Make project structure similar to other prometheus exporters
  • Add informative logging messages
  • Add CI with linter
  • Add tests
  • Add name for python process
  • Add badges with code coverage and tests passing
  • Add test that checks metrics after a few seconds after startup
  • Add info about cmd args default values to README.md

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

disk_usage_exporter-0.0.2.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

disk_usage_exporter-0.0.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file disk_usage_exporter-0.0.2.tar.gz.

File metadata

  • Download URL: disk_usage_exporter-0.0.2.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for disk_usage_exporter-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e4436bcb241ef983fe661bae29a83548b588817cf83bed9e34366f92f0be0d21
MD5 be969db6198d41434ab78e7139c05c3c
BLAKE2b-256 f77e8b66cd0a1472cb2e0072a8682236ee8b7480d87c8bdf90c1868034efd927

See more details on using hashes here.

File details

Details for the file disk_usage_exporter-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for disk_usage_exporter-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3406c90e4744f4dad001d2de1214a6b27e5e9c5e13328c8c23a399e2234044f3
MD5 3b86ded1a6f7bd42927ddda767ff690a
BLAKE2b-256 6d5f56db09c88b66eaccb83aa68f3be7f1c85b8e6941432396ffc5e52f8d116a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page