How to display vm properties in prometheus?

deathnote

New Member
Apr 29, 2025
8
0
1
Please help me extract a specific property, namely properties (protection) in prometheus so that I can then display it in grafana
 

Attachments

  • 430806407-ad4acb18-16da-4794-8bbd-482541b7bd74.png
    430806407-ad4acb18-16da-4794-8bbd-482541b7bd74.png
    74.8 KB · Views: 18
--protection <boolean> (default = 0)
Sets the protection flag of the VM. This will disable the remove VM and remove disk operations.
 
There's no standard way to export PVE metrics into prometheus. PVE supports Graphite and InfluxDB. That's why I asked. Don't be an ass.
If you want to implement it yourself, a node exporter textfile written by a simple bash script should do.
 
Last edited:
There's no standard way to export PVE metrics into prometheus. PVE supports Graphite and InfluxDB. That's why I asked. Don't be an ass.
If you want to implement it yourself, a node exporter textfile written by a simple bash script should do.
I used pve exporter prometheus then into grafana
 
This exporter does not appear to export such settings. What you can do is to write a simple script like this that you can then call every minute or so
Bash:
#!/usr/bin/env bash
set -euo pipefail

pct list | awk '/[0-9]/ {print $1}' | while read -r ct; do
  (pct config "${ct}" | grep -q "protection: 1") && echo "pve_protection_{id=\"lxc/${ct}\"} 1" || echo "pve_protection_{id=\"lxc/${ct}\"} 0"
done

qm list | awk '/[0-9]/ {print $1}' | while read -r vm; do
  (qm config "${vm}" | grep -q "protection: 1") && echo "pve_protection_{id=\"qemu/${vm}\"} 1" || echo "pve_protection_{id=\"qemu/${vm}\"} 0"
done
No, it's not pretty, but it should do. It gives output like this
Code:
pve_protection{id="lxc/101"} 0
pve_protection{id="qemu/100"} 1
You can write its output into a .prom file the textfile collector can then read.
Bash:
* * * * * bash /path/to/script.sh | sponge /path/to/textfiledir/pveprotection.prom
Install moreutils to get sponge. Test, extend and modify as needed. It's just an example.

Please don't quote every message.
 
Last edited:
This exporter does not appear to export such settings. What you can do is to write a simple script like this that you can then call every minute or so
Bash:
#!/usr/bin/env bash
set -euo pipefail

pct list | awk '/[0-9]/ {print $1}' | while read -r ct; do
  (pct config "${ct}" | grep -q "protection: 1") && echo "pve_protection_{id=\"lxc/${ct}\"} 1" || echo "pve_protection_{id=\"lxc/${ct}\"} 0"
done

qm list | awk '/[0-9]/ {print $1}' | while read -r vm; do
  (qm config "${vm}" | grep -q "protection: 1") && echo "pve_protection_{id=\"qemu/${vm}\"} 1" || echo "pve_protection_{id=\"qemu/${vm}\"} 0"
done
No, it's not pretty, but it should do. It gives output like this
Code:
pve_protection{id="lxc/101"} 0
pve_protection{id="qemu/100"} 1
You can write its output into a .prom file the textfile collector can then read.
Bash:
* * * * * bash /path/to/script.sh | sponge /path/to/textfiledir/pveprotection.prom
Install moreutils to get sponge. Test, extend and modify as needed. It's just an example.

Please don't quote every message.
in this exporter need to add something so that it collects the parameter data and compile it again.