Bläddra i källkod

use iot telegraf to push tasmota mqtt messages to influx

Thomas Buck 5 månader sedan
förälder
incheckning
c9ab98cab1
2 ändrade filer med 84 tillägg och 77 borttagningar
  1. 26
    19
      roles/iot/tasks/influx.yml
  2. 58
    58
      roles/iot/templates/etc_telegraf_telegraf.j2

+ 26
- 19
roles/iot/tasks/influx.yml Visa fil

@@ -15,25 +15,26 @@
15 15
   tags:
16 16
     - dependencies
17 17
 
18
-- name: Install InfluxDB and Telegraf from official repository
19
-  apt:
20
-    name: "{{ packages }}"
21
-    state: present
22
-    update_cache: yes
23
-  vars:
24
-    packages:
25
-    - influxdb
26
-    - telegraf
27
-  tags:
28
-    - dependencies
29
-
30
-- name: Configure InfluxDB
31
-  template:
32
-    src=etc_influxdb_influxdb.j2
33
-    dest=/etc/influxdb/influxdb.conf
34
-    owner=root
35
-    group=root
36
-  notify: restart influxdb
18
+# TODO can no longer run this!
19
+#- name: Install InfluxDB and Telegraf from official repository
20
+#  apt:
21
+#    name: "{{ packages }}"
22
+#    state: present
23
+#    update_cache: yes
24
+#  vars:
25
+#    packages:
26
+#    - influxdb
27
+#    - telegraf
28
+#  tags:
29
+#    - dependencies
30
+#
31
+#- name: Configure InfluxDB
32
+#  template:
33
+#    src=etc_influxdb_influxdb.j2
34
+#    dest=/etc/influxdb/influxdb.conf
35
+#    owner=root
36
+#    group=root
37
+#  notify: restart influxdb
37 38
 
38 39
 - name: Create InfluxDB data directories
39 40
   file: state=directory path={{ item }} owner=influxdb group=influxdb
@@ -58,6 +59,12 @@
58 59
     - 8088  # rpc
59 60
   tags: ufw
60 61
 
62
+# TODO influxdb should get following set in
63
+# /etc/systemd/system/influxdb.service.d/override.conf
64
+#
65
+# [Service]
66
+# TimeoutStartSec=60m
67
+
61 68
 - name: Register new InfluxDB and Telegraf service
62 69
   systemd: name={{ item }} daemon_reload=yes enabled=yes
63 70
   with_items:

+ 58
- 58
roles/iot/templates/etc_telegraf_telegraf.j2 Visa fil

@@ -4594,64 +4594,64 @@
4594 4594
 #     # unique_timestamp = "auto"
4595 4595
 
4596 4596
 
4597
-# # Read metrics from MQTT topic(s)
4598
-# [[inputs.mqtt_consumer]]
4599
-#   ## MQTT broker URLs to be used. The format should be scheme://host:port,
4600
-#   ## schema can be tcp, ssl, or ws.
4601
-#   servers = ["tcp://localhost:1883"]
4602
-#
4603
-#   ## QoS policy for messages
4604
-#   ##   0 = at most once
4605
-#   ##   1 = at least once
4606
-#   ##   2 = exactly once
4607
-#   ##
4608
-#   ## When using a QoS of 1 or 2, you should enable persistent_session to allow
4609
-#   ## resuming unacknowledged messages.
4610
-#   qos = 0
4611
-#
4612
-#   ## Connection timeout for initial connection in seconds
4613
-#   connection_timeout = "30s"
4614
-#
4615
-#   ## Maximum messages to read from the broker that have not been written by an
4616
-#   ## output.  For best throughput set based on the number of metrics within
4617
-#   ## each message and the size of the output's metric_batch_size.
4618
-#   ##
4619
-#   ## For example, if each message from the queue contains 10 metrics and the
4620
-#   ## output metric_batch_size is 1000, setting this to 100 will ensure that a
4621
-#   ## full batch is collected and the write is triggered immediately without
4622
-#   ## waiting until the next flush_interval.
4623
-#   # max_undelivered_messages = 1000
4624
-#
4625
-#   ## Topics to subscribe to
4626
-#   topics = [
4627
-#     "telegraf/host01/cpu",
4628
-#     "telegraf/+/mem",
4629
-#     "sensors/#",
4630
-#   ]
4631
-#
4632
-#   # if true, messages that can't be delivered while the subscriber is offline
4633
-#   # will be delivered when it comes back (such as on service restart).
4634
-#   # NOTE: if true, client_id MUST be set
4635
-#   persistent_session = false
4636
-#   # If empty, a random client ID will be generated.
4637
-#   client_id = ""
4638
-#
4639
-#   ## username and password to connect MQTT server.
4640
-#   # username = "telegraf"
4641
-#   # password = "metricsmetricsmetricsmetrics"
4642
-#
4643
-#   ## Optional TLS Config
4644
-#   # tls_ca = "/etc/telegraf/ca.pem"
4645
-#   # tls_cert = "/etc/telegraf/cert.pem"
4646
-#   # tls_key = "/etc/telegraf/key.pem"
4647
-#   ## Use TLS but skip chain & host verification
4648
-#   # insecure_skip_verify = false
4649
-#
4650
-#   ## Data format to consume.
4651
-#   ## Each data format has its own unique set of configuration options, read
4652
-#   ## more about them here:
4653
-#   ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
4654
-#   data_format = "influx"
4597
+# Read metrics from MQTT topic(s)
4598
+[[inputs.mqtt_consumer]]
4599
+  ## MQTT broker URLs to be used. The format should be scheme://host:port,
4600
+  ## schema can be tcp, ssl, or ws.
4601
+  servers = ["tcp://{{ server_fqdn }}:1883"]
4602
+
4603
+  ## QoS policy for messages
4604
+  ##   0 = at most once
4605
+  ##   1 = at least once
4606
+  ##   2 = exactly once
4607
+  ##
4608
+  ## When using a QoS of 1 or 2, you should enable persistent_session to allow
4609
+  ## resuming unacknowledged messages.
4610
+  qos = 0
4611
+
4612
+  ## Connection timeout for initial connection in seconds
4613
+  connection_timeout = "30s"
4614
+
4615
+  ## Maximum messages to read from the broker that have not been written by an
4616
+  ## output.  For best throughput set based on the number of metrics within
4617
+  ## each message and the size of the output's metric_batch_size.
4618
+  ##
4619
+  ## For example, if each message from the queue contains 10 metrics and the
4620
+  ## output metric_batch_size is 1000, setting this to 100 will ensure that a
4621
+  ## full batch is collected and the write is triggered immediately without
4622
+  ## waiting until the next flush_interval.
4623
+  # max_undelivered_messages = 1000
4624
+
4625
+  ## Topics to subscribe to
4626
+  ## matches tasmota "$room/$app/tele/STATE" and "$room/$app/tele/SENSOR"
4627
+  topics = [
4628
+    "+/+/tele/SENSOR",
4629
+    "+/+/tele/STATE",
4630
+  ]
4631
+
4632
+  # if true, messages that can't be delivered while the subscriber is offline
4633
+  # will be delivered when it comes back (such as on service restart).
4634
+  # NOTE: if true, client_id MUST be set
4635
+  persistent_session = false
4636
+  # If empty, a random client ID will be generated.
4637
+  client_id = "iot-mqtt-bridge"
4638
+
4639
+  ## username and password to connect MQTT server.
4640
+  username = "{{ lights_web_username }}"
4641
+  password = "{{ lights_web_password }}"
4642
+
4643
+  ## Optional TLS Config
4644
+  # tls_ca = "/etc/telegraf/ca.pem"
4645
+  # tls_cert = "/etc/telegraf/cert.pem"
4646
+  # tls_key = "/etc/telegraf/key.pem"
4647
+  ## Use TLS but skip chain & host verification
4648
+  # insecure_skip_verify = false
4649
+
4650
+  ## Data format to consume.
4651
+  ## Each data format has its own unique set of configuration options, read
4652
+  ## more about them here:
4653
+  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
4654
+  data_format = "json"
4655 4655
 
4656 4656
 
4657 4657
 # # Read metrics from NATS subject(s)

Laddar…
Avbryt
Spara