-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Templatable output data_format #13637
Comments
Hi @gazpachoking, This sounds potentially interesting. Would you be willing to provide an example of how you would use this, both a template + destination format, to give us a test case? |
Sure. This is super specific to my use case, but here's how I imagined it. The send_nsca program takes data via stdin, and I already have the data needed contained within my tags and fields. [[outputs.exec]]
fieldpass = ["CAT"]
command = ["send_nsca"]
data_format = "template"
template = 'my-nagios-host\t{{ .Tag "site" }}-{{ .Tag "device" }}\t0\tOk: {{ .Field "CAT" }}' EDIT: This is the format send_nsca is expecting Right now I have it working with a wrapper script that parses the influx line protocol then just does the above templating itself and pipes the data to the send_nsca program. I imagine a templated data format could also be useful if you were writing your own custom script for exec or execd output, in that you could make your parsing of stdin much simpler by only including the exact info you want in whatever format you want. |
Thanks for that. I was looking at the template processor earlier to see how we set this up there as well. This could be rather powerful for folks who may want even more customization or power over for JSON output. My concern is around getting the template definition right. For example, you have the line to define a template that I assume would apply to each metric the serializer receives. Let me chat with Sven when he is back in to see if he has any concerns. Is this something you are interested in contributing? |
I can have a go at it if I get some time, but I'm not too versed in go, so I'm not fully confident if I'll come up with a satisfactory solution yet. EDIT: Yeah, I might be able to handle it. I've hacked together something that seems to be working. Still needs quite a bit of cleanup and testing though. |
So, we have a couple options for how to handle batch mode:
I think 2 is the nicer answer, but I noticed that the 'exec' output always serializes in batches, and the 'execd' output always serializes individual metrics. I think that should probably be changed so that there is the option for either batched or non-batched mode in both of those plugins, with the default being individual metrics, so the user doesn't have to unexpectedly change their template when switching between them. The docs don't currently mention this at all, so I think this is already confusing if you are using exec/execd with the json serializer, and already warrants its own issue. |
If batch format is separate, is it preferred to just emit the array of metrics as dot for the template? Or is it better to be in a namespace. |
Here's the work in progress: |
Thanks for working on this!
#11902 already exists for
Think I agree
Feel free to put up a PR, but we will absolutely want tests :) |
Absolutely. I was waiting to open up a PR until I got some in there. |
This seems a bit different, no? Isn't that ticket to do with how the shim works in an external plugin, rather than how the internal execd plugin works? My understanding is that my proposal wouldn't affect how the shim/external plugin works at all. (I could be misunderstanding though, as I haven't fully grokked the telegraf internals, or how the shims work for external plugins.) |
ok I see your point, they are slightly different so we should keep them separate. I've commented on the new issue. |
Use Case
I want to output metrics to nagios using NSCA. There is a client which takes input on stdin, but I need to be able to customize the format. Having a data_format that allowed defining a go template would allow for this kind of use case using output.execd without having to write a wrapper script. The problem with the wrapper script is that most of the script consists of parsing the measurement, tags, and fields back out of the influx line protocol (whatever data_format is used.)
Expected behavior
A new data_format for outputting, which allows defining what goes to stdout based on a go template.
Actual behavior
A special script needs to be written which parses one of the existing data_formats, then rewrites to appropriate format that an external application is expecting.
Additional info
No response
The text was updated successfully, but these errors were encountered: