Skip to content

Commit 0efa83f

Browse files
authored
Refactor: Prometheus PVE Exporter to uv based install (#5412)
1 parent 66ab254 commit 0efa83f

File tree

2 files changed

+72
-29
lines changed

2 files changed

+72
-29
lines changed

ct/prometheus-pve-exporter.sh

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,69 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
26-
if [[ ! -f /etc/systemd/system/prometheus-pve-exporter.service ]]; then
27-
msg_error "No ${APP} Installation Found!"
28-
exit
29-
fi
30-
msg_info "Stopping ${APP}"
31-
systemctl stop prometheus-pve-exporter
32-
msg_ok "Stopped ${APP}"
33-
34-
msg_info "Updating ${APP}"
35-
$STD pip install prometheus-pve-exporter --default-timeout=300 --upgrade --root-user-action=ignore
36-
msg_ok "Updated ${APP}"
37-
38-
msg_info "Starting ${APP}"
39-
systemctl start prometheus-pve-exporter
40-
msg_ok "Started ${APP}"
41-
msg_ok "Updated Successfully"
42-
exit
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
if [[ ! -f /etc/systemd/system/prometheus-pve-exporter.service ]]; then
27+
msg_error "No ${APP} Installation Found!"
28+
exit 1
29+
fi
30+
31+
msg_info "Stopping ${APP}"
32+
systemctl stop prometheus-pve-exporter
33+
msg_ok "Stopped ${APP}"
34+
35+
export PVE_VENV_PATH="/opt/prometheus-pve-exporter/.venv"
36+
export PVE_EXPORTER_BIN="${PVE_VENV_PATH}/bin/pve_exporter"
37+
38+
if [[ ! -d "$PVE_VENV_PATH" || ! -x "$PVE_EXPORTER_BIN" ]]; then
39+
PYTHON_VERSION="3.12" setup_uv
40+
msg_info "Migrating to uv/venv"
41+
rm -rf "$PVE_VENV_PATH"
42+
mkdir -p /opt/prometheus-pve-exporter
43+
cd /opt/prometheus-pve-exporter
44+
$STD uv venv "$PVE_VENV_PATH"
45+
$STD "$PVE_VENV_PATH/bin/python" -m ensurepip --upgrade
46+
$STD "$PVE_VENV_PATH/bin/python" -m pip install --upgrade pip
47+
$STD "$PVE_VENV_PATH/bin/python" -m pip install prometheus-pve-exporter
48+
msg_ok "Migrated to uv/venv"
49+
else
50+
msg_info "Updating Prometheus Proxmox VE Exporter"
51+
PYTHON_VERSION="3.12" setup_uv
52+
$STD "$PVE_VENV_PATH/bin/python" -m pip install --upgrade prometheus-pve-exporter
53+
msg_ok "Updated Prometheus Proxmox VE Exporter"
54+
fi
55+
local service_file="/etc/systemd/system/prometheus-pve-exporter.service"
56+
if ! grep -q "${PVE_VENV_PATH}/bin/pve_exporter" "$service_file"; then
57+
msg_info "Updating systemd service"
58+
cat <<EOF >"$service_file"
59+
[Unit]
60+
Description=Prometheus Proxmox VE Exporter
61+
Documentation=https://github.com/znerol/prometheus-pve-exporter
62+
After=syslog.target network.target
63+
64+
[Service]
65+
User=root
66+
Restart=always
67+
Type=simple
68+
ExecStart=${PVE_VENV_PATH}/bin/pve_exporter \\
69+
--config.file=/opt/prometheus-pve-exporter/pve.yml \\
70+
--web.listen-address=0.0.0.0:9221
71+
ExecReload=/bin/kill -HUP \$MAINPID
72+
73+
[Install]
74+
WantedBy=multi-user.target
75+
EOF
76+
$STD systemctl daemon-reload
77+
msg_ok "Updated systemd service"
78+
fi
79+
80+
msg_info "Starting ${APP}"
81+
systemctl start prometheus-pve-exporter
82+
msg_ok "Started ${APP}"
83+
84+
msg_ok "Updated Successfully"
85+
exit 0
4386
}
4487

4588
start
@@ -49,4 +92,4 @@ description
4992
msg_ok "Completed Successfully!\n"
5093
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
5194
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
52-
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:9221${CL}"
95+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:9221${CL}"

install/prometheus-pve-exporter-install.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ setting_up_container
1313
network_check
1414
update_os
1515

16-
msg_info "Setup Python3"
17-
$STD apt-get install -y \
18-
python3 \
19-
python3-pip
20-
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
21-
msg_ok "Setup Python3"
16+
PYTHON_VERSION="3.12" setup_uv
2217

2318
msg_info "Installing Prometheus Proxmox VE Exporter"
24-
python3 -m pip install --default-timeout=300 --quiet --root-user-action=ignore prometheus-pve-exporter
2519
mkdir -p /opt/prometheus-pve-exporter
20+
cd /opt/prometheus-pve-exporter
21+
22+
$STD uv venv /opt/prometheus-pve-exporter/.venv
23+
$STD /opt/prometheus-pve-exporter/.venv/bin/python -m ensurepip --upgrade
24+
$STD /opt/prometheus-pve-exporter/.venv/bin/python -m pip install --upgrade pip
25+
$STD /opt/prometheus-pve-exporter/.venv/bin/python -m pip install prometheus-pve-exporter
2626
cat <<EOF >/opt/prometheus-pve-exporter/pve.yml
2727
default:
2828
user: prometheus@pve
@@ -42,7 +42,7 @@ After=syslog.target network.target
4242
User=root
4343
Restart=always
4444
Type=simple
45-
ExecStart=pve_exporter \
45+
ExecStart=/opt/prometheus-pve-exporter/.venv/bin/pve_exporter \
4646
--config.file=/opt/prometheus-pve-exporter/pve.yml \
4747
--web.listen-address=0.0.0.0:9221
4848
ExecReload=/bin/kill -HUP \$MAINPID

0 commit comments

Comments
 (0)