Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Add TCP driver alongiside UDP one #124

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Steveb-p
Copy link

@Steveb-p Steveb-p commented Feb 22, 2019

In my project I'm using influxdb-php to communicate to an InfluxDB database instance via a Telegraf instance. Since Telegraf exposes a handy Socket Listener plugin (https://docs.influxdata.com/telegraf/v1.9/plugins/inputs/#socket-listener) I decided to use UDP driver, but I found it only works with (obviously) UDP protocol. Socket Listener does support it, but I wanted to be sure in particular cases that message gets through.

Reasoning for usage of Telegraf in my case is that I can aggregate writes in it, reducing the amount of messages between application and InfluxDB instance. Also it does send messages in regular intervals in batches, so I don't really need to group messages myself.

It uses InfluxDB's "Line protocol" for messages, so one can either write directly to InfluxDB's UDP socket, or use Telegraf's Socket Listener.

This PR introduces TCP class similar to UDP one and puts common code into AbstractSocketDriver. Since I'm no particular expert in socket php functions, I'll welcome any criticism :)

@Steveb-p Steveb-p force-pushed the master branch 2 times, most recently from 83c78c3 to 490bbbd Compare February 22, 2019 12:12
@Steveb-p
Copy link
Author

I believe this PR should also contain documentation changes indicating that you can use it alongside with Telegraf instance, but I'm holding until one of maintainers says that it's a worthy addition :)

*/
protected function doWrite($data)
{
$this->result = false !== @fwrite($this->stream, "$data\n");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue can occur when multiple messages are written into TCP socket:

telegraf_1_279d9d02c69e | 2019-02-27T10:54:58Z E! [inputs.socket_listener]: Error in plugin: unable to parse incoming line: metric parse error: expected field at offset 49: "xxx,tag=tag_value parsed=0i,processing_time=85.6xxx,tag=tag_value parsed=0i...

Each message has to end with newline.

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

Successfully merging this pull request may close these issues.

1 participant