Contenu connexe Similaire à Sebastian Spaink [InfluxData] | Layer by Layer: Printing Your Own External Input Plugin for Telegraf | InfluxDays EMEA 2021 (20) Sebastian Spaink [InfluxData] | Layer by Layer: Printing Your Own External Input Plugin for Telegraf | InfluxDays EMEA 2021 2. © 2021 InfluxData. All rights reserved. 2
• My Name: Sebastian Spaink
• Team: Data Acquisition
• Quarantine Craft: 3D printing
| Introduction
3D printed Gopher!
3. © 2021 InfluxData. All rights reserved. 3
• Share how AWESOME external plugins are in Telegraf!
• Give you the knowledge you need to make your own!
| Goal?
4. © 2021 InfluxData. All rights reserved. 4
1. What and Why of external plugins
2. Show basic example
3. Walkthrough practical example
4. How to start with a new language?
| Overview
5. © 2021 InfluxData. All rights reserved. 5
● Telegraf: The plugin-driven agent for collecting & reporting metrics
● Hundreds of internal plugins included!
| Overview of Telegraf and its plugins
6. © 2021 InfluxData. All rights reserved. 6
Definition: An external plugin is a program outside of Telegraf that
can communicate and be run by a Telegraf plugin called execd
● There is a execd plugin for: input, processor, output
● Communicates through STDOUT with supported data format
External Plugins:
https:/
/github.com/influxdata/telegraf/blob/master/EXTERNAL_PLUGINS.md
| What is an external plugin?
7. © 2021 InfluxData. All rights reserved. 7
• Benefits:
– Create a plugin that covers your unique use case
– Begin using it immediately
– Write it in any language, not limited to Go
| Why would you want to make one?
For example a external plugin written in Python:
• https:/
/github.com/jhpope/smc_ipmi
8. © 2021 InfluxData. All rights reserved. 8
| Keep it simple, a basic example
Straight from the README:
https:/
/github.com/influxdata/telegraf/tree/master/pl
ugins/inputs/execd#daemon-written-in-bash-using-st
din-signaling
A simple bash script that blocks, waiting for
input from STDIN, incrementing a counter.
Done. You have an external plugin!
9. © 2021 InfluxData. All rights reserved. 9
| Configure it with Telegraf
Telegraf Config
11. © 2021 InfluxData. All rights reserved. 11
| Signals accepted by execd plugin
● "none" : Do not signal anything. (Recommended for service
inputs) The process must output metrics by itself.
● "STDIN" : Send a newline on STDIN. (Recommended for gather
inputs)
● “SIGHUP" : Send a HUP signal. Not available on Windows. (not
recommended)
● "SIGUSR1" : Send a USR1 signal. Not available on Windows.
● "SIGUSR2" : Send a USR2 signal. Not available on Windows.
12. © 2021 InfluxData. All rights reserved. 12
| Getting started with a practical example
● Octoprint: open source 3D printer controller application,
which provides a web interface for the connected printers
● Information you can get:
○ Printing state: paused or ready
○ Current temperature of nozzle/printing bed
● All you need is an API to make an input plugin!
13. © 2021 InfluxData. All rights reserved. 13
| Easy start to an external plugin, the Go Shim
● The Telegraf execd Go shim is a great way to start!
● A scaffolding created to make plugins as if they were in Telegraf
○ Provides same structures used in the internal project
○ Provides logic to interact with the execd plugin
14. © 2021 InfluxData. All rights reserved. 14
| Go Shim Versus Execd Plugin
● Go Shim: A utility tool to help start external plugins
● Execd Plugin: A Telegraf plugin to manage external plugins
Go Shim Execd Plugin Telegraf
15. © 2021 InfluxData. All rights reserved. 15
Get the main.go from the examples/cmd directory and
place it in your project.
Then you just need to edit the file to import the package
containing your plugin code, such as so:
| Quick step overview to use Go shim
Reference link:
https:/
/github.com/influxdata/telegraf/tree/master/plugins/common/shim
16. © 2021 InfluxData. All rights reserved. 16
| Gather the data
Screenshot #1 Screenshot #2
17. © 2021 InfluxData. All rights reserved. 17
| Custom configuration
● Optionally, you can create a separate config file for your
external plugin
● It is required this config is completely separate from the main
config and lives in another directory
18. © 2021 InfluxData. All rights reserved. 18
| Configuring the Octoprint plugin with Telegraf
1. Build the external plugin you’ve made to an executable binary
2. Then update the main Telegraf config such as below:
Note: The signal is set to “none” instead of “STDIN”
● The execd Go shim has a default polling interval of 1 second
○ can be adjusted by passing the flag poll_interval
21. © 2021 InfluxData. All rights reserved. 21
| Extend Octoprint with plugins!
● Not Telegraf plugins, but different plugins!
● Display Layer Progress
○ https:/
/plugins.octoprint.org/plugins/DisplayLayerProgress/
● Filament Manager
○ https:/
/plugins.octoprint.org/plugins/filamentmanager/
22. © 2021 InfluxData. All rights reserved. 22
| Display Layer Progress
● This plugin displays the current layer being printed!
● Fun to know and helpful!
23. © 2021 InfluxData. All rights reserved. 23
| Display Layer Progress
● New API endpoint: /plugin/DisplayLayerProgress/values
24. © 2021 InfluxData. All rights reserved. 24
| Filament Manager
● To get the filament data we need a postgres database!
29. © 2021 InfluxData. All rights reserved. 29
| Overview Components
inputs.execd outputs.influxdb_v2
Octoprint external plugin
Telegraf
API
Display Layer
Progress API
Filament
Manager
Postgres DB
Octoprint
InfluxDB 2.0
30. © 2021 InfluxData. All rights reserved. 30
| Try it for yourself!
● Source Code: https:/
/github.com/sspaink/octoprint-telegraf-plugin
● Feel free to make a pull request with changes!
31. © 2021 InfluxData. All rights reserved. 31
| Creating your own plugin
● With the structure defined, the rest is just regular fun coding!
● Tip: Following the plugin guidelines are a great way to work!
○ when external, they are more “guidelines” then actual rules…
Guidelines:
● https:/
/github.com/influxdata/telegraf/blob/master/docs/INPUTS.md
● https:/
/github.com/influxdata/telegraf/blob/master/docs/PROCESSORS.md
● https:/
/github.com/influxdata/telegraf/blob/master/docs/OUTPUTS.md
32. © 2021 InfluxData. All rights reserved. 32
• No shim?!?! What to do!
• Let’s try to re-implement the octoprint plugin in Rust!
| What if I want to use a different language?
33. © 2021 InfluxData. All rights reserved. 33
| Let’s try to implement octoprint plugin in Rust!
Output in influxdb line protocol
Loop in one second intervals
Set configuration
Gather data
35. © 2021 InfluxData. All rights reserved. 35
| What about outputs and processors?
Output Example: https:/
/github.com/morfien101/telegraf-output-kinesis
Processor Example: https:/
/github.com/a-bali/telegraf-geoip
36. © 2021 InfluxData. All rights reserved. 36
• Filter issues/pr’s by the label external plugin
• Suid input plugin: https:/
/github.com/influxdata/telegraf/pull/7597
• Libvirt input plugin: https:/
/github.com/influxdata/telegraf/issues/690
• Jira input plugin: https:/
/github.com/influxdata/telegraf/pull/4944
| Need ideas?
37. © 2021 InfluxData. All rights reserved. 37
Thank you for watching! I hope you learned something.
I look forward to seeing any external plugins you might make!
If you do make one, please share it by making a pull request to
update the EXTERNAL_PLUGINS.md doc in the Telegraf project!