S.M.A.R.T. and partition data exporter for the Prometheus monitoring system
Project description
prometheus-disk-exporter
A prometheus exporter for disk S.M.A.R.T. data and partition usage
information
For security reasons, this script is not supposed to be ran with root
privileges. Instead, the only command which requires these privileges
(smartctl
) is ran using sudo
within getter.sh
. For this reason
the installation step includes adding a sudoers configuration to run
this command without the need of a password for the specified user.
installing
These steps assume that you are running with root privileges.
Setup prometheus user
Note: this step can be skipped if you already have a linux user for exporting prometheus metrics, such as for prometheus-pve-exporter
- Create linux user with no login
# useradd -s /bin/false prometheus
Install package in virtual environment
- Install the
venv
python module
# apt install python3-venv
- Create the virtual environment in
/opt
# python3 -m venv /opt/prometheus-disk-exporter
- Activate the virtual environment
# source /opt/prometheus-disk-exporter/bin/activate
- Install the pip package for prometheus-disk-exporter
(prometheus-disk-exporter) # pip install prometheus-disk-exporter
- Disable the virtual environment
(prometheus-disk-exporter) # deactivate
Setup sudoers and systemd configuration
- Add sudoers configuration to run
smartctl
without password.
# echo "prometheus ALL=(ALL:ALL) NOPASSWD: $(which smartctl)" | tee -a /etc/sudoers.d/99-prometheus-disk-exporter
- Create a systemd service
/etc/systemd/system/prometheus-disk-exporter.service
for this script. A sample can be found in thesystemd
folder of the repository. - Start and enable the systemd service.
# systemctl daemon-reload
# systemctl enable prometheus-disk-exporter.service
# systemctl start prometheus-disk-exporter.service
- Verify that the installation was successful by visiting
0.0.0.0:9313
, or whatever address and port you specified in the command arguments
arguments
usage: prometheus_disk_exporter [-h] [--listen-address LISTEN_ADDRESS]
[--listen-port LISTEN_PORT]
options:
-h, --help show this help message and exit
--listen-address LISTEN_ADDRESS, -l LISTEN_ADDRESS
Address for HTTP server to listen on
--listen-port LISTEN_PORT, -p LISTEN_PORT
Port for HTTP server to listen on
- listen-address: Address for HTTP server to listen on (string) (Default: '0.0.0.0')
- listen-port: Port for HTTP server to listen on (int) (Default: 9313)
metrics sample
# HELP disk_getter_error Indicates an internal error while getting data from shell script
# TYPE disk_getter_error gauge
disk_getter_error{type="None"} 0.0
# HELP disk_model_info Disk Model Family
# TYPE disk_model_info gauge
disk_model_info{disk_serial="WD-WCC6Y3TVHSKJ",model_family="Western Digital Blue",rpm="7200 rpm"} 1.0
disk_model_info{disk_serial="50026B76821954FF",model_family="Kingston SSDNow UV400/500",rpm="Solid State Device"} 1.0
# HELP disk_power_on_hours Hours spent with disk powered
# TYPE disk_power_on_hours gauge
disk_power_on_hours{disk_serial="WD-WCC6Y3TVHSKJ"} 11583.0
disk_power_on_hours{disk_serial="50026B76821954FF"} 11583.0
# HELP disk_power_cycle_count Disk power cycle count
# TYPE disk_power_cycle_count gauge
disk_power_cycle_count{disk_serial="WD-WCC6Y3TVHSKJ"} 2055.0
disk_power_cycle_count{disk_serial="50026B76821954FF"} 2032.0
# HELP disk_raw_read_error_rate Disk raw read error rate
# TYPE disk_raw_read_error_rate gauge
disk_raw_read_error_rate{disk_serial="WD-WCC6Y3TVHSKJ"} 0.0
disk_raw_read_error_rate{disk_serial="50026B76821954FF"} 2.476152e+06
# HELP disk_temperature Disk temperature in Celsius
# TYPE disk_temperature gauge
disk_temperature{disk_serial="WD-WCC6Y3TVHSKJ"} 41.0
disk_temperature{disk_serial="50026B76821954FF"} 42.0
# HELP partition_info Partition metadata information
# TYPE partition_info gauge
partition_info{block="/dev/sda1",disk_serial="WD-WCC6Y3TVHSKJ",filesystem="ext4",mountpoint="/media"} 1.0
partition_info{block="/dev/sdb1",disk_serial="50026B76821954FF",filesystem="vfat",mountpoint="/boot/efi"} 1.0
partition_info{block="/dev/sdb2",disk_serial="50026B76821954FF",filesystem="ext4",mountpoint="/"} 1.0
# HELP partition_usage_bytes Partition used size in bytes
# TYPE partition_usage_bytes gauge
partition_usage_bytes{block="/dev/sda1",disk_serial="WD-WCC6Y3TVHSKJ"} 1.33785550848e+011
partition_usage_bytes{block="/dev/sdb1",disk_serial="50026B76821954FF"} 303104.0
partition_usage_bytes{block="/dev/sdb2",disk_serial="50026B76821954FF"} 2.4086495232e+010
# HELP partition_size_bytes Partition total size in bytes
# TYPE partition_size_bytes gauge
partition_size_bytes{block="/dev/sda1",disk_serial="WD-WCC6Y3TVHSKJ"} 9.83349346304e+011
partition_size_bytes{block="/dev/sdb1",disk_serial="50026B76821954FF"} 3.13929728e+08
partition_size_bytes{block="/dev/sdb2",disk_serial="50026B76821954FF"} 1.17236166656e+011
credits
- prometheus_smart_exporter. if all you are looking for is a SMART data exporter, i highly recommend their implementation
- proxmox prometheus metrics, for helping me figure out how to properly install the package
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
Built Distribution
Hashes for prometheus-disk-exporter-0.0.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93894174bfcad22931d627bb1162bd28c7e6a57082145e4f50ca6a7e58bd9ead |
|
MD5 | 9c2667d37ed7803c4b780aa5198f7cdf |
|
BLAKE2b-256 | e2d472ab3bd07d0700064d7d65d022776a585d543ee132ecd4580c3eb5253520 |
Hashes for prometheus_disk_exporter-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5c8781f2d2ff0306c0d3274e4dca71dde1e5a9ff6d9c02fe922a3db4397cdb8 |
|
MD5 | 7fca4c2138a1a41d2c9d0aeffc765751 |
|
BLAKE2b-256 | 126f94738e77c4218781fc5521d826a70113da92daecd52f3f0f901d0b3b6d93 |