Using tcp_listener plugin in Telegraf

I want to monitor my port on which my grafana is running i.e, 3000 .

I think I can do that with tcp_listener plugin in telegraf.

# # Generic TCP listener
# ## Address and port to host TCP listener on
service_address = "tcp6://:3000"
# ## Number of TCP messages allowed to queue up. Once filled, the
# ## TCP listener will start dropping packets.
# # allowed_pending_messages = 10000
## ## Maximum number of concurrent TCP connections to allow# # max_tcp_connections = 250#

## Data format to consume.`

# ## Each data format has it's own unique set of configuration options, read
# ## more about them here:
# ##
# data_format = "influx"

But I am not getting the hold of it. It listens on this port(3000 here). What is meant by the data format here ? If I have to add the data format which telegraf supports, How do I know that which data format my grafana server is using ?

I dont know why this data format is important.

Also, Where it will store the info which it listens on the socket, in the influxdb and under which measurement ?

How can I view the data about the port being monitored ?

Please tell me If I am going in the wrong direction.
Thank you.

The tcp_listener expects data to be sent to Telegraf on the listening port in the data_format specified. Maybe you want the http_response plugin instead, it verifies that a HTTP server is up and reports the response time.

What if I not only want to know that whether the server is up but also want to check the traffic on that server, like ingoing and outgoing ?

Please explain functionality of tcp_listener in a detailed way. It would be kind of you.

Also, difference between http_response and tcp_listener

The tcp_listener plugin listens on a port for metrics already formatted according to the data_format. It is generally used for routing or for custom event driven metrics.

The http_response plugin queries a HTTP resource and reports metrics about response code and response time. This can give you basic information about if a service is up.

If you want information on network traffic you could look into the netstat or net plugins, or you could monitor a proxy in front of your grafana server via the nginx or haproxy inputs.

You might also be able to leverage some of Grafana’s internal metrics, but I have not experimented with this.

@daniel , I tried http_listener,

# # Influx HTTP write listener
# ## Address and port to host HTTP listener on
service_address = ""

After this, I read the github page of http_listener, It says,

The HTTP listener is a service input plugin that listens for messages sent via HTTP POST. The plugin expects messages in the InfluxDB line-protocol ONLY, other Telegraf input data formats are not supported. The intent of the plugin is to allow Telegraf to serve as a proxy/router for the /write endpoint of the InfluxDB HTTP API.

So, it is a proxy for the /write api of the influxdb, right?

here is what I did,

curl -i -XPOST 'http://localhost:9898/write' --data-binary 'new_measurement,host=server01,region=us-west value=0.64 1434055562000000000'

Return Value -

HTTP/1.1 204 No Content Date: Thu, 13 Apr 2017 07:20:11 GMT

But there is no new measurement in the telegraf database. Why so ? Does it write directy to the telegraf database, or I can specify my own db also ?

Here is another example,

luvpreet@DHARI-Inspiron-3542:/tmp/telegraf$ curl -i -XPOST 'http://localhost:9898/write/?db=test' --data-binary 'new_measurement,host=server01,region=us-west value=0.64 1434055562000000000'
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Thu, 13 Apr 2017 07:24:25 GMT
Content-Length: 19

And what If I have to monitor the traffic per port, like port 3000, I want to see the incoming/outgoing traffic ? the net and netstat plugins tell us the about the whole network, but they don’t tell us the traffic corresponding to single particular ports.

I hope you are getting my point in the second question.

And also, it takes a long time to show the new measurements being made by this http_listener's proxy address.

To show measurements made by this method,influx almost takes 10 minutes to show them. While some are shown just after 10 seconds, some take almost 10 minutes.

Why is this and how can I improve this ?

It will write the data to all outputs configured, the db= query parameter is not used.

In your second example the url path should be /write instead of /write/.

This is correct, maybe you could use the nginx, haproxy, or iptables plugin to get what you want if you have any of these systems setup. Another option is to use the exec plugin with some custom code. Otherwise I’m not aware of an existing way to do this, you can open a feature request on the Telegraf github page.