Ask Your Question
0

Influx Destination not compatible with 2.0

asked 2021-10-29 18:27:13 -0600

graphadvantage gravatar image

Hi,

Any tips for addressing Influx 2.0 compatibility, seems the existing InfluxDB destination is set for v1 and not v2 which uses "bucket name" instead of "database name"

Thanks

Michael

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-11-01 13:53:32 -0600

graphadvantage gravatar image

updated 2021-11-01 13:54:16 -0600

ok folks here's the answer to this one

it's a little bit of a long walk, but it works

  1. create a groovy evaluator that generates a string in the the InfluxDB 2 line protocol format
  2. Use the HTTP destination to submit a POST request

Step one:

given some JSON:
{"CycleTime":72,"OperationalSetting1":0.0041,"OperationalSetting2":-5.0E-4,"OperationalSetting3":100.0,"Sensor1":518.67,"Sensor2":642.39,"Sensor3":1595.06,"Sensor4":1403.69,"Sensor5":14.62,"Sensor6":21.61,"Sensor7":554.01,"Sensor8":2388.08,"Sensor9":9046.32,"Sensor10":1.3,"Sensor11":47.39,"Sensor12":522.03,"Sensor13":2388.06,"Sensor14":8131.7,"Sensor15":8.4101,"Sensor16":0.03,"Sensor17":391.0,"Sensor18":2388.0,"Sensor19":100.0,"Sensor20":39.03,"Sensor21":23.2905}

converts the above JSON to influx line protocol

"digital_twin,location=midland-basin,pad=baker-9A cycletime=1,operationalsetting1=0.0014,operationalsetting2=-0.0,operationalsetting3=100.0,sensor1=518.67,sensor2=642.58,sensor3=1585.73,sensor4=1398.43,sensor5=14.62,sensor6=21.61,sensor7=553.44,sensor8=2388.05,sensor9=9064.87,sensor10=1.3,sensor11=47.16,sensor12=521.88,sensor13=2388.05,sensor14=8142.76,sensor15=8.4195,sensor16=0.03,sensor17=392.0,sensor18=2388.0,sensor19=100.0,sensor20=39.0,sensor21=23.2726 1635789187830000000"

a script for the groovy evaluator

def batch_list = []
def attributes = {}
def sourceId = ''
def data = ''
def ts = int

records = sdc.records
for (record in records) {
    try {
      ts = new Date().getTime()*1000000 //nanoseconds
      attributes = record.attributes
      data = record.value.text.toString().toLowerCase()
      data = data.replace('"','')
      data = data.replace(':','=')
      data = data.replace('{','')
      data = data.replace('}','')
      data = 'digital_twin,location=midland-basin,pad=baker-9A ' + data + ' ' + ts
      batch_list.add(data)

      sourceId = record.sourceId


    } catch (e) {
        // Write a record to the error pipeline
        sdc.log.error(e.toString(), e)
        sdc.error.write(record, e.toString())
    }
}

def newRecord = sdc.createRecord(sourceId + ':newRecordId')
newRecord.value = ['data': batch_list]
sdc.output.write(newRecord)

Next step configure the http client using your token

using this url format

http://localhost:8086/api/v2/write?org=neo4j&bucket=iot-test&precision=ns

and the suggested headers from the docs (see below)

[
    {
        "key": "Content-Type",
        "value": "text/plain;charset=utf-8"
    },
    {
        "key": "Accept",
        "value": "application/json"
    },
    {
        "key": "X-Stream",
        "value": "true"
    },
    {
        "key": "Authorization",
        "value": "Token drmJgo6bOSqI8Fl7agf582qxuaimyduYPk2lXA_yDk7myRRCzfTnvMq9vFM0JgVrXNvm-F_QLQSxf9I4qxmywg=="
    }
]

https://docs.influxdata.com/influxdb/...

and a little fooling around in influxdb dashboards and you can get something like this that updates as data streams in

image description

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-10-29 18:27:13 -0600

Seen: 166 times

Last updated: Nov 01