Make Exec Input Plugin output show along with other metrics

I have set the below script to run using exec input plugin on the configuration file :

[[inputs.exec]]
commands = [“PowerShell -File E:\TNC.ps1”]
timeout = “25s”
name_suffix = “Ping and Telnet Google”
data_format = “value”
data_type=“string”

The TNC script contains the test-netconnection command to run ping and telnet :

tnc google.com -port 443

When I try to test the config file using, I am seeing the correct command output with the telnet results on the console. However, I am not seeing the same telnet output along with the other metrics when I call http://localhost:9273/metrics. Please advise on what needs to be done for the command output to be displayed along with the other metrics.

Hi,

What is the exact output of tnc google.com -port 443?
What do your telegraf logs show?
Can you enable the [[outputs.file]] output to see what metrics might be produced?

Thanks!

Contents of the script :

tnc www.google.com -port 443

PS E:\> E:\TNC.ps1

ComputerName     : www.google.com
RemoteAddress    : 142.250.176.68
RemotePort       : 443
InterfaceAlias   : Ethernet0 2
SourceAddress    : 10.202.115.182
TcpTestSucceeded : True

Above is the expected output of the script and I’m also seeing the same when testing config file as shown below :

My understanding is that once it shows up here, it should also show up at /metrics endpoint.

I tried to output the metrics to a file, but couldnt get it to work for some reason :
[[outputs.file]]
files = [“stdout”, “E:\metrics.out”]
data_format = “influx”

Sorry I missed this. If you are using --test there should be a nice big message that says outputs are not used in test mode. So the output will only go to stdout.

1 Like

So what other plugin would one need to enable for the ping/telnet results to be displayed along with other regular metrics at /metrics endpoint during the normal run of Telegraf?

The current configuration file is capturing CPU, memory, disk info at the /metrics endpoint. I would like the results of the script(ping/telnet results) also to be displayed along with regular metrics. What am I doing wrong?

Your issue is not that clear to me, so I’ll try to summarize it…

  1. You are gathering data via Telegraf
  2. You are also running a custom PS script via inputs.exec
    2.a You are basically pinging google (I guess to ensure the machine has internet access)
  3. You expect whatever value comes out of it to be available on some /metrics endpoint
  4. I think you are writing data to InfluxDB…

First, Telegraf does not expose any endpoint, the only /metrics endpoint I’m aware of is exposed by InfluxDB and exposes InfluxDB-related counters. What /metrics endpoint you are talking about?
If you are talking about the InfluxDB endpoint you can’t change its content

The data you are gathering via script are not formatted/serialized in any way, it’s just a multiline string, meaning that filtering by SourceAddress or whatever won’t be possible… not in a nice/performing way at least.
In order to ping stuff you can also use input.ping which is built-in and might save you several Powershell related issues (version, proper permission and execution policy, data serialization, etc)

I’ve only been starting out with Telegraf, kindly excuse if I’m using incorrect terminology.

The /metrics endpoint I’m referring to is the [[outputs.prometheus_client]] plugin. I have this enabled and listening on port 9126 and I’m able to see metrics (CPU, Memory, Disk) from the configuration file when I call https://localhost:9126/metrics after starting telegraf. I’m looking for a way to be able to see the ping & telnet results also at https://localhost:9126/metrics which is going to be scraped by a VictoriaMetrics server that we have setup. (We are not sending data to influxdb for now) I’m hoping to setup alerting on the VictoriaMetrics side based on the script output, if that can be scraped from Telegraf prometheus endpoint.

My requirement is to monitor connections between 2 internal servers (requires ping and telnet) every interval and raise an alert on VictoriaMetrics side when the connection is down. So I feel the input.ping plugin might not be fit for this task.

Request you to also suggest any other plugin combinations that may help me with monitoring connections between servers. (ping & telnet)