Github Mirror / telegraf-plugins: 7dd2a896




Add initial implementation of ssd endurance plugin for utilities/telegraf-plugins#7

Add initial implementation of ssd endurance plugin for utilities/telegraf-plugins#7

Currently untested (and the README needs some work too)

Commit 7dd2a896.

Authored 2022-06-23T20:15:56.000+01:00 by B Tasker in project Github Mirror / telegraf-plugins

+116 lines -0 lines

Commit Signature

Changes

diff --git a/smartctl-ssd-remaining-endurance/.README.md.kate-swp b/smartctl-ssd-remaining-endurance/.README.md.kate-swp
--- a/smartctl-ssd-remaining-endurance/.README.md.kate-swp
+++ b/smartctl-ssd-remaining-endurance/.README.md.kate-swp
# Binary files /dev/null and b/smartctl-ssd-remaining-endurance/.README.md.kate-swp differ
#
diff --git a/smartctl-ssd-remaining-endurance/README.md b/smartctl-ssd-remaining-endurance/README.md
--- a/smartctl-ssd-remaining-endurance/README.md
+++ b/smartctl-ssd-remaining-endurance/README.md
# @@ -0,0 +1,58 @@
# +# SmartCTL SSD Remaining Endurance Exec Plugin for Telegraf
# +
# +### Background
# +
# +This `exec` plugin for Telegraf will use `smartctl` to try and collect the remaining endurance for SSDs so that you can generate alerts on any that are getting too low.
# +
# +
# +
# +### Setup
# +
# +You'll need `smartmontools` installed
# +
# + apt-get install smartmontools
# +
# +The user you run `telegraf` as (usually `telegraf`) will need to be allowed to invoke `smartctl`. The simplest way to do this is to add a sudo permission
# +
# + sudo -s
# + type -p smartctl # make a note of the path
# + visudo
# + telegraf ALL=(ALL) NOPASSWD:<path from above>
# +
# +This should give you something like
# +
# + telegraf ALL=(ALL) NOPASSWD:/usr/sbin/smartctl
# +
# +Save and exit
# +
# +
# +
# +### Configuration
# +
# +Save `smartctl-ssd-remaining-endurances.sh` to disk (I tend to use `/usr/local/src/telegraf_plugins`) and then edit the variables at the top.
# +
# + # Space seperated list of block device names
# + DEVICES=${DEVICES:-"sda"}
# +
# + # Command to use to invoke smartctl
# + SMARTCTL=${SMARTCTL:-"sudo smartctl"}
# +
# +ensure that it's executable
# +
# + chmod +x /usr/local/src/telegraf_plugins/smartctl-ssd-remaining-endurances.sh
# +
# +Then, add an `exec` section to your telegraf config (replacing the path to the file if you used a different one to me)
# +
# + [[inputs.exec]]
# + commands = [
# + "/usr/local/src/telegraf_plugins/smartctl-ssd-remaining-endurances.sh",
# + ]
# + timeout = "60s"
# + interval = "15m"
# + name_suffix = ""
# + data_format = "influx"
# +
# +Then restart telegraf
# +
# + systemctl restart telegraf
# +
#
diff --git a/smartctl-ssd-remaining-endurance/smartctl-ssd-remaining-endurance.sh b/smartctl-ssd-remaining-endurance/smartctl-ssd-remaining-endurance.sh
--- a/smartctl-ssd-remaining-endurance/smartctl-ssd-remaining-endurance.sh
+++ b/smartctl-ssd-remaining-endurance/smartctl-ssd-remaining-endurance.sh
# @@ -0,0 +1,58 @@
# +#!/bin/bash
# +#
# +#
# +# Version 0.1
# +#
# +#
# +
# +
# +# Space seperated list of block device names
# +DEVICES=${DEVICES:-"sda"}
# +
# +# Command to use to invoke smartctl
# +SMARTCTL=${SMARTCTL:-"sudo smartctl"}
# +
# +function get_remaining_percentage(){
# + device=$1
# + cmd_op=`$SMARTCTL -A $device`
# + echo "${cmd_op}" | grep -q "Percentage Used:"
# + if [ "$?" == "0" ]
# + then
# + # New format
# + usage=`echo "${cmd_op}" | grep "Percentage Used:" | awk '{print $NF}' | tr -d '%'`
# + remaining=$(( 100 - $usage ))
# + echo "$remaining"
# + return
# + fi
# +
# + echo "${cmd_op}" | egrep -q "Percent_Lifetime_Remain|Wear_Leveling_Count"
# + if [ "$?" == "0" ]
# + then
# + usage=`echo "${cmd_op}" | egrep "Percent_Lifetime_Remain|Wear_Leveling_Count" | awk '{print $4}'`
# + # Strip any leading 0s by converting from base10 to base10
# + remaining=$((10#$usage))
# + echo "$remaining"
# + return
# + fi
# +}
# +
# +
# +# Iterate over the configured devices
# +for device in $DEVICES
# +do
# + if [ ! -e /dev/$device ]
# + then
# + # Device doesn't exist
# + continue
# + fi
# +
# + lifetime=`get_remaining_percentage /dev/$device`
# + if [ "$lifetime" == "" ]
# + then
# + # Couldn't get a result, skip
# + continue
# + fi
# +
# + # Otherwise, echo out some lp
# + echo "ssd_lifetime,host=$HOSTNAME,device=$device perc_remaining=${lifetime}i"
# +done
#