How to custom build telegraf for docker desktop?

Dear,

I´m building a demo system consisting of InfluxDB, Telegraf, Grafana, in docker desktop.
I wonder how to custom build telegraf for use in a windows docker desktop environment. It seems all tutorials refer to or describe the native installation on the big three (Win/Mac/Linux). I assume this requires a dev container with GO et al. , right?

Any pointer is appreciated,

Best regards,

Jörg

Hey @Joerg_Sprengel,

you can simply cross-compile Telegraf. Here is a nice tutorial on the matter: How to cross-compile Go programs for Windows, macOS, and Linux (freshman.tech)

I guess you are using custom_builder so you should run

> make build_tools
> GOOS=windows ./tools/custom_builder/custom_builder ...

and you will get a telegraf.exe binary.
Does this answer your question?

Best regards,

Sven

Hi Sven,

this sounds very much what I was looking for, many thanks. This approach, however, doesn’t preempt for the need to create a custom docker container, too . I’ll give it a try and will report later.

Cheers,

Jörg

@Joerg_Sprengel if your question was if we provide a Windows docker container the answer is no AFAIK. :slight_smile:

Hi Sven,

that’s not the question - maybe I’m unclear. I’m currently running docker desktop on Win11 with the official Telegraf image (1.27). I was thinking to use a slim Telegraf binary serving only the plugins I need, hence my question.

If I understand docker and all of that correctly, something/someone needs to create a docker image with the slim Telegraf binary in it - otherwise any docker pull/rebuild will overwrite the stuff with the official image. Isn’t this what docker was made for?

Thanks again,
cheers,

Jörg

I’m also not sure I am going to answer your question, but in short: you could certainly build a custom docker image that only has your custom telelgraf build.

It is entirely up to you as to what base image you use or if you include any other deps. You could build a docker image with no other dependencies and try to make it as a small as possible. You could also build it with the Alpine or Debian base images like we do for the official images.

This really sounds like a how to use Docker question :wink:

Locally if I need to test a docker build I use the following Dockerfile:

FROM archlinux 

COPY telegraf /usr/bin/telegraf

CMD ["/usr/bin/telegraf"]

Our official docker files could also be used, but you would need to modify them to not pull down from the telegraf repo and instead use your custom binary.

indeed a how-to-use-docker question.

I guess this is the answer to the subject, many thanks,
Cheers,

Jörg

1 Like

Hello I have tried to create an rpm after custom build but when ever I have tried to install the telegraf getting some error like,
[root@ip-172-31-11-22 multi-user.target.wants]# systemctl status telegraf
× telegraf.service - Telegraf
Loaded: loaded (/usr/lib/systemd/system/telegraf.service; enabled; preset: disabled)
Active: failed (Result: exit-code) since Wed 2023-07-12 08:48:14 UTC; 12s ago
Docs: GitHub - influxdata/telegraf: The plugin-driven server agent for collecting & reporting metrics.
Process: 39784 ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRA>
Main PID: 39784 (code=exited, status=2)
CPU: 5ms

After trying to debug getting this

[root@ip-172-31-11-22 multi-user.target.wants]# telegraf --debug
flag provided but not defined: -debug

This is a tool build Telegraf with a custom set of plugins. The plugins are
select according to the specified Telegraf configuration files. This allows
to shrink the binary size by only selecting the plugins you really need.
A more detailed documentation is available at
http://github.com/influxdata/telegraf/tools/custom_builder/README.md

Usage:
custom_builder [flags]

Flags:
-config value
Import plugins from configuration file (can be used multiple times)
-config-dir value
Import plugins from configs in the given directory (can be used multiple times)
-dry-run
Skip the actual building step
-migrations
Include configuration migrations
-quiet
Print fewer log messages
-tags
Show build-tags used

Examples:

The following command with customize Telegraf to fit the configuration found
at the default locations

custom_builder --config /etc/telegraf/telegraf.conf --config-dir /etc/telegraf/telegraf.d

You can the --config and --config-dir multiple times

custom_builder --config global.conf --config myinputs.conf --config myoutputs.conf

or use one or more remote address(es) to load the config

custom_builder --config global.conf --config http://myserver/plugins.conf

Combinations of local and remote config as well as config directories are
possible.

[root@ip-172-31-11-22 multi-user.target.wants]#

Didn’t get any idea how to solve it. Can anyone help me on this

If you are running telegraf as a service then you should get the logs from the journal:

journalctl --no-pager --unit telegraf

See what that says

Also please put your console text that you are copying between ``` above and below the text to make it easier to read please.

Problem solved. Thanks