This repository was archived by the owner on Nov 15, 2022. It is now read-only.
Add TCP driver alongiside UDP one#124
Open
Steveb-p wants to merge 3 commits intoinfluxdata:masterfrom
Open
Conversation
83c78c3 to
490bbbd
Compare
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 :) |
Steveb-p
commented
Feb 27, 2019
| */ | ||
| protected function doWrite($data) | ||
| { | ||
| $this->result = false !== @fwrite($this->stream, "$data\n"); |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In my project I'm using
influxdb-phpto communicate to an InfluxDB database instance via a Telegraf instance. Since Telegraf exposes a handySocket Listenerplugin (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
TCPclass similar toUDPone and puts common code intoAbstractSocketDriver. Since I'm no particular expert in socket php functions, I'll welcome any criticism :)