This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

influxdb
#1
I want to store LM object (values) data in an influxdb database, does anybody have any experience with this?

Their documentation (https://docs.influxdata.com/influxdb/v1....ting_data/) says that you can use the http api for storing data like this;
Code:
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

Is this possible from lua in the LM? 

Thanks Mischa
Reply
#2
Code:
http = require('socket.http')
http.TIMEOUT = 5
res, err = http.request('http://192.168.1.2:8086/write?db=mydb', 'cpu_load_short,host=server01,region=us-west value=0.64')
log(res, err)
Reply
#3
(13.08.2018, 11:25)admin Wrote:
Code:
http = require('socket.http')
http.TIMEOUT = 5
res, err = http.request('http://192.168.1.2:8086/write?db=mydb', 'cpu_load_short,host=server01,region=us-west value=0.64')
log(res, err)

Thanks, works perfectly.
Reply
#4
Hi 
I have tried this influxdb-connection and got it to work.
I want to write several tags to influxdb and can't really figure out the best way to do this in scripts.....

Data like temperatures, Co2 and also presence objects are data I need to log i influx. 
Could anyone give me a push in the right direction here. 
Planning to use this with grafana. 

Everything is up and running but can't figure out the most vital part:-)

Eirik
Reply
#5
This code will send everything it captures to influx, then you can filter whatever you want in grafana. Create resident script with zero delay



Code:
local socket = require('socket')
local http = require('socket.http')
http.TIMEOUT = 5


local dt_cache = {}
function get_value(addr, datahex)
  local dt = dt_cache[addr]

  if(not dt) then
    dt = grp.find(addr)
    dt_cache[addr] = dt
  end
 
  return knxdatatype.decode(datahex, dt.datatype), dt
end

function knx_callback(event)
  local addr = event.dst
  local value, dt = get_value(addr, event.datahex)

  send_metric('rawdata', dt.name, addr, value)
end


function send_metric(table, name, addr, value)
  if(name == nil or name == '') then
    return
  end
 
  name = string.gsub(name, ' ', '\\ ')
 
  local url = 'http://IP:8086/write?db=knxdb'
  local args
  if(type(value) == 'boolean') then
    args = string.format('%s,name=%s,addr=%s state=%s', table, name, addr, value)
  else
    -- most likely number
    args = string.format('%s,name=%s,addr=%s value=%s', table, name, addr, value)
  end
  res, err = http.request(url, args)
  if(err ~= 204) then
    log('error sending to influx', res, err, args)
  end
end

function run_loop()
  local bus = require('localbus').new(1)
  bus:sethandler('groupwrite', knx_callback)
  local busfd = socket.fdmaskset(bus:getfd(), 'r')

 
  while(true) do
    res, fbus = socket.selectfds(10, busfd)
    if(fbus) then
      bus:step()
    end
  end
end

run_loop()
Reply


Forum Jump: