Skip to main content

Performance Co-Pilot and Arduino

Besides being an incredible nice toolkit to work with, Performance Co-Pilot is extremely simple to integrate with any application. Amongst an extensive API it allows to export any metric via JSON using the PMWEBAPI(3). I actived this feature on my Soekris firewall by installing PCP and running both the pmcd and the pmwebd services. Once pmwebd is active, querying any metric is quite simple:

  • In python the first step is to get a context:
    req = requests.get(url=url + 'pmapi/context?local=foo')
    resp = req.json()
    ctx_local = resp['context']
  • With this context we can get info about a specific metric:
    ctxurl = url + 'pmapi/' + str(ctx_local) + '/'
    req = requests.get(url=ctxurl + '_fetch?names=network.interface.out.bytes')
    resp = req.json()

The returned JSON is something along the following lines:

{u'timestamp': {u's': 1412888245, u'us': 443665}, u'values': [{u'instances': 
   [{u'instance': 0, u'value': 503730734}, {u'instance': 1, u'value': 17610637798}, ...

Armed with an Arduino with a 328 Atmel onboard, an Ethernet shield and a 2x16 LCD I wanted to display my ADSL bandwith use. Instead of having to write a network parser for the PCP protocol (or worse SNMP), it's simple to use the exported JSON data for this. Here are the results:

arduino-pcp

I'll eventually clean up the C code I used for this and publish it somewhere.

Comments

Comments powered by Disqus