The telegraf-query is an external telegraf input plugin to collects metrics from a sql query.
You can use this telegraf input plugin as base for development of other external plugins.
NOTES
This plugin was implemented for professional and educational purposes to learn: telegraf, telegraf-plugin and go language.
You can find an official telegraf input plug-in (included as a bundle in the standard telegraf installation) that supports the same features but in a much more mature and comprehensive way:
Edit plugin configuration as needed: vi /etc/telegraf/plugins/inputs/execd/query/plugin.conf
Create the mysql user for the telegraf plugin (for example):
CREATE USER IF NOT EXISTS telegraf IDENTIFIED BY 'GQ9TpUKDYLkkDM1eguAl'; GRANT SELECT, PROCESS, SHOW DATABASES, SUPER, REPLICATION CLIENT, SHOW VIEW, CREATE USER ON *.* TO telegraf; FLUSH PRIVILEGES;
Test plugin execution as standalone: /etc/telegraf/plugins/inputs/execd/query/query --config /etc/telegraf/plugins/inputs/execd/query/plugin.conf
Add to /etc/telegraf/telegraf.conf or into file in /etc/telegraf/telegraf.d/execd-query.conf