Skip to content
This repository was archived by the owner on Jul 3, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Make sure your node exporter uses `textfile` in `--collectors.enabled` and add t
## Example queries

```
CPU_Temperature{job="node"}
Freq_arm{job="node"}
Volt_core{job="node"}
rpi_temperature{job="node"}
rpi_freq{job="node",device="arm"}
rpi_volt{job="node",device="core"}
rpi_mem{job="node",device="arm"}
```
1 change: 1 addition & 0 deletions prometheus-raspberry-exporter.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Description=Collect Raspberry Pi metrics for Prometheus

[Service]
Type=oneshot
Environment=PROM_FILE_PATH=/var/lib/prometheus/node-exporter/raspberry_exporter.prom
ExecStart=/usr/local/bin/raspberry_exporter
48 changes: 27 additions & 21 deletions raspberry_exporter
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
#!/bin/bash
#!/bin/sh

set -eu

VCGEN=/opt/vc/bin/vcgencmd
TEXTFILE=/var/lib/node_exporter/textfile_collector/raspberry-metrics.prom
VCGEN=${VCGEN_PATH:-/opt/vc/bin/vcgencmd}
TEXTFILE=${PROM_FILE_PATH:-var/lib/node_exporter/textfile_collector/raspberry-metrics.prom}
TEMPFILE=$TEXTFILE.$$

mkdir -p /var/lib/node_exporter/textfile_collector/
mkdir -p $(dirname $TEXTFILE)

TEMP=$(awk '{printf "%.2f", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
cat /dev/null > $TEMPFILE

if [ -z "$TEMP" ];
then
echo "$NOW - Error: Value variable empty"
else
echo "CPU_Temperature ${TEMP}" > $TEMPFILE
for sensor in `ls /sys/class/thermal/`;
do
TEMP=$(awk '{printf "%.3f", $1/1000}' /sys/class/thermal/$sensor/temp)
CHIP=$(cat /sys/class/thermal/$sensor/type)

for id in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi; do
echo "Freq_$id $($VCGEN measure_clock $id | awk '{split($0,a,"="); print a[2]}')" >> $TEMPFILE
done
if [ -z "$TEMP" ];
then
echo "ERROR: Temperature variable empty for $sensor" >&2
else
echo "rpi_temperature{chip=\"$CHIP\",sensor=\"$sensor\"} ${TEMP}" >> $TEMPFILE
fi
done

for id in core sdram_c sdram_i sdram_p; do
echo "Volt_$id $($VCGEN measure_volts $id | awk '{split($0,a,"="); print a[2]}' | sed 's/V$//')" >> $TEMPFILE
done
for id in arm core h264 isp v3d uart pwm emmc pixel vec hdmi dpi; do
echo "rpi_freq{device=\"$id\"} $($VCGEN measure_clock $id | cut -d '=' -f 2)" >> $TEMPFILE
done

for id in arm gpu; do
echo "Mem_$id $($VCGEN get_mem $id | awk '{split($0,a,"="); print a[2]}' | sed 's/M$//')" >> $TEMPFILE
done
for id in core sdram_c sdram_i sdram_p; do
echo "rpi_volt{device=\"$id\"} $($VCGEN measure_volts $id | cut -d '=' -f 2 | sed 's/V$//')" >> $TEMPFILE
done

mv $TEMPFILE $TEXTFILE
fi
for id in arm gpu; do
echo "rpi_mem{device=\"$id\"} $($VCGEN get_mem $id | cut -d '=' -f 2 | sed 's/M$//')" >> $TEMPFILE
done
chown prometheus:prometheus $TEMPFILE
mv $TEMPFILE $TEXTFILE