How are Telegraf output plugins called?

Hi all,

How are Telegraf output plugins called?
Meaning, is the code in the plugin package folder (example: plugins/output/influxdb) run every time Telegraf needs to flush the metrics out, sort of like running a loop?

I think it’s probably more accurate to say the plugins are functions (hooks) that are called by the main telegraf code. Take a look:

https://github.com/influxdata/telegraf/blob/master/plugins/outputs/influxdb_v2/influxdb.go

What prompted your question ? What issues have you run into?

Hi,

Not experiencing any issues, I’m currently developing an output plugin the authenticates with google to create a token that is then used to make a REST request.
To avoid having to authenticate for a new token every time metrics are sent I’m trying to understand how the code is used by telegraf as the token can expire roughly once an hour. This would reduce the overhead of the handshaking process by only requesting a new token once an hour has elapsed, otherwise saving the value as a variable if it had only been say forty five minutes.
Make sense?

Thanks!

Got it. Yeh not sure based on a search of other plugins. You might be able to make some memory based cache using a file under /dev/shm- but that’s a bit of a hack and might not get accepted as an official plugin. Maybe @scott might have some other suggested approaches.

Out of curiosity how much time does getting a token actually require currently?

Hi @FixTestRepeat !

When running on my machine the code takes about a second to execute though I notice that occasionally I see this error:
2020-08-05T15:25:24Z W! [agent] ["outputs.cloudrun"] did not complete within its flush interval
but it seems largely benign as the buffer releases metrics on the next pass.
Just thought it would be best practice to only get the new token after after a certain time has past instead of when the metrics trigger, though it seems to be working fine for the most part.

Is there any missing data points before/after where you see these warnings? If not, then if no luck with caching angle, maybe try experimenting with flush_interval and flush_jitter?

Hi,
No missing points as far as I can tell, and after running it for some time I’m finding the warning to be very rare, and when it does the buffer just drains on the next pass.

Thanks for the assistance!