raspberrypi prometheus exporter
This commit is contained in:
85
hardware/raspberrypi/prometheus-exporter/files/raspberrypi_exporter.sh
Executable file
85
hardware/raspberrypi/prometheus-exporter/files/raspberrypi_exporter.sh
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
VCGEN="$(command -v vcgencmd)"
|
||||||
|
METRICS_DIR="/tmp/textfile-collector"
|
||||||
|
METRICS_FILE="${METRICS_DIR}/raspberrypi-metrics.prom"
|
||||||
|
TMP_FILE="${METRICS_FILE}.tmp"
|
||||||
|
PREFIX="rpi_"
|
||||||
|
|
||||||
|
[[ ! -d ${METRICS_DIR} ]] && mkdir -p ${METRICS_DIR}
|
||||||
|
|
||||||
|
# remove existing files
|
||||||
|
rm -f "${TMP_FILE}"
|
||||||
|
|
||||||
|
# get temperatures
|
||||||
|
{
|
||||||
|
echo "# HELP ${PREFIX}temperature Temperatures of the components in degree celsius.";
|
||||||
|
echo "# TYPE ${PREFIX}temperature gauge";
|
||||||
|
} >> "${TMP_FILE}"
|
||||||
|
for SENSOR in $(ls /sys/class/thermal/); do
|
||||||
|
unset CPU_TEMP_CELSIUS
|
||||||
|
unset CPU_TYPE
|
||||||
|
|
||||||
|
CPU_TEMP_CELSIUS="$(awk '{printf "%.3f", $1/1000}' /sys/class/thermal/${SENSOR}/temp)" || true
|
||||||
|
CPU_TEMP_CELSIUS="${CPU_TEMP_CELSIUS:=0}"
|
||||||
|
CPU_TYPE="$(cat /sys/class/thermal/${SENSOR}/type)"
|
||||||
|
CPU_TYPE="${CPU_TYPE:=N/A}"
|
||||||
|
|
||||||
|
echo "${PREFIX}temperature{sensor=\"${SENSOR}\",type=\"${CPU_TYPE}\"} ${CPU_TEMP_CELSIUS}" >> "${TMP_FILE}"
|
||||||
|
done
|
||||||
|
GPU_TEMP_CELSIUS="$( $VCGEN measure_temp | cut -d'=' -f2 | cut -d"'" -f1 )" || true
|
||||||
|
GPU_TEMP_CELSIUS="${GPU_TEMP_CELSIUS:=0}"
|
||||||
|
echo "${PREFIX}temperature{sensor=\"bcm2835\",type=\"gpu\"} ${GPU_TEMP_CELSIUS}" >> "${TMP_FILE}"
|
||||||
|
|
||||||
|
# get component frequencies
|
||||||
|
{
|
||||||
|
echo "# HELP ${PREFIX}frequency Clock frequencies of the components in hertz.";
|
||||||
|
echo "# TYPE ${PREFIX}frequency gauge";
|
||||||
|
} >> "${TMP_FILE}"
|
||||||
|
declare -a FREQ_COMPONENTS=("arm" "core" "h264" "isp" "v3d" "uart" "pwm" "emmc" "pixel" "hdmi")
|
||||||
|
for FREQ_COMPONENT in "${FREQ_COMPONENTS[@]}"; do
|
||||||
|
unset FREQUENCE
|
||||||
|
|
||||||
|
FREQUENCE="$($VCGEN measure_clock "${FREQ_COMPONENT}" | cut -d '=' -f 2)" || true
|
||||||
|
FREQUENCE="${FREQUENCE:=0}"
|
||||||
|
|
||||||
|
echo "${PREFIX}frequency{component=\"${FREQ_COMPONENT}\"} ${FREQUENCE}" >> "${TMP_FILE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# get component voltages
|
||||||
|
{
|
||||||
|
echo "# HELP ${PREFIX}voltage Voltages of the components in volts.";
|
||||||
|
echo "# TYPE ${PREFIX}voltage gauge";
|
||||||
|
} >> "${TMP_FILE}"
|
||||||
|
declare -a VOLT_COMPONENTS=("core" "sdram_c" "sdram_i" "sdram_p")
|
||||||
|
for VOLT_COMPONENT in "${VOLT_COMPONENTS[@]}"; do
|
||||||
|
unset VOLTS
|
||||||
|
|
||||||
|
VOLTS="$($VCGEN measure_volts "${VOLT_COMPONENT}" | cut -d '=' -f 2 | sed 's/V$//')" || true
|
||||||
|
VOLTS="${VOLTS:=0}"
|
||||||
|
|
||||||
|
echo "${PREFIX}voltage{component=\"${VOLT_COMPONENT}\"} ${VOLTS}" >> "${TMP_FILE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# get memory split of CPU vs GPU
|
||||||
|
{
|
||||||
|
echo "# HELP ${PREFIX}memory Memory split of CPU and GPU in bytes.";
|
||||||
|
echo "# TYPE ${PREFIX}memory gauge";
|
||||||
|
} >> "${TMP_FILE}"
|
||||||
|
declare -a MEM_COMPONENTS=("arm" "gpu")
|
||||||
|
for MEM_COMPONENT in "${MEM_COMPONENTS[@]}"; do
|
||||||
|
unset MEM
|
||||||
|
|
||||||
|
MEM="$($VCGEN get_mem "${MEM_COMPONENT}" | cut -d '=' -f 2 | sed 's/M$//')" || true
|
||||||
|
MEM="${MEM:=0}"
|
||||||
|
MEM="$(( MEM * 1024 * 1024 ))"
|
||||||
|
|
||||||
|
echo "${PREFIX}memory{component=\"${MEM_COMPONENT}\"} ${MEM}" >> "${TMP_FILE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# write metrics file
|
||||||
|
mv "${TMP_FILE}" "${METRICS_FILE}"
|
||||||
|
|
||||||
|
exit 0
|
||||||
19
hardware/raspberrypi/prometheus-exporter/ini.sls
Normal file
19
hardware/raspberrypi/prometheus-exporter/ini.sls
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
include:
|
||||||
|
- systemd.units
|
||||||
|
|
||||||
|
file-prometheus-exporter:
|
||||||
|
file:
|
||||||
|
- managed
|
||||||
|
- name: /usr/local/sbin/raspberrypi_exporter
|
||||||
|
- source: salt://hardware/raspberrypi/prometheus-exporter/files/raspberrypi_exporter.sh
|
||||||
|
- user: pi
|
||||||
|
- group: gpio
|
||||||
|
- mode: 0755
|
||||||
|
|
||||||
|
raspberrypi_exporter:
|
||||||
|
service.enabled:
|
||||||
|
- enable: True
|
||||||
|
- watch:
|
||||||
|
- file: /usr/local/sbin/raspberrypi_exporter
|
||||||
|
|
||||||
Reference in New Issue
Block a user