Add scsi smart data to prometheus exporter (#862)

Add scsi smart data to prometheus exporter

Signed-off-by: mueller <mueller@b1-systems.de>
This commit is contained in:
Bernd Müller 2018-07-04 00:30:20 +02:00 committed by Ben Kochie
parent ae90bac5b8
commit ee1e1997bc
1 changed files with 25 additions and 1 deletions

View File

@ -70,6 +70,26 @@ parse_smartctl_attributes() {
| grep -E "(${smartmon_attrs})"
}
parse_smartctl_scsi_attributes() {
local disk="$1"
local disk_type="$2"
local labels="disk=\"${disk}\",type=\"${disk_type}\""
while read line ; do
attr_type="$(echo "${line}" | tr '=' ':' | cut -f1 -d: | sed 's/^ \+//g' | tr ' ' '_')"
attr_value="$(echo "${line}" | tr '=' ':' | cut -f2 -d: | sed 's/^ \+//g')"
case "${attr_type}" in
number_of_hours_powered_up_) power_on="$( echo "${attr_value}" | awk '{ printf "%e\n", $1 }')" ;;
Current_Drive_Temperature) temp_cel="$(echo ${attr_value} | cut -f1 -d' ' | awk '{ printf "%e\n", $1 }')" ;;
Blocks_read_from_cache_and_sent_to_initiator_) lbas_read="$(echo ${attr_value} | awk '{ printf "%e\n", $1 }')" ;;
Accumulated_start-stop_cycles) power_cycle="$(echo ${attr_value} | awk '{ printf "%e\n", $1 }')" ;;
esac
done
echo "power_on_hours_raw_value{"${labels}",smart_id=\"9\"} ${power_on}"
echo "temperature_celsius_raw_value{"${labels}",smart_id=\"194\"} ${temp_cel}"
echo "total_lbas_read_raw_value{"${labels}",smart_id=\"242\"} ${lbas_read}"
echo "power_cycle_count_raw_value{"${labels}",smart_id=\"12\"} ${power_cycle}"
}
parse_smartctl_info() {
local -i smart_available=0 smart_enabled=0 smart_healthy=0
local disk="$1" disk_type="$2"
@ -143,5 +163,9 @@ for device in ${device_list}; do
# Get the SMART information and health
/usr/sbin/smartctl -i -H -d "${type}" "${disk}" | parse_smartctl_info "${disk}" "${type}"
# Get the SMART attributes
/usr/sbin/smartctl -A -d "${type}" "${disk}" | parse_smartctl_attributes "${disk}" "${type}"
case ${type} in
sat) /usr/sbin/smartctl -A -d "${type}" "${disk}" | parse_smartctl_attributes "${disk}" "${type}" ;;
scsi) /usr/sbin/smartctl -A -d "${type}" "${disk}" | parse_smartctl_scsi_attributes "${disk}" "${type}" ;;
*) echo "disk type is not sat or scsi, ${type}"; exit ;;
esac
done | format_output