Telegraf on Windows inputs.exec fields question

telegraf

#1

I made a config as shown below to collect the number of TCP connections established on a particular port as I need to trend that data.
It calls a custom program that returns the connection count based on a filter.

This command works fine and sends to Influx and that works properly.
But the downside is that it creates a measurement for each instance.
So I got 2 measurements now in my InfluxDB;
“TCP_Connections_Open_Protocol_4545” and “TCP_Connections_TDM_11250”

[[inputs.exec]]
commands = ["“C:\NetStatNaoFind_Influx.exe” :4545"]
name_override = “TCP_Connections”
name_suffix = “_Open_Protocol_4545”
data_format = “value”
data_type = “integer” # required

[[inputs.exec]]
commands = ["“C:\NetStatNaoFind_Influx.exe” :11250 "]
name_override = “TCP_Connections”
name_suffix = “_TDM_11250”
data_format = “value”
data_type = “integer” # required

My goal is to have 1 measurement with some type of field I can use to distinguish which port number was filtered, instead of separate measurements.
I’m not sure where to start and I have searched here and google.

I’m thinking something similar to below, where port would be a field in my InfluxDB.

[[inputs.exec]]
commands = ["“C:\NetStatNaoFind_Influx.exe” :4545"]
name_override = “TCP_Connections”
data_format = “value”
data_type = “integer” # required
port=“4545”

[[inputs.exec]]
commands = ["“C:\NetStatNaoFind_Influx.exe” :11250 "]
name_override = “TCP_Connections”
data_format = “value”
data_type = “integer” # required
port=“4545”


#2

I recommend using a tag for the port, this will allow you to use group by in your queries. You can add a static tag value using the tags subtable:

[[inputs.exec]]
  commands = ["C:\NetStatNaoFind_Influx.exe :11250"]
  name_override = "TCP_Connections"
  data_format = "value"
  data_type = "integer" # required
  [inputs.exec.tags]
    port = "11250"

#3

Thank you!
That worked…