mqtt

package
v1.20.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 12 Imported by: 181

README

MQTT Producer Output Plugin

This plugin writes to a MQTT Broker acting as a mqtt Producer.

[[outputs.mqtt]]
  ## URLs of mqtt brokers
  servers = ["localhost:1883"]

  ## topic for producer messages
  topic_prefix = "telegraf"

  ## QoS policy for messages
  ##   0 = at most once
  ##   1 = at least once
  ##   2 = exactly once
  qos = 2

  ## username and password to connect MQTT server.
  # username = "telegraf"
  # password = "metricsmetricsmetricsmetrics"

  ## client ID, if not set a random ID is generated
  # client_id = ""

  ## Timeout for write operations. default: 5s
  # timeout = "5s"

  ## Optional TLS Config
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

  ## When true, metrics will be sent in one MQTT message per flush.  Otherwise,
  ## metrics are written one metric per MQTT message.
  # batch = false

  ## When true, messages will have RETAIN flag set.
  # retain = false

  ## Defines the maximum length of time that the broker and client may not communicate. 
  ## Defaults to 0 which turns the feature off. For version v2.0.12 mosquitto there is a 
  ## [bug](https://github.com/eclipse/mosquitto/issues/2117) which requires keep_alive to be set.
  ## As a reference eclipse/paho.mqtt.golang v1.3.0 defaults to 30.
  # keep_alive = 0

  ## Data format to output.
  # data_format = "influx"
Required parameters:
  • servers: List of strings, this is for speaking to a cluster of mqtt brokers. On each flush interval, Telegraf will randomly choose one of the urls to write to. Each URL should just include host and port e.g. -> ["{host}:{port}","{host2}:{port2}"]
  • topic_prefix: The mqtt topic prefix to publish to. MQTT outputs send metrics to this topic format "<topic_prefix>///" ( ex: prefix/web01.example.com/mem)
  • qos: The mqtt QoS policy for sending messages. See https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q029090_.htm for details.
Optional parameters:
  • username: The username to connect MQTT server.
  • password: The password to connect MQTT server.
  • client_id: The unique client id to connect MQTT server. If this parameter is not set then a random ID is generated.
  • timeout: Timeout for write operations. default: 5s
  • tls_ca: TLS CA
  • tls_cert: TLS CERT
  • tls_key: TLS key
  • insecure_skip_verify: Use TLS but skip chain & host verification (default: false)
  • batch: When true, metrics will be sent in one MQTT message per flush. Otherwise, metrics are written one metric per MQTT message.
  • retain: Set retain flag when publishing
  • data_format: About Telegraf data formats
  • keep_alive: Defines the maximum length of time that the broker and client may not communicate with each other. Defaults to 0 which deactivates this feature.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MQTT

type MQTT struct {
	Servers     []string `toml:"servers"`
	Username    string
	Password    string
	Database    string
	Timeout     config.Duration
	TopicPrefix string
	QoS         int    `toml:"qos"`
	ClientID    string `toml:"client_id"`
	tls.ClientConfig
	BatchMessage bool  `toml:"batch"`
	Retain       bool  `toml:"retain"`
	KeepAlive    int64 `toml:"keep_alive"`

	sync.Mutex
	// contains filtered or unexported fields
}

func (*MQTT) Close

func (m *MQTT) Close() error

func (*MQTT) Connect

func (m *MQTT) Connect() error

func (*MQTT) Description

func (m *MQTT) Description() string

func (*MQTT) SampleConfig

func (m *MQTT) SampleConfig() string

func (*MQTT) SetSerializer added in v1.14.0

func (m *MQTT) SetSerializer(serializer serializers.Serializer)

func (*MQTT) Write

func (m *MQTT) Write(metrics []telegraf.Metric) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL