telegraf-query

module
v0.0.0-...-19cf3d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2021 License: MIT

README

Query Input Plugin for Telegraf

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:

Usage

  • Install telegraf

  • Build the plugin:

    make all
    
  • Install the build to your system:

    mkdir -p /etc/telegraf/plugins/inputs/execd/query
    cp dist/* /etc/telegraf/plugins/inputs/execd/query
    chmod +x /etc/telegraf/plugins/inputs/execd/query/query
    
  • 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

    ## 
    ## Input plugins: Query
    ## 
    [[inputs.execd]]
      command = ["/etc/telegraf/plugins/inputs/execd/query/query", "--config", "/etc/telegraf/plugins/inputs/execd/query/plugin.conf"]
      signal = "none"
    
  • Restart or reload Telegraf

Development

go mod init github.com/ricfio/telegraf-query
go mod tidy
go mod edit -replace github.com/ricfio/telegraf-query=./

make

usage: make

TARGETS:
  all          Build all
  clean        Clean all
  install      Install plugin
  run          Run plugin
  test         Run test
Contributing an External Plugin
External Input Plugin Examples

Directories

Path Synopsis
plugins

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL