Telegraf charm for k8s


This post is about a k8s charm for telegraf that I wrote using the operator framework.

Telegraf is an agent for collecting, processing, aggregating, and writing metrics. We (Canonical IS) use it to monitor all our servers, physical and virtual, as well as the DBs, web servers, etc. running on them.

I think that telegraf is a great software, and in the past years, contributed various things for it (an input plugin, a snap, and an update to the (IAAS) charm to support that snap).

My first thought about a k8s charm for telegraf, was that it would be pointless: telegraf running in a container, monitoring itself.

But there are actually a lot of input plugins which monitor remote services, totally decorrelated from the host where telegraf runs.

For instance:

  • http_response (monitor responses from an http(s) server)
  • github (gather stats about a github repo)
  • dns_query (gathers dns query times from a list of servers)
  • minecraft (collects scores from a minecraft server) (yes.)

For these plugins, deploying on k8s totally makes sense.

The charm is available on the charm store.

By default, it uses an OCI image built by Launchpad.

It uses a few configuration items, which are native telegraf config stanzas.

For instance, to deploy and configure telegraf to monitor a github repository, and expose the metrics for scraping by prometheus on port 9103:

juju deploy cs:~telegraf-charmers/telegraf-k8s --config inputs='[[inputs.github]]
repositories = ["influxdata/telegraf"]' \
--config outputs='[[outputs.prometheus_client]]
listen = ":9103"'

The charm embeds a suite of unit tests, and an MP is pending to add functional tests, leveraging the zaza framework. The functional tests allow to quickly validate changes by deploying locally with microk8s and running additional tests on live units.

As mentioned above the charm uses an OCI image built by Launchpad by default, but it is also possible to build a custom image using the Dockerfile and Makefile target image-build from the charm code repository on Launchpad. Once built and pushed to your local docker registry, you can deploy by setting the image_path charm option.

We would be interested in any feedback on the charm. Please feel free to file bugs against the project on Launchpad.

Special thanks to John Lenton (@chipaca) and Facundo Batista (@facundo) for their very valuable feedback in the code review.