mblackstock / node-red-contrib-influxdb

Node-RED nodes to save and query data from an influxdb time series database
Other
64 stars 45 forks source link

issues with datatypes - integer won't recognize correctly #90

Closed iORichy closed 3 years ago

iORichy commented 3 years ago

Hi team,

Thanks for your add-on and I really like it! It's just that a recent error drive me crazy: I try to get system-data from a raspberry into influx via node-red. I have a short function node parsing everything to the correct fields and using influx-batch in order to write tags etc.

Function:

var timestamp1 = Date.now();
var mem_used = (msg.payload.totalmem - msg.payload.freemem);
msg.payload = [
{
    "measurement": "raspi_mem",
    "fields":
    {
        "mem_free": msg.payload.freemem,   
        "mem_percent": msg.payload.memusage,
        "mem_used": mem_used
    },
    "tags":
    {
        "location": "raspi-homematic"
    },
    "time": timestamp1
}]
return msg;

This is the input of the function:

{
    "totalmem":1004507136,
    "freemem":79413248,
    "memusage":92.09
}

This is the output of the function:

[
    {"measurement":"raspi_mem",
    "fields":
        {
        "mem_free":79413248,
        "mem_percent":92.09,
        "mem_used":925093888
    },
    "tags":
    {"location":"raspi-homematic"},
    "time":1615328802057}
]

So it seems to be fine and I have other data-points sending to the same influx db table just with other location tags and doing integer on mem_free and mem_used…

But I always get this error: Error: A 400 Bad Request error occurred: {"error":"partial write: field type conflict: input field \"mem_free\" on measurement \"raspi_mem\" is type float, already exists as type integer dropped=1"}

I have even tried the function to work with hardcoded some real integer like:

    {
        "mem_free": 1,   
        "mem_percent": 20,
        "mem_used": 2
    },

also referring to your #71 I tried to convert to string and include an 'i' as suffix but this just changed the error to "…is type string, already exists as type integer…"

Using Influx-DB v1.0 configuration. I would highly appreciate any help or support. Thanks in advance.

mblackstock commented 3 years ago

Sorry for the trouble. I think this is related to #49. I recall the issue was that I don't have a way to specify/change the schema of the measurement up front to ensure the values sent are coerced to integers. This was the way things worked with the 1.0 configuration and older InfluxDb library.

I'm going to work on supporting the batch node with 1.8 and 2.0 configurations #93 , then you can specify to use integers using the "i" suffix. Are you using InfluxDb 1.8 or 2.0?

iORichy commented 3 years ago

Hi @mblackstock, thanks for your quick and kind response. I‘m using influxDB 1.8 on Raspberry, but with your node I‘m only able to connect via „db 1.0“ as I can‘t set a database with the other connectors. I have enabled InfluxDB 2.0 API and be able to GET /health endpoints correct e.g. and also be able to do queries via this api with another client - but not via node-red. Not sure, but I think it‘s another issue maybe and I don‘t want to mix up for sure! Just try to provide as many information as possible to make it easier for you... Appreciate your response and please let me know if I might be able to help you in advance.

mblackstock commented 3 years ago

Version 0.6.0 adds support for InfluxDb 1.8-Flux and 2.0 in the batch node, as well as specifying integers with the 'i' suffix for those configurations (not 1.x).