I spun up a configuration that uses the tail input plugin configured with the “logfmt” data input format. The input plugin appears to be working as expected. However, I have not been able to figure out how to specify which field contains the time stamp and to provide the timestamp format. Can this be specified with the logfmt input data format? Or, is there a way to use a processor to process the timestamp?
There currently isn’t anything in the logfmt parser to specify which field contains a timestamp. It seems to always use the time at processing. If that’s not ideal, you can open a feature request to add an option like json’s json_time_key. Otherwise you should be able to drop the ts tag?
Just to verify, is ts being output as a tag or a field?
Hi @glinton ts is a field. I thought using a parser processor would allow me the opportunity to extract the timestamp but it doesn’t seem to do the trick?
@glinton There is a workaround for this but it is kind of ugly. If I reverse the order of things I tried earlier I can almost make it work. That is, use a tail input plugin configured with a grok input data format. I can capture the timestamp from the input and the remainder of the log line is captured into a field (I called it “message”) as follows:
The unfortunate consequence is that the “message” field passes through to the output. I had a look at the “fielddrop” filter but it appears you cannot use it inside an output. And if I try to use it in the parser processor, nothing passes to the output suggesting the drop happens before the parser processes the field.
Is there another way I can drop the unwanted field?
I may be incorrect, but I think if you set drop_original=true, the original message field will not get passed through to the output. If that doesn’t work, setting field_drop=["message"] should do the trick. Learn more about field drop here.
Unfortunately, the drop_original=true parameter drops everything, including tags that I added with the input plugin [inputs.tail.tags].
Regarding fielddrop, the documentation indicates that you cannot use it in the output plugin. Is that correct?
Regarding the error message in the telegraf log, the equals inside the quoted string is not the problem. I think I have found a bug in the grok input data processor. Here is an example:
Note the quoted string value for the “msg” field in the input line. Also note the position of this field in the input line and particularly the double quote at the end of the line.
In the output line there are two issues. First, the “message” field is missing the second escaped double quote that goes with the “msg” field value. Second, the “message” field has not been parsed by the logfmt parser. I now believe this is what is throwing the logfmt syntax error message in the telegraf log (unterminated quoted value). Accordingly, the parser processor ignores the line which explains why the parsed fields and tags do not appear in the output.
I believe I have tracked this problem down and isolated it to the log lines that end with a double quote. Thus, the lines that end with msg=“some text” are mangled and are missing the second escaped double quote. I have confirmed that any line from the input that ends without a double quote is properly parsed by the grok input data processor and passed along to the logfmt parser processor. This appears to be a bug and I think it is with the grok input data format.