From ee1e1997bcd04c4a2b23380204a92029a85c6e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernd=20M=C3=BCller?= Date: Wed, 4 Jul 2018 00:30:20 +0200 Subject: Add scsi smart data to prometheus exporter (#862) Add scsi smart data to prometheus exporter Signed-off-by: mueller --- text_collector_examples/smartmon.sh | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'text_collector_examples') diff --git a/text_collector_examples/smartmon.sh b/text_collector_examples/smartmon.sh index cca3478..9b0c7d4 100755 --- a/text_collector_examples/smartmon.sh +++ b/text_collector_examples/smartmon.sh @@ -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 -- cgit v1.2.3