#!/bin/bash

IFS=' ' read -r -a IOSTAT <<< $(iostat -cd  | tr -d "()" | tr -s " \n" " ")

hostname=${IOSTAT[2]}
userpct=${IOSTAT[13]}
nicepct=${IOSTAT[14]}
syspct=${IOSTAT[15]}
iopct=${IOSTAT[16]}
stealpct=${IOSTAT[17]}
idlepct=${IOSTAT[18]}
rdkbps=${IOSTAT[27]}
wrkbps=${IOSTAT[28]}

IFS=' ' read -r -a DF <<< $(df | grep -e "/$" | tr -s " " " " | tr -d "%")

disk=${DF[0]}
diskused=${DF[2]}
diskfree=${DF[3]}
diskusepct=${DF[4]}

mosquitto_pub -t "v1/cpu0/cpu" -m "hostname=\"$hostname\" userpct=$userpct,nicepct=$nicepct,syspct=$syspct,iopct=$iopct,stealpct=$stealpct,idlepct=$idlepct,rdkbps=$rdkbps,wrkbps=$wrkbps,diskused=$diskused,diskfree=$diskfree,diskusepct=$diskusepct"
