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 that you accept these cookies being set.

massive data logging
#11
(15.09.2022, 12:55)admin Wrote: This example will push only objects that have influx tag attached.

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

local objs = {}
local tagobjs = grp.tag('influx')

for _, obj in ipairs(tagobjs) do
  objs[ obj.address ] = {
    name = obj.name:gsub(' ', '\\ '),
    datatype = obj.datatype,
  }
end

function callback(event)
  local addr = event.dst
  local obj = objs[ addr ]

  if obj then
    local value = knxdatatype.decode(event.datahex, obj.datatype)
    sendmetric('rawdata', obj.name, addr, value)
  end
end

function sendmetric(table, name, addr, value)
  local url = 'https://europe-west1-1.gcp.cloud2.influxdata.com/api/v2/write?bucket=XX&org=XXX'
  local body

  if type(value) == 'boolean' or type(value) == 'number' then
    body = string.format('%s,name=%s,addr=%s state=%s', table, name, addr, value)
  elseif type(value) == 'string' then
    body = string.format('%s,name=%s,addr=%s value=%q', table, name, addr, value)
  else
    log('invalid data type', addr, type(value))
    return
  end

  local res, code = http.request({
    url = url,
    method = 'POST',
    body = body,
    headers = {
      Authorization = 'Token XXXXXXXXXXXXXXXXXXX'
    }
  })

  if code ~= 204 then
    log('error sending to influx', res, code, body)
  end
end

local busclient = require('localbus').new()
busclient:sethandler('groupwrite', callback)

while true do
  busclient:loop(1)
end

Everything is fine (although I still have to learn how to handle the data to create a decent report Smile )

Now  I have the final step: to connect influxdb to Grafana.

I don't know how to choose the right authentication metod to connect it. Where to put the token and org name??!

Attached Files Thumbnail(s)
       
Reply


Messages In This Thread
massive data logging - by gdimaria - 05.09.2022, 16:22
RE: massive data logging - by admin - 06.09.2022, 10:08
RE: massive data logging - by gdimaria - 07.09.2022, 07:42
RE: massive data logging - by admin - 07.09.2022, 07:47
RE: massive data logging - by gdimaria - 14.09.2022, 11:14
RE: massive data logging - by admin - 14.09.2022, 11:33
RE: massive data logging - by gdimaria - 15.09.2022, 09:05
RE: massive data logging - by admin - 15.09.2022, 09:23
RE: massive data logging - by gdimaria - 15.09.2022, 10:04
RE: massive data logging - by admin - 15.09.2022, 12:55
RE: massive data logging - by gdimaria - 16.09.2022, 10:26
RE: massive data logging - by admin - 19.09.2022, 06:10

Forum Jump: