
#!/bin/sh
# File	: get_system_cpuload.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"

GROUPNAME="nl"
HOSTNAME="`hostname |cut -d\. -f1`" 
# Graphite: system.<group>|nl.<hostname>.<device>|bmp180|rpi.<item>-<value>|temperature-c|pressure-mbar
# Filename: system-<group>|nl-<hostname>-<device>_<date>.csv
DATAFILE="${DATADIR}/system-${GROUPNAME}-${HOSTNAME}-cpuload_`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;cpu-1m;cpu-5m;cpu-15m;" > ${DATAFILE}
fi

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

exit 0

