DataYours: InfluxDB as an AltUI Data Storage Provider

Okay, suppose I wanted to try InfluxDB. What’s involved in registering it as an AltUI data storage provider? Thanks.

Just a question of knowing what format and credentials it needs to send it data, writing that as a little callback handler, and making an action call to AltUI. The code in DataYours that does it could be a template for what’s needed, but it’s probably only a few tens of lines of code.

Having taken a quick look at the docs for InfluxDB, I see that it has an interface which accepts Graphite data streams. It may be that you can link directly to that with the existing DataYours code.

Basically I’d need to set “DESTINATIONS” in the DataYours variables to the IP and UDP port of the InfluxDB server (which must be configured to use UDP). Correct? Then debug any issues…

Yes, indeed. That’s what I’d try first.

I’ll split these recent posts out into a new thread re. InfluxDB.

done!

I can say that this does work and isn’t too hard to enable. Get the InfluxDB running, enable the Graphite plugin and switch it to UDP in the config file and it will accept data. There is a translation from the Graphite measurement names to the tags used by InfluxDB that can be customized. On the openLuup side just add the port to the DESTINATIONS and reload openLuup (didn’t realize I needed a reload on the first try).

One note about Grafana: when I first brought this up, the test button said the database was fine, but I got the red exclamation point in the panels. Then I reloaded the browser and it worked. It wasn’t obvious that this would be required, but apparently it is.

That’s the good news. I don’t have it doing everything I want, but I haven’t had any time to read over the InfluxDB documentation. For standard stuff such as temperature, it works well.

Oh, this is excellent news - thumbs up to industry standards!

I have anyway been mulling over making the front-end part of DataYours (i.e. DataWatcher, which is the bit which registers with AltUI as a Data Service Provider) an integral part of openLuup, which would mean that for this configuration (and similar) you wouldn’t need DataYours at all.

Yes indeed, the key variables like DESTINATIONS are not dynamic, and only read at startup.

On what platform did you install InfluxDB?

I’m running InfluxDB on the very same RPi that is also running openLuup, openHAB, Z-way. I’m a bit worried about running out of steam on it. And I’m worried about the flash storage. Either I’m going to get an external drive attached to the RPi or switch to different hardware. For now, though, it works. About 2.5% CPU most of the time. I think InfluxDB can use quite a bit of resources, but I’m only sending it temperature and power every few minutes so the workload isn’t much. Probably takes a hit on queries.

After some use of InfluxDB I can see that it would be handy if we could register the http write interface in AltUI instead of using the Graphite plugin. The http interface allows more flexibility as might be expected. It’s a basic POST request with a few parameters: InfluxDB API reference | InfluxDB OSS 1.3 Documentation. With that interface you can select the database, set the precision, change the retention policy and set a password, etc.

I can write functions in the plugins I care about to directly do the POST, but it would be nicer and much more flexible to have it in AltUI.

Is this something that needs to be requested from amg0? I’m not sure what is involved in getting it added or how feasible it is.

[quote=“jswim788, post:10, topic:197151”]I can write functions in the plugins I care about to directly do the POST, but it would be nicer and much more flexible to have it in AltUI.

Is this something that needs to be requested from amg0? I’m not sure what is involved in getting it added or how feasible it is.[/quote]

No, you can do it yourself. Rather straight-forward to write a piece of code which will register as a Data Storage Provider to AltUI, pick up the monitored data and POST it to InFlux.

I haven’t looked at the API yet, but I imagine it’s not an issue.

Okay, follow this thread, correct? http://forum.micasaverde.com/index.php/topic,35860.msg265383.html#msg265383

But one item I don’t understand. You’ve used this for the URL:

url = "http://127.0.0.1:3480/data_request?id=lr_DataWatcherRelay&format=altui"

How does this get translated to a lua function? Or more precisely, how do I choose the URL for my own function and then get the function connected to the URL?

By the way, if the AltUI supported POST directly, I wouldn’t need the above, correct? A function does allow me to format the data and do some sanity checking, so it is nice, but if the data were in good shape initially, all I’m missing is the POST I think.

once again: thank you!

With luup.register_handler… Okay, I’ll give this a try. L_DataWatcher.lua is the example to follow.

Yes, exactly. You beat me to it.

By the way, if the AltUI supported POST directly, I wouldn't need the above, correct? A function does allow me to format the data and do some sanity checking, so it is nice, but if the data were in good shape initially, all I'm missing is the POST I think.

I don’t think that this is the case. Different Data Storage Providers require different APIs. The purpose of the intercept code is to address these issues, and also to add some degree of tailoring. Whilst the original HTTP GET request from AltUI includes the variable’s name/serviceId/new value parameters, it also includes the various parameters which you may have added during registering your code. This allows, for example, DataYours to select a completely different variable name to put into the database. AltUI includes code for thingspeak and emoncms, but the same API tailoring goes on inside. DataYours adds its own, as does each VeraBridge instance, to allow ‘mirroring’ of openLuup variables back onto bridged Veras. The mechanism is very flexible. Hats off to @amg0!!

Have you given any thought as to how to get a rendered graph back into AltUI from InfluxDB / Grafana?

I’ve attached a working example of the InfluxDB relay. It doesn’t have much checking, but it does work for me. Anybody trying this should look at the InfluxDB page on writing data: Writing Data with the HTTP API | InfluxDB OSS 1.3 Documentation

Couple of questions: I retained the “_G.” for the luup.register_handler function, but since I’ve put this code in the startup lua, I don’t think it is needed. True? I’m not 100% sure what the “_G” is, but I’m guessing it is the global environment? Also, I’ve pulled in dkjson, but isn’t there an openLuup json? I thought I saw that somewhere but I’m not sure if that replaces dkjson or not.

As to displaying this in AltUI, I know we can get an embed link such as this via the “share” button:

And you can get a rendered image:

http://192.168.1.205:3000/render/dashboard-solo/db/chelan-dashboard?orgId=1&panelId=2&from=1505445867042&to=1506050667042&width=1000&height=500&tz=UTC-07%3A00

But I don’t know how to get these into AltUI.

EDIT: Added entry for InfluxDB server IP and port with default as 127.0.0.1:8086, switched to openLuup.json

Great stuff!

Couple of questions: I retained the "_G." for the luup.register_handler function, but since I've put this code in the startup lua, I don't think it is needed. True? I'm not 100% sure what the "_G" is, but I'm guessing it is the global environment?

Yes, _G is the global environment. Whether you need to use it or not may depend on the context of your code and how it’s referenced. There are, in fact, not really ANY true globals in Lua. If the ‘global’ name is in a module, it’s global to that module, but the name may be referenced within the external module name. Depends to some extent on how it was written and how it was loaded. If this works, you may as well keep it.

Also, I've pulled in dkjson, but isn't there an openLuup json? I thought I saw that somewhere but I'm not sure if that replaces dkjson or not.

Oh, yes. It’s used all over the place in openLuup, try:

local json = require "openLuup.json"

The openLuup installation does pull down a copy of dkjson.lua, simply because that’s what UI7 uses (UI5 had no standard one) and some plugins may expect it. The openLuup one is nicer for debugging since it pretty-prints the encoded JSON, so you can actually read it if you take a look at it.

As to displaying this in AltUI, I know we can get an embed link such as this via the "share" button:

No need for all this, I think, since AltUI already does it for you in the variable’s push data page. What you need is to include the information in the graphic_url parameter when you register as a Data Storage Provider.

http://192.168.1.205:3000/render/dashboard-solo/db/chelan-dashboard?orgId=1&panelId=2&from=1505445867042&to=1506050667042&width=1000&height=500&tz=UTC-07%3A00

Oh, excellent - I didn’t know that (did I miss some documentation?) Now we can definitely get rid of DataYours for doing this entirely within the openLuup (+Grafana) environment. I will give this a go!

But I don't know how to get these into AltUI.

…you do now?

Oh, excellent - I didn't know that (did I miss some documentation?)

…ah, got it, I think…

http://docs.grafana.org/reference/sharing/

That’s the one. The links from the “share” button will be fine for local use, but if remote, I think I’ll need to hide this behind a request similar to lr_render?

Thanks for the answers on the InfluxDB relay code - I’ll update it.

…hmm, doesn’t work for me, but I have it installed on a BeagleBone Black, not a RPi, so maybe need the extra library they mention.

So far I can only get the full panel link to work. If I try the ‘render’ or ‘dashboard-solo’ I get nothing or just the header but no graph. I’ve attached a picture of what does work.