I intend to have multiple [[inputs.mqtt_consumer]]
's & [[outputs.influxdb_v2]]
's, and need to ensure that each output, only processes a single matching input.
So in the example below, only topics mybridge/data/sensors
will be sent to the temperature
bucket.
And the same applies to other inputs & outputs.
# # output configuration for incoming mqtt msgs
[[outputs.influxdb_v2]]
urls = ["https://my-server:8999/"]
token = "XYtzjexhtbFmsbk4hgGfhg34gyg34h434jggzptRQ1xBFkU4jtessb7BEbPYMQSl3uFK81o3VwJvZNQ=="
organization = "my server"
bucket = "temperature"
# # Read metrics from MQTT topic(s)
[[inputs.mqtt_consumer]]
servers = ["tcp://localhost:1883"]
topics = ["mybridge/data/sensors",]
topic_tag = ""
qos = 0
username = "zen"
password = "mypassword"
data_format = "json"
I’ve read other posts and the docs, but can’t get my head around namepass
and how its is used, if indeed that is the correct approach…
You will want to use either a namepass
or tagpass
on the outputs, see the selectors docs
If you have two metrics for example:
metric,tag=sensor1 value=42
other,tag=sensor2 value=21
Using namepass
:
# only for metrics called "metric"
[[outputs.influxdb_v2]]
namepass = ["metric"]
# only for metrics called "other"
[[outputs.influxdb_v2]]
namepass = ["other"]
Is that more clear? I think showing what your metrics actually look like would help if you wanted more examples.
Or using tagpass
:
# only for sensor1 tagged metrics
[[outputs.influxdb_v2]]
tagpass = {"tag" = ["sensor1"]}
# only for sensor2 tagged metrics
[[outputs.influxdb_v2]]
tagpass = {"tag" = ["sensor2"]}
@jpowers - my mqtt message is an array of json objects like this;
[
[
{
"temperature": 19.9,
"humidity": 60,
"battery": 2.9,
"rssi": -50,
"time": 1681312968333
},
{
"tag1": "node23",
"tag2": "sensor"
}
]
]
…and have numerous similar messages using "tag2": "sensor"
, but the tag1
varies, such as node25
, node26
etc.
All of the "tag2": "sensor"
messages should be processed by the same output, but which should disregard others, such as;
{
“tag1”: “voltage”,
“tag2”: “diverter”
}
What is your goal? Have any tag2 = sensor to go to one output, but not others?
Yes. All "tag2": "sensor"
to go to the one output, and eventually to the same bucket.
Then I would do the following:
# only metrics with tag2 == sensor go to this output
[[outputs.influxdb_v2]]
tagpass = {"tag2" = ["sensor"]}
# everything not matching tag2 == sensor go to this output
[[outputs.influxdb_v2]]
tagdrop = {"tag2" = ["sensor2"]}
1 Like
Thanks Josh, that’s clear now, and it works exactly how I hoped.
After the reading I did earlier, I think I was expecting it to be much more complicated than that, but it’s pretty straightforward really.
I appreciate your help.
1 Like