smartctl to influx

From Rude Dolphin, 1 Year ago, written in Bash, viewed 248 times.
URL https://paste.steamr.com/view/70fcb352 Embed
Download Paste or View Raw
  1. # cat /usr/sbin/smartctl-influx.sh
  2. #!/bin/bash
  3.  
  4. lsblk | grep disk | while read device _ ; do
  5.         /usr/sbin/smartctl -a /dev/$device \
  6.                 | awk -v timestamp=$(date +%s"000000000") '
  7. function after(x) {
  8.        out=""
  9.        for (i=x; i<=NF; i++) out=out" "$i
  10.        return out
  11. }
  12. BEGIN {
  13.        Model="none"
  14.        Serial="none"
  15. }
  16. /^Device Model:/ {
  17.        Model=after(3)
  18.        sub(/^[ \t\r\n]+/, "", Model)
  19.        gsub(" ", "_", Model)
  20. }
  21. /^Serial Number:/ {
  22.        Serial=after(3)
  23.        sub(/^[ \t\r\n]+/, "", Serial)
  24.        gsub(" ", "_", Serial)
  25. }
  26. /^\s*[0-9]+ [a-zA-Z_-]{5,}/ {
  27.        if ( $10 ~ /^[0-9]+$/ )
  28.                Values[$1]=$10
  29. }
  30.  
  31. END {
  32.        if (Serial != "none") {
  33.                        printf("disk,serial=" Serial ",model=" Model " ")
  34.  
  35.                        first=1
  36.                        for (value in Values) {
  37.                                        if ( ! first) printf(",")
  38.                                        first=0
  39.                                        printf(value"="Values[value])
  40.                        }
  41.                        printf(" " timestamp "\n")
  42.        }
  43. }
  44. ' \
  45.         | while read data ; do
  46.                 curl --header "Authorization: Token ..." -X POST 'http://influxdb/write?db=smartctl' --data-binary "$data"
  47.         done
  48. done
  49.  

Reply to "smartctl to influx"

Here you can reply to the paste above