<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Rick Brown</title>
    <description>Posts by Rick Brown on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/rick-brown/</link>
    <language>en-us</language>
    <lastBuildDate>Mon, 09 Dec 2019 07:00:57 -0700</lastBuildDate>
    <pubDate>Mon, 09 Dec 2019 07:00:57 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>Continuous Deployment of Telegraf Configurations</title>
      <description>&lt;p&gt;After I shared my “&lt;a href="https://www.influxdata.com/blog/using-a-telegraf-gateway/"&gt;Using Telegraf as a Gateway&lt;/a&gt;” post with &lt;a href="https://twitter.com/rawkode"&gt;Rawkode&lt;/a&gt;, he mentioned a talk he gives, where he discusses advanced Telegraf topics, including a requirement he’s seen for automatically configuring running Telegraf instances just by editing config files in GitHub. Watch that talk &lt;a href="https://www.youtube.com/watch?v=3iZnGnRRs8E"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I had a couple of questions about Telegraf reloading its configs, which he answered, and I wondered whether I have all the toolkit components already running in my home LAN to get this working. I could look at implementing a Continuous Delivery or Release Automation application to do this, but I’ll look at using what I already have.&lt;/p&gt;

&lt;p&gt;I found that I already use everything I need! So here’s a Continuous Deployment mechanism for Telegraf. To replicate this, you will need:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li&gt;&lt;a href="https://www.influxdata.com/time-series-platform/telegraf/"&gt;Telegraf&lt;/a&gt;
&lt;ul&gt;
 	&lt;li&gt;I mostly use Linux servers, but I have a couple of Windows machines and I mention how to include those later in this post&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
 	&lt;li&gt;Root access to those machines
&lt;ul&gt;
 	&lt;li&gt;to change configuration files&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
 	&lt;li&gt;&lt;a href="https://nodered.org/"&gt;Node-RED&lt;/a&gt;
&lt;ul&gt;
 	&lt;li&gt;other applications that permit the dynamic creation of HTTP endpoints would do just as well, but I use Node-RED&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
 	&lt;li&gt;Err, that's it!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When installed on Linux (Debian - other distros might put config locations elsewhere), Telegraf command line options read &lt;strong&gt;/etc/telegraf/telegraf.conf &lt;/strong&gt;and &lt;strong&gt;/etc/telegraf/telegraf.d/*.conf&lt;/strong&gt;. Telegraf also includes the option of reading its configuration from an HTTP endpoint, which you’ll have seen if you use InfluxDB v2. When prompted to configure Telegraf with InfluxDB v2, you are provided with an API Token to store as an environment variable on the machine where your Telegraf runs, and you’re presented with this command line:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;telegraf --config https://InfluxDBCloud2Instance/api/v2/telegrafs/NNN&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That command line will run Telegraf (assuming it’s in your PATH), connecting to the specified endpoint to read its configuration from there.&lt;/p&gt;

&lt;p&gt;So, what happens if I use this configuration?&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;/usr/bin/telegraf -config http://192.168.1.8:1880/telegraf/myhost&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This should connect to that IP address (it’s my Node-RED server) on port 1880 (the Node-RED port), to the endpoint &lt;strong&gt;/telegraf/myhost&lt;/strong&gt;. If I can get Node-RED to respond to web requests on&lt;strong&gt; /telegraf/myhost&lt;/strong&gt;, I should be able to send a configuration to Telegraf.&lt;/p&gt;

&lt;p&gt;The Node-RED http-in and http-out nodes are designed to do exactly this.&lt;/p&gt;

&lt;p&gt;The next challenge is that each of my Telegraf instances might want a different set of configurations, so I want Node-RED to understand which instance of Telegraf is calling it, and to change configs accordingly. Telegraf will send a GET, so it’ll need to ensure the URL is unique in some way.&lt;/p&gt;

&lt;p&gt;After that, I want Node-RED to provide updated configurations, for when I change any config, so I need to have Node-RED refresh its configs periodically. What might be a reasonable refresh time? I’ll go with 10 minutes.&lt;/p&gt;

&lt;p&gt;Then I want each instance of Telegraf to refresh configurations, so everything is automated. What might be a reasonable refresh time for this? I’ll try an hour.&lt;/p&gt;

&lt;p&gt;Of course, I want all this stuff to run without exposing any sensitive config information, so I need to have Node-Red modify any retrieved configs to add personal information such as the InfluxDB v2 API Token.&lt;/p&gt;

&lt;p&gt;This is quite a kit-bag of things I need to do, so let’s get to it!&lt;/p&gt;

&lt;p&gt;First, the Telegraf end:&lt;/p&gt;

&lt;p&gt;I run Telegraf from &lt;strong&gt;systemd&lt;/strong&gt; in all my LXC containers, so it runs automatically on start-up. Therefore, the configuration of Telegraf is in the &lt;strong&gt;systemd&lt;/strong&gt; directories. If you’re manually running Telegraf, running on a system that uses sysvinit, or running from Docker, you’ll need to modify accordingly, but for my configuration, I need to edit the Telegraf service file located here:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/lib/systemd/system/telegraf.service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Copy that file to &lt;strong&gt;/etc&lt;/strong&gt;, so it’s preserved when Telegraf is updated:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;cp /lib/systemd/system/telegraf.service /etc/systemd/system&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now edit the new file. The ExecStart line shows the command line that will run Telegraf, with the &lt;strong&gt;-config&lt;/strong&gt; and &lt;strong&gt;-config-directory&lt;/strong&gt; options. Change it to this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;ExecStart=/usr/bin/telegraf -config http://192.168.1.8:1880/telegraf/%H $TELEGRAF_OPTS&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the &lt;strong&gt;%H&lt;/strong&gt;. It’s a special property in systemd that means “replace this with the hostname of this machine”, so each machine will request its own set of configs. That should be enough uniqueness for now — if I ever want to implement multiple instances of Telegraf on a single machine, or expand this mechanism to include environment definitions, I’ll investigate abstractions in systemd to retrieve variables from the EnvironmentFile entry rather than using &lt;strong&gt;%H&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Look at the next line in that file:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;ExecReload=/bin/kill -HUP $MAINPID&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This states that a “systemctl reload” command will send a SIGHUP signal to Telegraf, which is designed to cause Telegraf to refresh its configuration. I want to execute that on an hourly schedule. Linux machines run cron for regular automated tasks, so we can use this facility. Create the file &lt;strong&gt;/etc/cron.hourly/telegraf&lt;/strong&gt; and put these lines into it:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-bash"&gt;#!/bin/bash -e 
# random sleep (max 5 min) to prevent clients from hitting the server at the same time 
SLEEP=$[ ($RANDOM % 300) ] &amp;amp;&amp;amp; sleep $SLEEP 
systemctl reload telegraf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will cause Telegraf to reload its configuration every 60-65 minutes.&lt;/p&gt;

&lt;p&gt;Make that file executable:&lt;/p&gt;

&lt;p&gt;This will cause Telegraf to reload its configuration every 60-65 minutes.&lt;/p&gt;

&lt;p&gt;Make that file executable:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;chmod +x /etc/cron.hourly/telegraf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;Notes:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;em&gt;If your filename uses punctuation marks, it will be rejected by cron. There's no running a &lt;strong&gt;telegraf.runthis&lt;/strong&gt; file — just keep the filename simple.&lt;/em&gt;&lt;/li&gt;
 	&lt;li&gt;&lt;em&gt;If you want your config reload to happen at a different time scale than hourly, other parts of the cron system enable this, so you can edit crontab, cron.daily, etc.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now run two commands:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;systemctl daemon-reload 
systemctl restart telegraf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and Telegraf will now complain in its log file that it can’t get a configuration from anywhere. We’d better jump to Node-RED and sort this out!&lt;/p&gt;

&lt;p&gt;Before we run off, a quick note for readers running Telegraf on Windows. Edit the registry, go to:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-lua"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\telegraf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Change ImagePath to this (change the IP address to that of your own Node-RED server):&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-bash"&gt;"C:\Program Files(x86)\Telegraf\telegraf.exe" --config 
"http://192.168.1.8:1880/telegraf/%ComputerName%"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Either reboot, or run “Services” and restart Telegraf.&lt;/p&gt;

&lt;p&gt;This will NOT cause Telegraf to regularly reload its configuration in Windows. Just reboot the PC or restart the Telegraf service for this to happen.&lt;/p&gt;

&lt;p&gt;Now, let’s run to Node-RED.&lt;/p&gt;

&lt;p&gt;Create a new tab in Node-RED. Add the required nodes into it for configs.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/timestamp.png" alt="timestamp" width="1026" height="292" /&gt;&lt;/p&gt;

&lt;p&gt;The first node, “timestamp”, updates the configs every 10 minutes.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-inject-node.png" alt="edit inject node" width="996" height="1026" /&gt;&lt;/p&gt;

&lt;p&gt;The next nodes set properties for private settings. These are “Change” nodes, and are where I’ll add all my personal information for connecting and authenticating against my Cloud instances of InfluxDB. They look like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-Change-node-2.png" alt="edit change node" width="986" height="1256" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-change-node.png" alt="" width="984" height="1244" /&gt;&lt;/p&gt;

&lt;p&gt;Now we need to retrieve the configs from wherever they are stored. I created nodes like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/creating-nodes.jpg" alt="creating nodes" width="1200" height="763" /&gt;&lt;/p&gt;

&lt;p&gt;This is the time where you can get really creative! You might want to store your configs in GitHub or GitLab, or you might be into Software-Defined Networking (config-as-a-service) and so want to send updates over something like a messaging topic. Updated config data can come from many places, and the only difference in Node-RED is the type of node used to update the config information:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/update-config-infomation.jpg" alt="update config information" width="958" height="584" /&gt;&lt;/p&gt;

&lt;p&gt;I prefer to use Node-RED to directly store my configs, so my config nodes look something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/edit-template-node-output-cloud1.jpg" alt="" width="900" height="1105" /&gt;&lt;/p&gt;

&lt;p&gt;Note the “mustache” template for the options &lt;code class="language-bash"&gt;urls&lt;/code&gt;, &lt;code class="language-bash"&gt;database&lt;/code&gt;, &lt;code class="language-bash"&gt;username&lt;/code&gt; and &lt;code class="language-bash"&gt;password&lt;/code&gt;. These pieces of information are retrieved from the “Change” nodes and inserted into here, so the data is always correct and current.&lt;/p&gt;

&lt;p&gt;Multiple config snippets can exist in one template node. Create each template node as you would like, for best readability, understanding, and appropriate re-use, such as this one for a set of core monitoring inputs:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-template-node-3-1.png" alt="" width="1066" height="1294" /&gt;&lt;/p&gt;

&lt;p&gt;After a deployment of the flow, all of our config snippets are loaded into Node-RED, and refreshed every 10 minutes. The final task is to serve a web page for Telegraf to use:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/config-snippets.jpg" alt="config snippets" width="1200" height="529" /&gt;&lt;/p&gt;

&lt;p&gt;The first node in this flow is a “http-in” node. It listens for GET requests on &lt;strong&gt;http://192.168.1.8:1880/telegraf/:hostname&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/http-in-node.jpg" alt="http in node" width="394" height="178" /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class="language-bash"&gt;:hostname&lt;/code&gt; automatically becomes a property in Node-RED, which we will use in the “Select on hostname” Switch node. Remember when we configured Telegraf with &lt;strong&gt;%H&lt;/strong&gt;? That parameter replacement is what we’re using here.&lt;/p&gt;

&lt;p&gt;The Switch node matches against the hostname, and sends the request down a specific path for each host.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-Switch-node-1.png" alt="" width="996" height="1300" /&gt;&lt;/p&gt;

&lt;p&gt;As an example to follow the workflow, let’s look at what happens for the host “mqtt”. After the Switch node selects the “mqtt” path, it goes next to a “MQTT config” template node, which enables specific monitoring config for my MQTT implementation.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-template-node-2.png" alt="" width="1060" height="1290" /&gt;&lt;/p&gt;

&lt;p&gt;That config contains my ActiveMQ and Jolokia-2 config information (I use ActiveMQ as my MQTT broker because it has monitoring hooks and a built-in view of all the topics I’m using, along with an indication of how many subscribers I have listening to each topic). The workflow then goes to the Linux config node, which inserts all the standard Linux monitoring configs I want to use, appending the MQTT config at the end:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/Edit-Template-node.png" alt="" width="1070" height="1284" /&gt;&lt;/p&gt;

&lt;p&gt;The final step is a “http-out” node, which responds to the original requestor with the required config data.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/http-out-node.jpg" alt="http out node" width="278" height="194" /&gt;&lt;/p&gt;

&lt;p&gt;Every few minutes, Node-Red logs that a connection has been made and a new config has been served:&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/debug-2.jpg" alt="" width="636" height="1396" /&gt;&lt;/p&gt;

&lt;p&gt;How does this look from the Telegraf end? Here’s a section of &lt;strong&gt;telegraf.log&lt;/strong&gt; from the server named “mqtt”, which shows what happens when the reload command is sent to Telegraf, how it writes all buffered points to InfluxDB before it restarts and loads all its updated inputs and outputs.&lt;/p&gt;

&lt;p&gt;&lt;img src="/images/legacy-uploads/telegraf-output.jpg" alt="telegraf output" width="1200" height="839" /&gt;&lt;/p&gt;

&lt;p&gt;Note that the first outputs after the reload contain more points than the outputs before the reload. This is Telegraf processing inputs that were buffered while it was reloading its config. During testing, I noticed that, if I write to the Telegraf instance over HTTP while it’s reloading its config, the HTTP port isn’t open, so this could be a consideration for determining how frequently to reload configs.&lt;/p&gt;

&lt;p&gt;So all my Telegraf instances are now updating their running config every hour, which means I can tune my jitter and buffers as required, and I can update my configs as I want, for every instance of Telegraf, a subset of instances, or individually, all without needing to log in to a server.&lt;/p&gt;

&lt;p&gt;Node-RED can even be configured to commit your tabs to version control, so all the configs are safe and secure.&lt;/p&gt;

&lt;p&gt;In effect, I’ve just configured Node-RED-to-Telegraf to run as a configuration management / change management / continuous deployment system, all through UI elements using model-based processes, without needing a single line of code.&lt;/p&gt;

&lt;p&gt;I don’t know if I’m going to continue to use this mechanism for Telegraf configs, whether I’ll use the &lt;a href="https://www.influxdata.com/blog/using-a-telegraf-gateway/"&gt;Telegraf Gateway&lt;/a&gt; mechanism, or whether I’ll use a combination of both. I’ll run a combination for now and revisit this at a later date to determine the most appropriate deployment mechanism for my use case.&lt;/p&gt;
</description>
      <pubDate>Mon, 09 Dec 2019 07:00:57 -0700</pubDate>
      <link>https://www.influxdata.com/blog/continuous-deployment-of-telegraf-configurations/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/continuous-deployment-of-telegraf-configurations/</guid>
      <category>Use Cases</category>
      <category>Product</category>
      <category>Developer</category>
      <author>Rick Brown (InfluxData)</author>
    </item>
    <item>
      <title>Using A Telegraf Gateway</title>
      <description>&lt;p&gt;If you meet InfluxData at a trade show, or we provide you with a demo, you might be shown the dashboard called “Rick’s House”. I’m that “Rick”, and this is how I’m sending my data to InfluxDB Cloud, which currently looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img class="size-full wp-image-239233 aligncenter" src="/images/legacy-uploads/sending-data-to-influxdb-cloud.png" alt="Sending data to InfluxDB Cloud" width="1600" height="850" /&gt;&lt;/p&gt;

&lt;p&gt;My home network contains numerous servers (many of them LXC containers in Proxmox), lots of software components (Node-Red, MQTT, MariaDB, etc), and a variety of smart-home sensors (SmartThings, Xiaomi, IKEA). It’s grown over many years, and I now find that I want to monitor the whole set-up in one place, because without monitoring everything I can’t visualize what’s happening, and without visualizing what’s happening, it’s difficult to understand what automations to execute or what maintenance I might need to do. It’s been a long-running vanity project, and I discovered InfluxDB during my journey. It’s partly because I found my “time to awesome” was so fast when implementing the software that I applied to join InfluxData!&lt;/p&gt;

&lt;p&gt;So, I want to visualize my home network from data stored in InfluxDB. I want everything to write directly into my local instance of InfluxDB OSS, but I also want to be able to write to remote &lt;a href="https://www.influxdata.com/blog/monitor-your-influxdb-open-source-instances-with-influxdb-cloud/"&gt;instances&lt;/a&gt;, such as InfluxDB Cloud. I also want this to be usable for larger use cases than mine. To do this, there are some restrictions:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;InfluxDB Cloud can only accept HTTP ingest. Any UDP messages (Proxmox writes UDP to an InfluxDB endpoint) will be dropped before they get through the Internet.&lt;/li&gt;
 	&lt;li&gt;Usernames and passwords might change, so I will need to edit every Telegraf configuration file on every machine on my LAN.&lt;/li&gt;
 	&lt;li&gt;Access tokens might change over time (especially as I migrate to InfluxDB Cloud v2), so I will need to edit every Telegraf configuration file on every machine on my LAN.&lt;/li&gt;
 	&lt;li&gt;I've had instances in corporate networks where I had to go through long security processes to open an outgoing TCP port from a host in a data centre. If I need to do this for many hosts in order to get Telegraf data sent to a remote InfluxDB, the elapsed time for security clearance would be correspondingly longer.&lt;/li&gt;
 	&lt;li&gt;I want to be efficient sending data to remote instances of InfluxDB. This means that I should look at concepts like batching my outputs. If I write to InfluxDB with a Telegraf Gateway, batching and associated settings can be configured in that collator, and those settings are used for all writes. If I write directly to InfluxDB from client libraries, each one might have a different mechanism for batching, so I'll need to configure it in multiple places.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If I can collate all my updates into one place, all the administration of the points above goes away.&lt;/p&gt;

&lt;p&gt;Therefore, implementing an interstitial instance of Telegraf — a Telegraf Gateway — is a good solution for these use cases. To create it, I’ll need to do some things:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li style="list-style-type: none;"&gt;
&lt;ol&gt;
 	&lt;li&gt;Install a container for Telegraf&lt;/li&gt;
 	&lt;li&gt;Enable &lt;a href="https://www.influxdata.com/blog/plugin-spotlight-exec-execd/"&gt;Telegraf inputs&lt;/a&gt; for UDP &amp;amp; HTTP&lt;/li&gt;
 	&lt;li&gt;Enable Telegraf outputs for wherever I'll be writing my data&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So, I need to create a configuration for my Telegraf gateway.
Telegraf reads default configurations from &lt;code class="language-ini"&gt;/etc/telegraf/telegraf.conf&lt;/code&gt; and &lt;code class="language-ini"&gt;/etc/telegraf/telegraf.d/.conf&lt;/code&gt;, so let’s create these.&lt;/p&gt;

&lt;p&gt;Firstly, here is my&lt;strong&gt; /etc/telegraf/telegraf.conf&lt;/strong&gt; for global settings&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[global_tags]]

[[agent]]
  interval = "10s"
  round_interval = true

  metric_batch_size = 1000   
  metric_buffer_limit = 10000

  collection_jitter = "3s"
  flush_interval = "10s"
  flush_jitter = "5s"

  precision = ""
   
  debug = false
  quiet = false
   
  logfile = "/var/log/telegraf/telegraf.log"   
  logfile_rotation_interval = "0d"
  logfile_rotation_max_size = "1MB"
  logfile_rotation_max_archives = 5

  hostname = ""&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now some specific config files for providing endpoints for Telegraf to act as an InfluxDB server:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/socket_listener.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.socket_listener]]
  service_address = "udp://:8089"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/influxdb_listener.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;# Influx HTTP write listener
[[inputs.influxdb_listener]]
  service_address = ":8086"

  read_timeout = "10s"
  write_timeout = "10s"

  max_body_size = "500MiB"
  max_line_size = "64KiB"

  database_tag = "bucket_name"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the use of &lt;code class="language-ini"&gt;database_tag = "bucket_name"&lt;/code&gt; in the config above. When I write directly to an InfluxDB HTTP endpoint using its URL, which I do from Node-Red, I select a database to write to. I don’t want to lose this information, so Telegraf stores it in a tag called bucket_name. Of course, I don’t want that sent as a tag to InfluxDB, because it’ll increase my &lt;a href="https://www.influxdata.com/blog/solving-runaway-series-cardinality-when-using-influxdb/"&gt;cardinality&lt;/a&gt; for no purpose, so the output configuration will need to remove it. Telegraf does this by the configuration line &lt;code class="language-ini"&gt;exclude_database_tag = true&lt;/code&gt;. Here’s the output configuration:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/output_influxdb.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;# Local InfluxDB
[[outputs.influxdb]]
  urls = ["http://ip_address_of_local_InfluxDB_server:8086"]
  database_tag = "bucket_name"
  exclude_database_tag = true
   
# SE Cloud
[[outputs.influxdb]]
  urls = ["https://FQDN_of_Influx_Cloud:8086"]
  database = "database_name_to_write_to"
  username = "my_username"
  password = "my_password"   
  timeout = "30s"

# Cloud 2 instance
[[outputs.influxdb_v2]]
  urls = ["https://FQDN_of_Influx_Cloud_2"]
  token = "The_Token_Generated_within_Influx_Cloud_2"   
  organization = "my_registered_email_address_on_Influx_Cloud_2"   
  bucket = "my_bucket_to_write_to"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At this point, this gives me a working Telegraf gateway. However, it also gives me an extra thing to monitor on my LAN, so capturing internal Telegraf metrics seems like the thing to do. As this is a LXC container, and I want to monitor all my containers in the same way, I should add my usual set of OS monitoring configurations. I shouldn’t enable SMART monitoring or temperature monitoring, as those should come from the underlying server on which I’m running the container. Additionally, if this was a Windows machine rather than a LXC container, I would want to replace “processes” and “system” with “win_processes” and “win_perf_counters”.
These are the defaults that I try and use with every server I include in my dashboards:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/cpu.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = false&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/disk.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[inputs.disk]]  
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

[[inputs.diskio]]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/internal.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.internal]]  
  collect_memstats = true&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/kernel.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.kernel]]  
  # no configuration&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/mem.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.mem]]  
  # no configuration&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/net.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.net]]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/swap.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.swap]]  
  # no configuration&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The final two sections are for capturing Linux metrics - see the equivalents mentioned above for Windows metrics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/processes.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ini"&gt;[[inputs.processes]]  
  # no configuration&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;/etc/telegraf/telegraf.d/system.conf&lt;/strong&gt;&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[inputs.system]]  
  ## Uncomment to remove deprecated metrics.  
  # fielddrop = ["uptime_format"]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now Telegraf will write to all three of my outputs, collating data from all three of the types of input I commonly use (Telegraf, HTTP custom endpoint, UDP).&lt;/p&gt;

&lt;p&gt;This is what my Telegraf gateway looks like, showing a system view:&lt;/p&gt;

&lt;p&gt;&lt;img class="size-full wp-image-239234 aligncenter" src="/images/legacy-uploads/telegraf-gateway.png" alt="Telegraf gateway" width="1600" height="879" /&gt;&lt;/p&gt;

&lt;p&gt;I’ll be running my Telegraf implementation like this for a while, to see if this meets my needs as-is, or if it needs extra configuration. If you deploy Telegraf like this, or use alternative ways to get your data through Telegraf into InfluxDB, let me know - I’m interested in Telegraf deployment patterns!&lt;/p&gt;
</description>
      <pubDate>Mon, 18 Nov 2019 09:01:11 -0700</pubDate>
      <link>https://www.influxdata.com/blog/using-a-telegraf-gateway/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/using-a-telegraf-gateway/</guid>
      <category>Use Cases</category>
      <category>Product</category>
      <category>Developer</category>
      <author>Rick Brown (InfluxData)</author>
    </item>
  </channel>
</rss>
