Skip to content

Commit

Permalink
Add scsi smart data to prometheus exporter (#862)
Browse files Browse the repository at this point in the history
Add scsi smart data to prometheus exporter

Signed-off-by: mueller <mueller@b1-systems.de>
  • Loading branch information
Bernd Müller authored and SuperQ committed Jul 3, 2018
1 parent ae90bac commit ee1e199
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion text_collector_examples/smartmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

2 comments on commit ee1e199

@kormotodor
Copy link

@kormotodor kormotodor commented on ee1e199 Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not working with scsi typo when it under "Adaptec" controller.

upd: or when disk were emulated on for example with "QEMU"

Example output:

# ./smartmon.sh | grep 'scsi'

smartmon_device_info{disk="/dev/sda",type="scsi",vendor="QEMU",product="QEMU HARDDISK",revision="2.5+",lun_id="",model_family="",device_model="",serial_number="",firmware_version=""} 1
smartmon_device_smart_available{disk="/dev/sda",type="scsi"} 0
smartmon_device_smart_enabled{disk="/dev/sda",type="scsi"} 0
smartmon_device_smart_healthy{disk="/dev/sda",type="scsi"} 0
smartmon_power_cycle_count_raw_value{disk="/dev/sda",type="scsi",smart_id="12"}
smartmon_power_on_hours_raw_value{disk="/dev/sda",type="scsi",smart_id="9"}
smartmon_smartctl_run{disk="/dev/sda",type="scsi"} 1532097570
smartmon_temperature_celsius_raw_value{disk="/dev/sda",type="scsi",smart_id="194"}
smartmon_total_lbas_read_raw_value{disk="/dev/sda",type="scsi",smart_id="242"}

@SuperQ
Copy link
Member

@SuperQ SuperQ commented on ee1e199 Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kormotodor Can you file this as an issue, please include the output, and it would also help to include the output of /usr/sbin/smartctl -A -d scsi /dev/sda.

Please sign in to comment.