Crates.io | pistachio |
lib.rs | pistachio |
version | 0.3.1 |
source | src |
created_at | 2024-09-14 03:35:41.251048 |
updated_at | 2024-09-25 22:43:50.151335 |
description | A Prometheus exporter designed for monitoring UPS devices using Network UPS Tools (NUT). |
homepage | |
repository | https://github.com/barrelmaker97/pistachio |
max_upload_size | |
id | 1374436 |
size | 81,544 |
Pistachio is a Prometheus exporter designed for monitoring UPS devices using Network UPS Tools (NUT).
Pistachio can be configured using either command-line options or by setting corresponding environment variables. Command-line options take precedence over environment variables. Below is a breakdown of the available options:
Option | Description | Environment Variable | Default |
---|---|---|---|
--ups-name <UPS_NAME> |
Name of the UPS to monitor. | UPS_NAME |
ups |
--ups-host <UPS_HOST> |
Hostname of the NUT server to monitor. | UPS_HOST |
127.0.0.1 |
--ups-port <UPS_PORT> |
Port of the NUT server to monitor. | UPS_PORT |
3493 |
--bind-ip <BIND_IP> |
IP address on which the exporter will serve metrics. | BIND_IP |
0.0.0.0 |
--bind-port <BIND_PORT> |
Port on which the exporter will serve metrics. | BIND_PORT |
9120 |
--poll-rate <POLL_RATE> |
Time in seconds between requests to the NUT server. Must be at least 1 second. | POLL_RATE |
10 |
-h, --help |
Print help message | - | - |
-V, --version |
Print version information | - | - |
To run Pistachio with custom values for UPS_HOST
and POLL_RATE
, you can either use the command-line options:
pistachio --ups-host 192.168.1.100 --poll-rate 5
Or set the environment variables:
export UPS_HOST=192.168.1.100
export POLL_RATE=5
pistachio
If Pistachio is run as a systemd service, systemctl edit
can be used to set configuration options.
Run the following to open up an override.conf
file in /etc/systemd/system/pistachio.service.d/
sudo systemctl edit pistachio.service
In this file, environment variables can be set to configure Pistachio:
[Service]
Environment="UPS_HOST=192.168.1.100"
Environment="POLL_RATE=5"
After saving the file, the service must be restarted for changes to take effect:
sudo systemctl restart pistachio.service
To undo changes made to the configuration, systemctl revert
can be used:
sudo systemctl revert pistachio.service
Clone the repository:
git clone https://github.com/barrelmaker97/pistachio.git
Navigate to the project directory:
cd pistachio
Build the project using Cargo:
cargo build --release
Run the exporter:
./target/release/pistachio
Configure Prometheus to scrape metrics from the exporter at http://<your_host>:<BIND_PORT>/metrics
.
Using cargo-deb, a .deb package for Pistachio can be built. This package can be used to install and run Pistachio as a systemd service. To create, install, and start the service, use the following steps:
Install cargo-deb:
cargo install cargo-deb
Build the Debian package:
cargo deb
Install the generated package:
sudo dpkg -i target/debian/pistachio_*.deb
Enable and start the systemd service:
sudo systemctl enable pistachio
sudo systemctl start pistachio
The package can be uninstalled by running the following:
sudo dpkg -P pistachio
To build Pistachio for a different architecture (a Raspberry Pi for example), install the appropriate target and linker:
rustup target add aarch64-unknown-linux-gnu
sudo apt install gcc-aarch64-linux-gnu
Configure the linker in ~/.cargo/config.toml
:
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
Specify the target in the build command:
cargo build --target aarch64-unknown-linux-gnu
A pre-built Docker image of Pistachio is available on the GitHub Container Registry. This allows you to easily deploy the exporter in any containerized environment.
You can pull the Docker image from the GitHub Container Registry with the following command:
docker pull ghcr.io/barrelmaker97/pistachio:latest
To run the exporter using Docker, use the following command:
docker run -d \
--name pistachio \
-p 9120:9120 \
-e UPS_NAME=your_ups_name \
-e UPS_HOST=your_nut_server_host \
-e UPS_PORT=3493 \
-e RUST_LOG=info \
-e POLL_RATE=10 \
ghcr.io/barrelmaker97/pistachio:latest
Replace the environment variables (UPS_NAME
, UPS_HOST
, etc.) with the appropriate values for your setup.
Here’s an example of how you can include Pistachio in a Docker Compose setup:
version: '3.7'
services:
pistachio:
image: ghcr.io/barrelmaker97/pistachio:latest
environment:
UPS_NAME: your_ups_name
UPS_HOST: your_nut_server_host
UPS_PORT: 3493
RUST_LOG: info
POLL_RATE: 10
ports:
- "9120:9120"
Copyright (c) 2024 Nolan Cooper
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.