Storing values that is not present in the message

I have a MQTT stream where I only want to keep the unixtimestamp, the rest of the data is not important and doesn’t contain the data I want to store.
The message is sent every time I have consumed 100l of water and unfortunately doesn’t contain the number 100.
Is there a way where i can use the timestamp from the message and then insert 100 into the database?

You could use count() to see how many messages you get (no matter what the
content is) in a given time period, then multiply that by 100 in your query,
and get the number of litres of water.

Antony.

Tried that but cant figure out how to get it cumulative!
Thought it would be most flexible for the future to get the real value in the database!

Hi @pettaflex , welcome !

that is possible …

> insert mqstream message="limit reached"
> insert mqstream message="limit reached"
> insert mqstream message="limit reached"
> select * from mqstream
name: mqstream
time                message
----                -------
1556883246767552172 limit reached
1556883254824113777 limit reached
1556883259568610336 limit reached
>
> insert mqstream value=100 1556883254824113777
>
> select * from mqstream
name: mqstream
time                message       value
----                -------       -----
1556883246767552172 limit reached
1556883254824113777 limit reached 100
1556883259568610336 limit reached
>

best regards

Is that possible with Telegraf?
I’m getting the stream trough MQTT and Telegraf!

Hi , yes , I guess :slight_smile:

from this document : telegraf/CONFIGURATION.md at master · influxdata/telegraf · GitHub

you can add tags to inputs , this is an example based on the above document for cpu …
I guess you can do the same for MQTT

$ cat cpu.conf
[agent]
  omit_hostname = false
  hostname = "influxserver.com"

[[inputs.cpu]]
   fieldpass = ["usage_idle"]
 [inputs.cpu.tags]
   this_is_my_added_tag="100"


$ telegraf --config  cpu.conf --test
2019-05-03T12:36:06Z I! Starting Telegraf 1.10.1
> cpu,cpu=cpu0,host=influxserver.com,this_is_my_added_tag=100 usage_idle=100 1556886967000000000
> cpu,cpu=cpu1,host=influxserver.com,this_is_my_added_tag=100 usage_idle=100 1556886967000000000
> cpu,cpu=cpu-total,host=influxserver.com,this_is_my_added_tag=100 usage_idle=99.00990098918604 1556886967000000000

I have tried that with inputs.cpu.fields but that didn’t work

Hi.

Seems that tags only marks the data, it’s not possible to use the tag in calculations!

/Peter

Hi ,

to use the tag in calculations ,
I convert it to an integer using the processor.converter in telegraf.

[[processors.converter]]
  [processors.converter.tags]
    integer = ["this_is_my_added_tag"]

the converter creates an extra field which you can access by adding ::field …

> select this_is_my_added_tag::field,this_is_my_added_tag::field *7 from cpu order by desc limit 5
name: cpu
time                this_is_my_added_tag this_is_my_added_tag_1
----                -------------------- ----------------------
1557145110000000000 100                  700
1557145110000000000 100                  700
1557145110000000000 100                  700
1557145100000000000 100                  700
1557145100000000000 100                  700

I also tested what happens when I drop the measurement cpu ,
then the tag is gone and only the field with the value 100 remains …

So to add a default field in a measurement , you can combine the
[inputs.cpu.tags] //in my case
and the
[processors.converter.tags]
integer = [“this_is_my_added_tag”]

here is a link to the converter
and there is also the rename that you could use …

hope this solves your problem ,
best regards