Created
February 1, 2026 18:00
-
-
Save Preclowski/d0ebc1502a87cd29573cfd64ff58d7f0 to your computer and use it in GitHub Desktop.
Snapraid disk spin status prometheus textfile exporter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "# HELP snapraid_disk_state Disk state in SnapRAID: 1=Active, 0=StandBy" | |
| echo "# TYPE snapraid_disk_state gauge" | |
| echo "# HELP snapraid_disks_active_total Total Active disks" | |
| echo "# TYPE snapraid_disks_active_total gauge" | |
| echo "# HELP snapraid_disks_standby_total Total StandBy disks" | |
| echo "# TYPE snapraid_disks_standby_total gauge" | |
| snapraid probe | awk ' | |
| NR>2 && NF>=2 && $1 != "State" { | |
| state=$1 | |
| device=$2 | |
| disk="" | |
| for(i=3;i<=NF;i++) disk=(disk=="")?$i:disk" "$i | |
| if(disk=="-") disk="" | |
| value=(state=="Active")?1:0 | |
| printf("snapraid_disk_state{device=\"%s\",disk=\"%s\"} %d\n", device, disk, value) | |
| if(value==1) active++ | |
| else standby++ | |
| } | |
| END { | |
| printf("snapraid_disks_active_total %d\n", active) | |
| printf("snapraid_disks_standby_total %d\n", standby) | |
| }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment