Inputs.exec script hang

Hello All
I am using Telegraf 1.17.3 on FreeBSD 12.2-STABLE amd64 . I want to collect some details from FreeBSD’s netstat program that are not available in the builtin netstat plugin. The solution was to use libxo to get netstats output in json format and using a small python script via telegraf’s exec.input plugin collect the data. Most of the time it works fine however after it has been running for a few weeks telegraf hangs while trying to run the plugin.

The plugin is here telegraf-plugins/ at master · failedrequest/telegraf-plugins · GitHub

The telegraf.conf block is this

commands = [" sudo /usr/local/bin/ "]
timeout = “5s”
data_format = “influx”

If there is a easier way to inject json into influx I am all for that . The command I am running and transforming into telegraf is this

[highwire]$ netstat -s -p ip --libxo json
{"statistics": {"ip": {"received-packets":495664605465,"dropped-bad-checksum":0,"dropped-below-minimum-size":0,"dropped-short-packets":0,"dropped-too-long":0,"dropped-short-header-length":0,"dropped-short-data":0,"dropped-bad-options":0,"dropped-bad-version":0,"received-fragments":0,"dropped-fragments":0,"dropped-fragments-after-timeout":0,"reassembled-packets":0,"received-local-packets":48554109,"dropped-unknown-protocol":0,"forwarded-packets":495605886382,"fast-forwarded-packets":24,"packets-cannot-forward":8295544,"received-unknown-multicast-group":0,"redirects-sent":0,"sent-packets":64590961,"send-packets-fabricated-header":115,"discard-no-mbufs":0,"discard-no-route":0,"sent-fragments":0,"fragments-created":0,"discard-cannot-fragment":0,"discard-tunnel-no-gif":0,"discard-bad-address":0}}

Hello @Mark_Saad,
yes you could change the format for execd to json instead:

Thanks for your response . Switching to calling netstat directly resolved the hangs I was seeing from my json to influx converter script.

This is what i added to the telegraf.conf this works on FreeBSD 11.3 and newer . I tested it on 11.3-STABLE and 12.2-STABLE and its been fantastic.

   commands = [" sudo netstat -s -p ip --libxo json "]
   timeout = "5s"
   name_suffix = "_bsd_netstat"
   data_format = "json"