In a previous blog post, I was talking about how to send IoT sensor data to Hawkular-metrics.
While this already works quite well, it also lacks the integration with other parts of Hawkular, namely Inventory and Alerting.
In this blog post I will talk about integration with Inventory and how to view the data in the Hawkular-UI. An upcoming article will then talk about Alerting.
I have modified the setup from the last post a bit:
New setup with a Ruby client
Instead of PTrans I've written a small Ruby client, that makes use of the Hawkular-Client-Ruby ruby gem (it needs version 0.2.1, that has not yet been published to RubyGems.org. In addition it uses a MQTT gem, which makes the code pretty short.
The Ruby client MQTT-bridge now listens on /hawkular/+
topics. Metric arriving on /hawkular/metrics
are forwarded as such and registration messages on /hawkular/register
are used to register the external resource like the ESP8622 micro controller in Hawkular inventory.
The following is an example registration message:
{"feed": "esp16617927", "rt":"esp8266", "r":"mcu16617927", "mt":{ "id":"thermo", "unit":"NONE", "type":"GAUGE", "collectionInterval":0 }, "m":{ "id":"16617927:40.176.91.120.5.0.0.125", "mt":"thermo", "na":"thermo_40.176.91.120.5.0.0.125", } }
You can get the client from https://github.com/pilhuhn/hawkular-mqtt-bridge and then easily run it via
$ ruby lib/hawk.rb
If you are not using a Hawkular-Server on localhost with default user, then you first need to modify the ruby code at the top.
The client will connect to the Hawkular server and then wait for messages on the MQTT topics.
The client code is still rather simplistic and does not spool data when the target Hawkular server is down.
UI
Since Hawkular 1 Alpha11 we have an Explorer (as easter egg :-) that allows to browse through inventory and to show resources and their metrics. The following shows the explorer with a chart from the thermo sensor for the last 12h.
Hawkular UI with chart of sensor data from last 12h
The chart shows a peak at 1am - I have no idea why it is there. Possibly one of my cats examined the sensor :)
ESP Sample code
I have also provided a sample Lua script, that can be used on a ESP8266 like the Adafruit Huzzah shown in the previous post.
As the stock Huzzah comes with NodeMCU Lua 0.9.5 which was not working well for me, I have flashed it with a newer version of NodeMCU Lua. This is now running a firmware with the following modules:
NodeMCU custom build by frightanic.com branch: master commit: c8037568571edb5c568c2f8231e4f8ce0683b883 SSL: false modules: cjson,file,gpio,i2c,mqtt,net,node,ow,rtcmem,rtctime,sntp,tmr,uart,wifi,ws2812 build built on: 2016-02-18 08:33
Alerting?
In an upcoming post I will talk about alerting in Hawkular to act on unusually high or low temperatures.
No comments:
Post a Comment