Telegraf EXEC reporting: Invalid data format: CSV

Hello,

I am trying to capture data from stdout using a test script. Following is my telegraf (v1.7.4) configuration:

[[inputs.exec]]
commands = ["/opt/tcathome/jstat.sh"]
timeout = “5s”
name_suffix = “_jstat”
data_format = “csv”
csv_header_row_count = 0
csv_column_names = [“S0,S1,E,O,P,YGC,YGCT,FGC,FGCT,GCT”]
csv_skip_rows = 0
csv_skip_columns = 0
csv_delimiter = " "
csv_trim_space = false
csv_tag_columns = [“S0,S1,E,O,P,YGC,YGCT,FGC,FGCT,GCT”]
csv_measurement_column = “”

However upon testing the plugin i get:

telegraf --config telegraf.conf --test

2018/09/17 16:34:40 E! Error parsing telegraf.conf, Invalid data format: csv

The script itself generates following data (tab seperated):

./jstat.sh
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
1935665.2 0.00 100.00 69.70 40.93 97.94 93.06 39276 6322.108 0 0.000 6322.108
1935670.2 0.00 100.00 69.70 40.93 97.94 93.06 39276 6322.108 0 0.000 6322.108

What am I doing wrong? Please help.

You will need Telegraf 1.8.0 to use the csv parser, we have a release candidate available now, but we found some issues with the csv parser so you will want to wait for 1.8.0-rc2.

Another issue I see is that if you use csv_column_names it will need to specify all columns, and you will need at least one column that is not a tag. Based on the data type in your sample probably don’t want any of them to be tags.

Thank you Daniel. I will upgrade telegraf and test it out.

-Naresh

I have now upgraded to 1.8.0. However now I see following error:

2018-09-28T20:29:00Z D! Output [influxdb] wrote batch of 466 metrics in 300.68507ms
2018-09-28T20:29:00Z E! Error in plugin [inputs.exec]: exec: exit status 1 for command ‘/opt/tcathome/jstat.sh’: Could not attach to 1284

My configuration now is:
[[inputs.exec]]
commands = ["/opt/tcathome/jstat.sh"]
timeout = “5s”
name_suffix = “_jstat”
data_format = “csv”
csv_header_row_count = 0
csv_column_names = [“S0,S1,E,O,P,YGC,YGCT,FGC,FGCT,GCT”]
csv_skip_rows = 0
csv_skip_columns = 0
csv_delimiter = “”
csv_trim_space = true
csv_measurement_column = “”

The contents of jstat is:

#!/bin/sh

cd /opt/java/jdk1.8.0_161/bin

./jstat -gcutil 1284 5s

where 1284=PID (Process ID)

The process 1284 is run as a different system user than the telegraf itself. Telegraf is running as “root”.

This whole setup is on CentOS Linux release 7.5.1804 (Core)

Are you sure Telegraf is running as root? Normally when ran as a service it runs as telegraf.

Yes, you are correct telegraf is running as user “telegraf”. How can I resolve the current issue stated above?

You will have to arrange for the telegraf user to have permissions to attach to the process, the easiest way I know is to allow telegraf to run the command using sudo without a password.