
#!/bin/sh
# File	: get_cpu-load.sh
# By	: MaartenDeBoer.nl, 160226, 161006
# Subject	: Script to log the cpu-load in a CSV-file
PGM="`basename $0|cut -d\. -f1`"
VER="0.1"

DATADIR="${HOME}/data"
HOSTNAME="`hostname |cut -d\. -f1`" 
# Graphite: domotica.<group>|nl.<hostname>.<device>|bmp180|rpi.<item>-<value>|temperature-c|pressure-mbar
# Filename: domotica-<group>|nl-<hostname>-<device>|bmp180|rpi.csv
DATAFILE="${DATADIR}/domotica-nl-${HOSTNAME}_`date +%Y-%m-%d`.csv"

# If DATADIR does not exist, create this dir
if [ ! -d ${DATADIR} ]; then
  mkdir -p ${DATADIR}
fi

# If file does not exist, create by adding header
if [ ! -f ${DATAFILE} ]; then
   echo "# Date time;temperature-c;cpu-1m;cpu-5m;cpu-15m;" > ${DATAFILE}
fi

echo -n "`date +%Y-%m-%d' '%H:%M:%S`; ;"|tee -a ${DATAFILE}
echo    "`uptime|cut -d\, -f4-6|cut -d\: -f2|sed 's/,/;/g'`;"|tee -a ${DATAFILE}

exit 0

