Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

processors.regex doesn't works well. or works unstable #4787

Closed
Dees7 opened this issue Oct 2, 2018 · 11 comments
Closed

processors.regex doesn't works well. or works unstable #4787

Dees7 opened this issue Oct 2, 2018 · 11 comments

Comments

@Dees7
Copy link

Dees7 commented Oct 2, 2018

Relevant telegraf.conf:

[global_tags]                       
[agent]                             
  interval = "5s"                   
  round_interval = true             
  metric_batch_size = 500           
  metric_buffer_limit = 1000        
  collection_jitter = "0s"          
  flush_interval = "10s"            
  flush_jitter = "0s"               
  precision = ""                    
  debug = true                      
  quiet = false                     
  logfile = ""                      
  hostname = ""                     
  omit_hostname = true              
[[processors.printer]]              
[[processors.regex]]                
    [[processors.regex.tags]]       
      key = "topic"                 
      pattern = ".*/(.*)/.*"        
      replacement = "${1}"          
      result_key = "topicname"      
[[inputs.mqtt_consumer]]            
  servers = ["tcp://localhost:1883"]
  qos = 0                           
  connection_timeout = "30s"        
  topics = ["test/#"]               
  persistent_session = true         
  client_id = "telegraftest"        
  username = "name"                 
  password = "pass"    
  name_override = "mqttc"           
  tag_keys = ["hostname"]           
  data_format = "json"              
[[outputs.file]]                    
   files = ["stdout"]               
   data_format = "graphite"         

System info:

Telegraf unknown (git: master 3268937)
Description: Raspbian GNU/Linux 9.4 (stretch)
mosquitto is an MQTT v3.1 broker.

Steps to reproduce:

  1. Satart telegraf.
  2. publish topoc. all ok
  3. restart telegraf
  4. publish topic. processors.regex doesnt works
    ..
    n. processors.regex begins work again after 5-10 telegram restart.

Expected behavior:

tag topicname=sonoff

Actual behavior:

no tag "topicname" after restart

Additional info:

publishing:

mosquitto_pub -u 'user' -P 'pass' -t 'test/sonoff/RESULT' -m '{"POWER1":13,"TEMP":41.1,"hostname":"mine"}'
mosquitto_pub -u 'user' -P 'pass' -t 'test/sonoff/RESULT' -m '{"POWER1":13,"TEMP":41.1,"hostname":"mine"}'

testing as client subscribtion with mosquitto_sub:

test/sonoff/RESULT {"POWER1":13,"TEMP":41.1,"hostname":"mine"}
test/sonoff/RESULT {"POWER1":13,"TEMP":41.1,"hostname":"mine"}

Telegraf log (looks good topicname=sonoff)

[root@duino:influxdb]# /usr/bin/telegraf --debug -config /etc/telegraf/telegraftest.conf
2018-10-02T10:51:52Z D! Attempting connection to output: file
2018-10-02T10:51:52Z D! Successfully connected to output: file
2018-10-02T10:51:52Z I! Starting Telegraf
2018-10-02T10:51:52Z I! Loaded inputs: inputs.mqtt_consumer
2018-10-02T10:51:52Z I! Loaded aggregators:
2018-10-02T10:51:52Z I! Loaded processors: regex printer
2018-10-02T10:51:52Z I! Loaded outputs: file
2018-10-02T10:51:52Z I! Tags enabled:
2018-10-02T10:51:52Z I! Agent Config: Interval:5s, Quiet:false, Hostname:"", Flush Interval:10s
2018-10-02T10:51:55Z I! MQTT Client Connected
2018-10-02T10:51:55Z I! MQTT Client Connected
2018-10-02T10:51:55Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Connection lost
error: EOF
MQTT Client will try to reconnect
2018-10-02T10:51:55Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Connection lost
error: read tcp [::1]:57884->[::1]:1883: use of closed network connection
MQTT Client will try to reconnect
2018-10-02T10:51:55Z I! MQTT Client Connected
2018-10-02T10:51:55Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Connection lost
error: EOF
MQTT Client will try to reconnect
2018-10-02T10:51:55Z I! MQTT Client Connected
2018-10-02T10:51:56Z I! MQTT Client Connected
2018-10-02T10:51:56Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Connection lost
error: read tcp [::1]:57892->[::1]:1883: use of closed network connection
MQTT Client will try to reconnect
2018-10-02T10:51:56Z E! Error in plugin [inputs.mqtt_consumer]: E! MQTT Connection lost
error: EOF
MQTT Client will try to reconnect
2018-10-02T10:51:56Z I! MQTT Client Connected
2018-10-02T10:51:56Z I! MQTT Client Connected
mqttc,hostname=mine,topic=test/sonoff/RESULT,topicname=sonoff TEMP=41.1,POWER1=13 1538477518180205009
2018-10-02T10:52:05Z D! Output [file] buffer fullness: 1 / 1000 metrics.
mine.test-sonoff-RESULT.sonoff.mqttc.TEMP 41.1 1538477518
mine.test-sonoff-RESULT.sonoff.mqttc.POWER1 13 1538477518
2018-10-02T10:52:05Z D! Output [file] wrote batch of 1 metrics in 487.031µs
2018-10-02T10:52:06Z I! Hang on, flushing any cached metrics before shutdown
2018-10-02T10:52:06Z D! Output [file] buffer fullness: 0 / 1000 metrics.

Telegraf log with no topicname

[root@duino:influxdb]# /usr/bin/telegraf --debug -config /etc/telegraf/telegraftest.conf
2018-10-02T10:52:10Z D! Attempting connection to output: file
2018-10-02T10:52:10Z D! Successfully connected to output: file
2018-10-02T10:52:10Z I! Starting Telegraf
2018-10-02T10:52:10Z I! Loaded inputs: inputs.mqtt_consumer
2018-10-02T10:52:10Z I! Loaded aggregators:
2018-10-02T10:52:10Z I! Loaded processors: printer regex
2018-10-02T10:52:10Z I! Loaded outputs: file
2018-10-02T10:52:10Z I! Tags enabled:
2018-10-02T10:52:10Z I! Agent Config: Interval:5s, Quiet:false, Hostname:"", Flush Interval:10s
2018-10-02T10:52:15Z I! MQTT Client Connected
2018-10-02T10:52:15Z I! MQTT Client Connected
mqttc,hostname=mine,topic=test/sonoff/RESULT POWER1=13,TEMP=41.1 1538477535301600165
2018-10-02T10:52:21Z I! Hang on, flushing any cached metrics before shutdown
2018-10-02T10:52:21Z D! Output [file] buffer fullness: 1 / 1000 metrics.
mine.test-sonoff-RESULT.sonoff.mqttc.POWER1 13 1538477535
mine.test-sonoff-RESULT.sonoff.mqttc.TEMP 41.1 1538477535
2018-10-02T10:52:21Z D! Output [file] wrote batch of 1 metrics in 267.291µs

mosquito.log

Tue 2 Oct 15:51:55 +05 2018 1538477515: Received SUBSCRIBE from telegraftest
Tue 2 Oct 15:51:55 +05 2018 1538477515: test/# (QoS 0)
Tue 2 Oct 15:51:55 +05 2018 1538477515: Sending SUBACK to telegraftest
Tue 2 Oct 15:51:56 +05 2018 1538477516: Sending CONNACK to telegraftest (1, 0)
Tue 2 Oct 15:51:56 +05 2018 1538477516: Sending CONNACK to telegraftest (1, 0)
Tue 2 Oct 15:51:56 +05 2018 1538477516: Sending CONNACK to telegraftest (1, 0)
Tue 2 Oct 15:51:58 +05 2018 1538477518: Sending CONNACK to mosqpub/24949-duino (0, 0)
Tue 2 Oct 15:51:58 +05 2018 1538477518: Received PUBLISH from mosqpub/24949-duino (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:51:58 +05 2018 1538477518: Sending PUBLISH to mosqsub/13070-duino (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:51:58 +05 2018 1538477518: Sending PUBLISH to telegraftest (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:51:58 +05 2018 1538477518: Received DISCONNECT from mosqpub/24949-duino



Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending CONNACK to telegraftest (1, 0)
Tue 2 Oct 15:52:15 +05 2018 1538477535: Received SUBSCRIBE from telegraftest
Tue 2 Oct 15:52:15 +05 2018 1538477535: test/# (QoS 0)
Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending SUBACK to telegraftest
Tue 2 Oct 15:52:15 +05 2018 1538477535: Received SUBSCRIBE from telegraftest
Tue 2 Oct 15:52:15 +05 2018 1538477535: test/# (QoS 0)
Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending SUBACK to telegraftest
Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending CONNACK to mosqpub/25036-duino (0, 0)
Tue 2 Oct 15:52:15 +05 2018 1538477535: Received PUBLISH from mosqpub/25036-duino (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending PUBLISH to mosqsub/13070-duino (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:52:15 +05 2018 1538477535: Sending PUBLISH to telegraftest (d0, q0, r0, m0, 'test/sonoff/RESULT', ... (43 bytes))
Tue 2 Oct 15:52:15 +05 2018 1538477535: Received DISCONNECT from mosqpub/25036-duino
```

@Dees7
Copy link
Author

Dees7 commented Oct 2, 2018

I tested Telegraf 1.8.0. The same behavior

@Dees7 Dees7 changed the title processors.regex doesn't works well. or work unstable processors.regex doesn't works well. or works unstable Oct 3, 2018
@danielnelson
Copy link
Contributor

I think this is the same bug as in #4594, lets discuss further on that issue.

@Dees7
Copy link
Author

Dees7 commented Oct 4, 2018

No. This is other bug.
MQTT works well. and data recived but processed wrong

#first start
mqttc,hostname=mine,topic=test/sonoff/RESULT,topicname=sonoff TEMP=41.1,POWER1=13 1538477518180205009

#restart
mqttc,hostname=mine,topic=test/sonoff/RESULT POWER1=13,TEMP=41.1 1538477535301600165

There is no topicname=sonoff after restart
As we can see in log TEMP=41.1 and other are recived by telegraf

@danielnelson
Copy link
Contributor

This may just be an issue of which order the two processors run in. Unless you add the order option it is undefined. Can you retest with these additions:

[[processors.printer]]
  order = 2
[[processors.regex]]
  order = 1
  [[processors.regex.tags]]
    key = "topic"
    pattern = ".*/(.*)/.*"
    replacement = "${1}"
    result_key = "topicname"

@Dees7
Copy link
Author

Dees7 commented Oct 6, 2018

Yes. It helps.
Is it possible to set "order" option in [[outputs.influxdb]] ?

@glinton
Copy link
Contributor

glinton commented Oct 8, 2018

@Dees7 there is no "order" config for the influxdb output, are you asking if you can define the order of the tags/fields being output?

@Dees7
Copy link
Author

Dees7 commented Oct 8, 2018

Yes, I ask if I can define order of tagging and output to influxdb. Something like:

[[inputs.mqtt_consumer]]
  order = 1
  ..
  tag_keys = ["hostname","POWER","POWER1"]
[[processors.converter]]
  [processors.converter.tags]
    order = 2
    float = ["POWER*"]
[[processors.regex]]
  [[processors.regex.tags]]
    order = 3
    key = "topic"
    pattern = ".*/(.*)/.*"
    replacement = "${1}"
    result_key = "topicname"
[[processors.printer]]
  order = 4
  ..
[[outputs.influxdb]]
  order = 5
  ..

Because I have no "topicname" in output to influxdb (and POWERs were added as tag not float) if it was not printed with processors.printer.
So now I have in DB:
POWER(float) POWER1(float) POWER1_1(tag) POWER2(float) POWER2_1(tag) (cause bug-order?)

@danielnelson
Copy link
Contributor

Inputs and Outputs do not have an order option because they run before and after the processors and so there is no need for them to be ordered.

If you are still having issues after adding the order option to the processors, can you show the full config after the new changes?

@Dees7
Copy link
Author

Dees7 commented Oct 10, 2018

Ok. Now it looks as unstable connection to mqtt.
I cant catch the bug. Issue can be closed.
Thank you.

@danielnelson
Copy link
Contributor

Keep an eye on #4594 for updates on the MQTT issue.

@erkexzcx
Copy link
Contributor

Using below options should be part of documentation... Would be such a time saver!

order = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants