influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.48k stars 5.54k forks source link

Provide a plug-in for serial port data. #7218

Open rin67630 opened 4 years ago

rin67630 commented 4 years ago

Feature Request

I wasn't able to find in input plug-in for data coming from a serial port

Proposal:

Could it be possible to provide such a plug-in that reads data from the serial port according to a given pattern?

Current behavior:

Currently no plug-in available, at least not under the keyword serial.

Desired behavior:

Provide a new plug in or add the keyword "serial" to and eventually existing plug-in that could do the job.

Use case:

Many measuring instruments are providing data over a serial port. The serial port is also the primary, communication wait for microcontrollers like the Arduino. That way of receiving data should not be missing in Telegraf.

danielnelson commented 4 years ago

Similar to the code here? https://www.arduino.cc/reference/en/language/functions/communication/serial/read/

What types of data would be received?

rin67630 commented 4 years ago

Basically csv text without time stamp, but a more flexible solution allowing different separators should be very much appreciated. A good reference is the serial plotter of the arduino IDE: https://github.com/arduino/Arduino/blob/ba34eb640e5f6c2f8618debf61022f731c0eab74/build/shared/ArduinoSerialPlotterProtocol.md Adding the ability to gather from bytes, integers, words, doubles (little,big endian) options would be useful as well in future versions.

danielnelson commented 4 years ago

We could have a plugin that reads from a serial device line wise and passes the lines to any parser, it would be similar to the tail input plugin.

Perhaps it could use https://github.com/goburrow/serial, which is already a Telegraf dependency. This library is focused at modbus so I'm not completely sure if it will work.

For parsing binary data, I need to take a look over https://github.com/influxdata/telegraf/pull/7030. I'm not sure how we would handle message framing with our current architecture though.

rin67630 commented 4 years ago

If people need to write a parser, then they won't need telegraph to feed their influxDB. The delta to write it directly were only a few instructions. A simple no frills solution with configurable delimiters for values and labels should be the way to go. Just my few cents...

tophee commented 4 years ago

Take a look at https://github.com/ppetr/arduino-influxdb It basically provides the functionality you are looking for but by default it sends the data directly to influxdb, not via telegraf. Telegraf is mentioned and even recommended for certain setups but I havn't quite figured out how it's supposed to be done...

That said, I agree that it would be excellent to have a telegraf plugin that can directly read from the serial port.

rin67630 commented 3 years ago

@tophee: The serial plugin should be hardware agnostic. Just accept x serial values separated by a configurable delimiter, the series being ended by a \n, else ignoring whitespaces and other non digits. So anything capable of printing a report could provide the data, even a commodore 64 ;-)

tophee commented 3 years ago

@rin67630 I believe the script I referred to is entirely hardware agnostic. Nevermind that the repository has "arduino" in its name.

8none1 commented 3 years ago

I've hit a use case for this today. A device connected over a USB to Serial convertor which outputs a line of text which has the measurements I want. I was able to change the output format of the device to something close enough to JSON to parse it.

In order to read from the serial port what I did was (on Linux):

I think that having a dedicated Serial Port plugin would be useful though, so I can move the configuration of the serial port speed in to Telegraf conf instead.

l-fy commented 2 years ago

I'm working on a module for serial. I intend to use https://github.com/bugst/go-serial because it supports better hardware flow control. I will most likely publish it at https://github.com/l-fy/serial

l-fy commented 2 years ago

The code is in https://github.com/l-fy/telegraf in the serial branch in the input plugin directory as serial. It works fine for my test bed but is not an actual production code.

tophee commented 2 years ago

@l-fy Sorry about my ignorance, but I'm unable to find the plugin. By input plugin directory, do you mean this: https://github.com/l-fy/telegraf/tree/master/plugins/inputs?

l-fy commented 2 years ago

Take a look at: https://github.com/l-fy/telegraf/tree/serial/plugins/inputs/serial

Hello1024 commented 1 year ago
  • sudo stty -F /dev/ttyUSB0

I don't think @8none1 's answer works... The telegraf logs show:

[inputs.tail] Stopping tail on "/dev/ttyUSB0": Seek error on /dev/ttyUSB0: seek /dev/ttyUSB0: illegal seek

Obviously tty devices aren't seekable... This happens for all combinations of the from_begining and pipe options for the tail plugin.

It appears to work for a bit because telegraf takes one input buffer worth of data correctly, so you get a few entries written to influxdb correctly and it appears to work, but then the stream stops.

Here is a different workaround:

mkfifo fifo
tail -f /dev/ttyUSB0 > fifo

Run that as a bootup shell script.

Then configure 'fifo' as the telegraf file, using the pipe = true. That seems to do the trick.