Skip to content

Instantly share code, notes, and snippets.

@NotYusta
Created May 18, 2025 12:57
Show Gist options
  • Save NotYusta/5ab4a72e28957575b4ed75a17f111699 to your computer and use it in GitHub Desktop.
Save NotYusta/5ab4a72e28957575b4ed75a17f111699 to your computer and use it in GitHub Desktop.
Install Smartctl Exporter
#!/bin/sh
PORT=9102
BIN_DIR="/usr/local/bin"
SERVICE_NAME="smartctl-exporter"
BINARY_NAME="smartctl-exporter"
VERSION="0.14.0"
DOWNLOAD_URL="https://github.com/prometheus-community/smartctl_exporter/releases/download/v${VERSION}/smartctl_exporter-${VERSION}.linux-amd64.tar.gz"
# Function to download and extract smartctl_exporter
install_smartctl_exporter() {
curl -sL "$DOWNLOAD_URL" -o /tmp/smartctl_exporter.tar.gz
tar -xzf /tmp/smartctl_exporter.tar.gz -C /tmp
mv /tmp/smartctl_exporter-${VERSION}.linux-amd64/smartctl_exporter "${BIN_DIR}/${BINARY_NAME}"
chmod +x "${BIN_DIR}/${BINARY_NAME}"
}
# Function to create systemd service
create_systemd_service() {
cat <<EOF > /etc/systemd/system/${SERVICE_NAME}.service
[Unit]
Description=Prometheus smartctl Exporter
After=network.target
[Service]
ExecStart=${BIN_DIR}/${BINARY_NAME} --web.listen-address=":${PORT}"
Restart=always
[Install]
WantedBy=multi-user.target
EOF
}
# Function to enable and start the service
start_service() {
systemctl daemon-reload
systemctl enable ${SERVICE_NAME} --now
}
# Main function
main() {
install_smartctl_exporter
create_systemd_service
start_service
}
# Run main
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment