olimp/roles/proxmox_base_setup/templates/storcli_metrics.sh.j2
Administrator 906555ab4b Update 4 files
- /roles/proxmox_base_setup/tasks/main.yml
- /roles/proxmox_base_setup/templates/node_exporter.service.j2
- /roles/proxmox_base_setup/templates/storcli_metrics.sh.j2
- /roles/proxmox_base_setup/handlers/main.yml
2025-11-14 06:18:58 +00:00

64 lines
2.9 KiB
Django/Jinja

#!/bin/bash
if (enc != "" && slot != "") {
# Вывести предыдущий диск
gsub(/ /, "_", model);
printf "storcli_disk_temp{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, (temp ~ /^[0-9]+$/ ? temp : 0)
printf "storcli_disk_state{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, state_num
printf "storcli_disk_media_error_count{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, media_err
printf "storcli_disk_other_error_count{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, other_err
}
enc=""; slot=""; model=""; temp=""; media_err=0; other_err=0; state_num=0
}
/Enclosure Device ID:/ { enc = $4 }
/Slot Number:/ { slot = $3 }
/Device Id:/ { if (enc == "") enc = $3 } # fallback
/Model Number:/ { model = $3 }
/Drive Temperature/ {
match($0, /([0-9]+)C/);
if (RSTART) temp = substr($0, RSTART, RLENGTH-1)
}
/Firmware state:/ {
state = $3
if (state ~ /Online/) state_num = 2
else if (state ~ /Unconfigured.*Good/) state_num = 1
else if (state ~ /Failed/) state_num = 3
else if (state ~ /Rebuild/) state_num = 4
else if (state ~ /Offline/) state_num = 0
else state_num = -1
}
/Media Error Count:/ { media_err = $4 }
/Other Error Count:/ { other_err = $4 }
END {
if (enc != "" && slot != "") {
gsub(/ /, "_", model);
printf "storcli_disk_temp{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, (temp ~ /^[0-9]+$/ ? temp : 0)
printf "storcli_disk_state{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, state_num
printf "storcli_disk_media_error_count{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, media_err
printf "storcli_disk_other_error_count{controller=\"%s\",enclosure=\"%s\",slot=\"%s\",model=\"%s\"} %s\n", c, enc, slot, model, other_err
}
}
' c="$c")
echo "$disks_info" >> "$OUT_FILE"
# Виртуальные диски (массивы)
vds=$(storcli /c$c/vall show | awk '
NR>8 && $1 ~ /^[0-9]+$/ {
vd = $1; state = $2; size = $3;
gsub(/,/,"", size);
# state: Optl=Online(1), Dgrd=Degraded(2), Offln=Offline(0), Ft=Failed(3)
state_num = 1;
if (state == "Dgrd") state_num = 2;
else if (state ~ /Offln|Pdgd/) state_num = 0;
else if (state == "Ft") state_num = 3;
printf "storcli_array_state{controller=\"%s\",vd=\"%s\",size=\"%s\"} %s\n", c, vd, size, state_num
}
')
echo "$vds" >> "$OUT_FILE"
done
# Атомарная замена
mv "$OUT_FILE" "$FINAL_FILE"
chmod 644 "$FINAL_FILE"
echo "$(date -Iseconds) storcli metrics updated" >&2