influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.9k stars 5.6k forks source link

Input.Exec empty output emit warning #2448

Closed jeremydenoun closed 7 years ago

jeremydenoun commented 7 years ago

Descriptions

Since 1.2.1 (but maybe before because I jump from 1.0.1 -> 1.2.1) If I setup an input.exec source with an empty output I have an error with in log :

ERROR in input [inputs.exec]: Errors encountered: [metric parsing error, reason: [buffer too short], buffer: [], index: [0]]

with a valid data we don't have this error

Relevant telegraf.conf:

[[inputs.exec]]
  commands = ["/telegraf-plugin/empty_metrics.sh"]
  timeout = "5s"
  data_format = "influx"

empty_metrics.sh (emit error) :

#!/bin/bash
cat $0 | sed "1,3d"
exit 0

and if I change for

#!/bin/bash
cat $0 | sed "1,3d"
exit 0
kernel_vmstat random_entropy_avail=42

no errors

System info:

telegraf 1.2.1 / debian 8.1 / debian official package

sparrc commented 7 years ago

what would you expect it to do???

seems like an error to me

jeremydenoun commented 7 years ago

Hi Cameron,

I expect no error because no content output isn't an error.

What do you suggest if I have a script who can generate a metric or not ? (maybe change config and restart telegraf without my "empty content" script and rechange when metrics comeback ? but this can restart telegraf very often)

This is an issue for me because I supervise logfile and this error is print each period on collect

Thanks for your help

danielnelson commented 7 years ago

It sounds to me like you really need something like the logparser input but with access to the data_format parsers?

danielnelson commented 7 years ago

Or perhaps the tail input would work?

jeremydenoun commented 7 years ago

not really or I don't understand something but for help you to understand my issue, my script look like :

if [ "$var" -eq XX ]; then
   echo "Metrics A"
elif [ "$var" -eq YY ]; then
   echo "Metrics B"
else
   #I don't want any metrics in this case
fi

and in the 'else' case I have a script output empty content (so emit warning in telegraf log).

I can't remove my script in empty case because the '$var' can change between execution, so I need to find a way to clean this "false" warning without hack my log detection.

Thanks

danielnelson commented 7 years ago

The solution in your PR is a good addition, I was just curious if one of the logfile streaming inputs would be more convenient if it were able to filter your log into one of the data_format. That way you wouldn't need to reopen and reposition in the file stream on every gather. To be clear, the exec plugin is the only current way that I know of to accomplish your task.