Logging system stats from NAS to Cosm.com

Cosm.com (formerly Pachube) is an online database that lets you store values and plot them over time. One use is to log system stats from a computer or NAS (in this case a Qnap 419p).

First setup an account on Cosm and add a new Feed, this will give you a feed id which you’ll use in your script. You’ll also need to create an API key.

Then create a script in the /home/ directory on your nas:

cd /home/
nano cosm_sysinfo.sh

Enter the following into the file (put your API key and Feed id in the script towards the end):

loadAvg5min=`cat /proc/loadavg | sed 's/\([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\)\(.*\)/\1/'`
loadAvg10min=`cat /proc/loadavg | sed 's/\([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\)\(.*\)/\2/'`
loadAvg15min=`cat /proc/loadavg | sed 's/\([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\)\(.*\)/\3/'`

upDays=`uptime | cut -f 4 -d " "`
memFree=`free | grep Mem | awk '{print $4}'`
swapFree=`free | grep Swap | awk '{print $4}'`
processes=`ps aux | wc -l`
freeSpace=`df -m | grep /dev/md0 | awk '{print $4}'`
totalSpace=`df -m | grep /dev/md0 | awk '{print $2}'`
ptcSpace=`df -m | grep /dev/md0 | awk '{print $5}' | sed 's/%//'`
temp=`cat /proc/tsinfo/systemp`

hdd1temp=`/sbin/get_hd_temp 1`
hdd2temp=`/sbin/get_hd_temp 2`
hdd3temp=`/sbin/get_hd_temp 3`
hdd4temp=`/sbin/get_hd_temp 4`


wget -O - --header="X-Http-Method-Override:put" \
--post-data "updays,$upDays
hdd4temp,$hdd4temp" \
--header "X-ApiKey: YOU_API_KEY_HERE" \
--verbose \

Make the file executable:

chmod +x cosm_sysinfo.sh

And test the script by running it:


This should give you an output that looks something like this:

[/home] # ./cosm_sysinfo.sh
--2013-01-27 11:32:27-- http://api.cosm.com/v2/feeds/xxxxx.csv
Resolving api.cosm.com..., 2001:470:1f10:333::2
Connecting to api.cosm.com||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1 [text/plain]
Saving to: `STDOUT'

100%[==============================================================================================================================>] 1 --.-K/s in 0s


2013-01-27 11:32:28 (34.5 KB/s) - `-' saved [1/1]

Now head over to cosm.com and look at your feed, it should now be populated with values. Of course, it’s not much fun if this isn’t getting updated regulary, so we’ll set up crontab to update the feed every 5 minutes:

nano /etc/config/crontab

Enter this entry somewhere in the file (this will run the script every 5 minues):

*/5 * * * * /home/cosm_sysinfo.sh

Save the file and load the changes:

crontab /etc/config/crontab

Then all we need to do is restart cron:

/etc/init.d/crond.sh restart

The NAS should now populate the cosm database every 5 minutes and after a while you’ll get something that looks like this:


One response to “Logging system stats from NAS to Cosm.com”

Leave a Reply

Your email address will not be published.