bgirardot
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Simple data logging to COSM for online graphs

Thu Oct 25, 2012 6:37 am

I wanted to try out COSM, a website that allows you to feed it data and it stores and graphs the data. I still don't quite know all the details, I am only using the free version.

Anyway, I created a simple feed of the load averages of my RPi, which runs nothing but the stock raspbian 09-18-2012 image and does nothing but run my little shell script. Eventually I will be using COSM to log current and voltage data from a portable solar generator.

The feed is located here:
https://cosm.com/feeds/82165

Here are the steps I followed if anyone is interested in doing something similar:

1. Created a COSM account
2. Created a COSM feed, "something else", push data to feed
3. Created 3 datastreams in that feed
4. Generated an API key in COSM for the feed with 'update' permissions
5. Wrote a 1 line sed "script" on my RPi to transform /proc/loadavg to JSON format for COSM. I am not sure how this will display, but here is the one line:

Code: Select all

s/\([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\)\(.*\)/{"datastreams":[ {"id":"5min","current_value":"\1"},{"id":"10min","current_value":"\2"},{"id":"15min","current_value":"\3"} ]}/
6. I made a two line shell script to transform /proc/loadavg to JSON and save it out to a file and the use curl to send it to COSM

Code: Select all

sed -f cosm-test.sed /proc/loadavg > cosm-test.json
curl --request PUT --data-binary @cosm-test.json --header "X-ApiKey: api_key_I_generated_here" http://api.cosm.com/v2/feeds/82165
7. Created a crontab entry to call my shell script once a minute

I just wanted to create a post about it because I have so far found COSM to be pretty easy to use and a nice service.

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Simple data logging to COSM for online graphs

Thu Oct 25, 2012 9:51 am

It might also be worth considring gnuplot for generating graphs. Feed it a series of numbers or number pairs and it usually comes up with a sensible graph.

Tafkas
Posts: 49
Joined: Sun Sep 16, 2012 11:15 pm
Contact: Website

Re: Simple data logging to COSM for online graphs

Thu Oct 25, 2012 10:12 am

I will definitily look into cosm. So far I have been generating my charts using munin:
Image
Image
Image

bgirardot
Posts: 517
Joined: Wed Oct 10, 2012 6:20 am
Location: Switzerland

Re: Simple data logging to COSM for online graphs

Thu Oct 25, 2012 12:53 pm

Thank you for the heads up on gnuplot and munin, I was just thinking that cosm didn't seem to offer a lot of options for different types of graphs, but that may just be my unfamiliarity with it still.

Cosm does make it easier for me in the sense that I don't have to run a web server anywhere to make my data public and they have a bit of a renewable energy community focus. Cosm lets you pull the data back via json, xml or csv so maybe I end up with an upload to cosm just for storage and public access and then nicer, more flexible local graphs via gnuplot or munin.

Thanks again.

Return to “Automation, sensing and robotics”