Skip to content

Instantly share code, notes, and snippets.

@rooreynolds
Created July 3, 2012 17:53
Show Gist options
  • Save rooreynolds/3041367 to your computer and use it in GitHub Desktop.
Save rooreynolds/3041367 to your computer and use it in GitHub Desktop.
Publish Raspberry Pi system stats to Cosm
loadAvg=`uptime | cut -f 6 -d,`
upDays=`uptime | cut -f 4 -d " "`
upHours=`uprecords -s | sed -n '3p' | cut -c 23-25`
upMinutes=`uprecords -s | sed -n '3p' | cut -c 27-28`
upD=`echo "scale=5;$upDays + ($upHours / 24) + ($upMinutes / 24 / 60)" | bc`
users=`w | head -1 | cut -f 3 -d, | awk '{print $1}'`
memFree=`free -m | grep Mem | awk '{print $4}'`
swapFree=`free -m | grep Swap | awk '{print $4}'`
processes=`ps aux | wc -l`
wget -O - --header="X-Http-Method-Override:put" \
--post-data "uptime,$upD
load,$loadAvg
memfree,$memFree
swapfree,$swapFree
processes,$processes
users,$users" \
--header "X-ApiKey: YOUR_COSM_API_KEY" \
--verbose \
http://api.cosm.com/v2/feeds/YOUR_COSM_FEED_ID.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment