<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Noah Crowley</title>
    <description>Posts by Noah Crowley on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/noah-crowley/</link>
    <language>en-us</language>
    <lastBuildDate>Mon, 16 Sep 2019 07:22:42 -0700</lastBuildDate>
    <pubDate>Mon, 16 Sep 2019 07:22:42 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>Synthetic Monitoring with Telegraf</title>
      <description>&lt;p&gt;There are two main modes for collecting data about your systems and software: the first is by collecting data from within the application itself, often called white-box monitoring, and the second is by querying the system from the outside and collecting data about the response.&lt;/p&gt;

&lt;p&gt;Google’s SRE book defines white-box monitoring as “Monitoring based on metrics exposed by the internals of the system,” and black-box monitoring as “testing externally visible behavior as a user would see it.” Synthetic monitoring is an implementation of a black-box monitoring system which involves creating requests which simulate user activity.&lt;/p&gt;

&lt;p&gt;With synthetic monitoring, the aim is to expose any active issues that the user might be experiencing with a system, such as a website being inaccessible. Since it represents real user pain, this data is especially useful as an alerting signal for paging.&lt;/p&gt;

&lt;p&gt;This complements the white-box approach, which allows developers and operators to get insight into the internal functioning of the system, providing insight into issues that may be obscured to the user, such as failures that result in a successful retry, and providing invaluable information for debugging purposes.&lt;/p&gt;

&lt;p&gt;Telegraf can gather many white-box metrics using application-specific plugins like the ones for NGINX or MySQL, and you can instrument your applications using the InfluxDB client libraries, but we can also use Telegraf as a synthetic monitoring tool to monitor the status of our systems from the outside.&lt;/p&gt;

&lt;h2&gt;HTTP Response Input Plugin&lt;/h2&gt;

&lt;p&gt;Telegraf’s &lt;code class="language-markup"&gt;http_response&lt;/code&gt; input plugin checks the status of HTTP and HTTPS connections by polling an endpoint with a custom request, and then recording information about the result. The configuration for the plugin allows you to specify a list of URLs to query, define the request method, and send a custom request body or headers to simulate actions that might be taken by external users and systems. It also allows you to verify the behavior of those endpoints by verifying that the responses to these requests match certain predefined strings using regular expressions. These options give us a lot of flexibility in terms of how we monitor our applications.&lt;/p&gt;

&lt;p&gt;For each target server that is being polled, the plugin will send a measurement to InfluxDB with tags for the server (the target URL), request method, status code, and result, and fields with data about response times, whether the response string matched, the HTTP response code, and a numerical representation of the result called the result code.&lt;/p&gt;

&lt;p&gt;We can create a new block in our Telegraf configuring for each endpoint we want to monitor. Telegraf will collect data for each config block once per collection interval.&lt;/p&gt;

&lt;h2&gt;Monitoring influxdata.com&lt;/h2&gt;

&lt;p&gt;Let’s look at a quick example: we’ll create a simple synthetic monitoring check that will tell us whether influxdata.com is up or not. Because we want these monitoring checks to come from outside of the system, we’ll need to set up some kind of independent infrastructure, separate from the rest of our systems, for running Telegraf. This could mean running in a different Availability Zone on AWS, or using a different cloud provider altogether. Since I don’t actually need long-lived infrastructure for this example, I’ll configure Telegraf to run on my Mac, which is external to the influxdata.com infrastructure.&lt;/p&gt;

&lt;p&gt;I already have Telegraf installed using Homebrew, so the next step will be to create a new config file with our http_response settings. Here’s a snippet of what the &lt;code class="language-markup"&gt;inputs.http_response&lt;/code&gt; block would look like:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# HTTP/HTTPS request given an address a method and a timeout
[[inputs.http_response]]
  ## List of urls to query.
  urls = ["https://www.influxdata.com"]

[...]

  ## Optional substring or regex match in body of the response (case sensitive)
  response_string_match = "InfluxDB is the open source time series database"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This queries the InfluxData homepage and looks to match the phrase “InfluxDB is the open source […]”.&lt;/p&gt;

&lt;p&gt;One thing to note is that Telegraf’s collection interval is especially important for this plugin because it determines how often to make requests to the endpoint in question. Individual plugins can &lt;a href="https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#input-plugins"&gt;define their own collection interval&lt;/a&gt; by including a &lt;code class="language-markup"&gt;interval&lt;/code&gt; parameter in the appropriate config block. For the sake of example we’ll use the Telegraf defaults, but you’ll need to decide what an appropriate interval is for your own systems. You can find a complete configuration file in this &lt;a href="https://gist.github.com/noahcrowley/506c32ea79e43810f8607652e5f2e2a0"&gt;gist&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We can then launch a copy of Telegraf using the new config, and should see some output, as follows:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ telegraf --config synthetic-telegraf.conf --debug
2019-07-01T11:51:52Z I! Starting Telegraf 1.10.4
2019-07-01T11:51:52Z I! Loaded inputs: http_response
2019-07-01T11:51:52Z I! Loaded aggregators: 
2019-07-01T11:51:52Z I! Loaded processors: 
2019-07-01T11:51:52Z I! Loaded outputs: influxdb
2019-07-01T11:51:52Z I! Tags enabled: host=noah-mbp.local
2019-07-01T11:51:52Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:noah-mbp.local", Flush Interval:10s
2019-07-01T11:51:52Z D! [agent] Connecting outputs
2019-07-01T11:51:52Z D! [agent] Attempting connection to output: influxdb
2019-07-01T11:51:52Z D! [agent] Successfully connected to output: influxdb
2019-07-01T11:51:52Z D! [agent] Starting service inputs
2019-07-01T11:52:10Z D! [outputs.influxdb] wrote batch of 1 metrics in 9.118061ms
2019-07-01T11:52:10Z D! [outputs.influxdb] buffer fullness: 0 / 10000 metrics. 
2019-07-01T11:52:20Z D! [outputs.influxdb] wrote batch of 1 metrics in 7.672117ms
2019-07-01T11:52:20Z D! [outputs.influxdb] buffer fullness: 0 / 10000 metrics.&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Next steps&lt;/h2&gt;
&lt;p&gt;The http_reponse plugin provides a lot of flexibility in terms of creating monitoring requests which you can use to more accurately model how users and applications might interact with your site. For example, on &lt;a href="https://www.influxdata.com/"&gt;influxdata.com&lt;/a&gt; you might want to verify that your search page is working by submitting a POST request and verifying that the response includes text from the search result page, rather than just checking if the page loads. Because synthetic monitoring is intended to model the user experience, the specific number, frequency, and implementation of your checks will depend on the design and function of your product, but in general you’re looking for things like slow response times or high rates of errors - things that effect user happiness.&lt;/p&gt;

&lt;p&gt;Since black-box monitoring often exposes issues that are already impacting users, you’ll also want to create a sane alerting strategy based on this data. That might mean paging an engineer, or dropping a notification in Slack, at which point they will have to turn to data better suited for debugging: white box metrics and events.&lt;/p&gt;

&lt;p&gt;Black box monitoring isn’t a replacement for data captured from your application, but it provides end-to-end coverage that’s useful in the most catastrophic of scenarios. When used in conjunction with white box tools, it can give you that extra bit of confidence in the functioning of your software, making it a critical component of your monitoring system.&lt;/p&gt;
</description>
      <pubDate>Mon, 16 Sep 2019 07:22:42 -0700</pubDate>
      <link>https://www.influxdata.com/blog/synthetic-monitoring-with-telegraf/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/synthetic-monitoring-with-telegraf/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Reading Maxim 1-Wire Temperature Sensors</title>
      <description>&lt;p&gt;One of my favorite sensors is the Maxim DS18*20 series, a variety of inexpensive temperature sensors which communicate over a “single contact serial interface” called 1-Wire. I’ve been integrating them into a variety of projects for years now, and they’ve always been reliable, accurate, and extremely easy to use. That’s partly due to their use of a single contact for communication — valuable when you’re looking to save pins on an embedded computer or microcontroller — but also because of the built in &lt;code class="language-markup"&gt;w1_therm&lt;/code&gt; driver in the Linux kernel, which means they’ll work on any Linux machine with the appropriate physical interface.&lt;/p&gt;

&lt;p&gt;For the sake of example, we’ll use a Raspberry Pi with a DS18B20 connected to the GPIO pins. You can find a wiring diagram &lt;a href="http://www.circuitbasics.com/raspberry-pi-ds18b20-temperature-sensor-tutorial/" rel="nofollow"&gt;in this blog post&lt;/a&gt;. We’ll load the &lt;code class="language-markup"&gt;w1_therm&lt;/code&gt; kernel module as well as the &lt;code class="language-markup"&gt;w1_gpio&lt;/code&gt; module, which uses the GPIO API to provide a 1-Wire interface:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;modprobe w1_gpio
modprobe w1_therm&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With the kernel modules enabled, the sensor is now accessible through the sysfs interface as individual directories. We can use the &lt;code class="language-markup"&gt;ls&lt;/code&gt; command with some wildcards to find information about our sensors:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ ls -laH /sys/class/hwmon/hwmon*
total 0
drwxr-xr-x 3 root root    0 Apr 24 23:59 .
drwxr-xr-x 3 root root    0 Apr 24 23:59 ..
lrwxrwxrwx 1 root root    0 Apr 24 23:59 device -&amp;gt; ../../../28-000002e36be9
-r--r--r-- 1 root root 4096 Apr 24 23:59 name
drwxr-xr-x 2 root root    0 Apr 24 23:59 power
lrwxrwxrwx 1 root root    0 Apr 24 23:59 subsystem -&amp;gt; ../../../../../class/hwmon
-r--r--r-- 1 root root 4096 Apr 24 23:59 temp1_input
-rw-r--r-- 1 root root 4096 Apr 24 23:59 uevent&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Within this directory you’ll find a variety of files, including a symlink to the device itself, the sensor name, and a file called &lt;code class="language-markup"&gt;temp1_input&lt;/code&gt;, which you can read to get the temperature of the sensor in units of Celsius*1000:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ cat /sys/class/hwmon/hwmon0/temp1_input
27562&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In addition, you can access more info about the sensor by reading the &lt;code class="language-markup"&gt;/sys/class/hwmon/hwmon0/device/w1_slave file&lt;/code&gt;, which looks something like this:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ cat /sys/class/hwmon/hwmon0/device/w1_slave
bb 01 4b 46 7f ff 05 10 c6 : crc=c6 YES
bb 01 4b 46 7f ff 05 10 c6 t=27678&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This shows the output of the device in hex on the left, with the results of the CRC error checking and temperature reading on the right.&lt;/p&gt;
&lt;h2&gt;Telegraf's Temp plugin&lt;/h2&gt;
&lt;p&gt;Telegraf’s &lt;code class="language-markup"&gt;temp&lt;/code&gt; input plugin reads data about temperature sensors from the filesystem during each collection. You can &lt;a href="https://w2.influxdata.com/blog/running-the-tick-stack-on-a-raspberry-pi/"&gt;install Telegraf and InfluxDB on a Raspberry Pi&lt;/a&gt; using the official InfluxData repositories. Once installed, we can configure Telegraf by uncommenting the following section in &lt;code class="language-markup"&gt;/etc/telegraf/telegraf.conf&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# # Read metrics about temperature
[[inputs.temp]]
# # no configuration&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since there is no configuration beyond enabling the plugin, we can restart Telegraf and we should see data begin to appear in the &lt;code class="language-markup"&gt;temp&lt;/code&gt; measurement of the &lt;code class="language-markup"&gt;telegraf&lt;/code&gt; database (since we’re using the configuration defaults.)&lt;/p&gt;
&lt;h2&gt;Using multiple sensors&lt;/h2&gt;
&lt;p&gt;Unfortunately, there is one shortcoming with the current implementation of the temp plugin: it only supports a single sensor. This is because of an issue with the DS18*20 sensors and the library that Telegraf’s &lt;code class="language-markup"&gt;temp&lt;/code&gt; plugin uses to access the filesystem: &lt;a href="https://github.com/shirou/gopsutil"&gt;gopsutil&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When reading temperatures using gopsutil, &lt;a href="https://github.com/shirou/gopsutil/blob/db425313bfa86d78ce81b07d8898e0f9723e0ecd/host/host_linux.go#L677"&gt;the library generates a SensorKey&lt;/a&gt; using data from the filesystem, including a &lt;code class="language-markup"&gt;label&lt;/code&gt; file. This is what &lt;a href="https://github.com/torvalds/linux/blob/3bd6e94bec122a951d462c239b47954cf5f36e33/Documentation/hwmon/sysfs-interface#L400-L406"&gt;the kernel documentation&lt;/a&gt; has to say about those files:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;temp[1-*]_label	Suggested temperature channel label.
		Text string
		Should only be created if the driver has hints about what
		this temperature channel is being used for, and user-space
		doesn't. In all other cases, the label is provided by
		user-space.
		RO&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because the application of a DS18B20 and other similar sensors can vary, the driver is generic and does not have any information about what the temperature channel is being used for, so this file is not created. That means when Telegraf collects data from multiple sensors their tag values are identical, as they all have the same &lt;code class="language-markup"&gt;SensorKey&lt;/code&gt;. So even though we’re collecting data from each sensor, the data points have the same metadata and timestamp, and so will overwrite one another. We can verify this by running Telegraf using the &lt;code class="language-markup"&gt;--test&lt;/code&gt; argument, which will print the line protocol to the command line.&lt;/p&gt;
&lt;h2&gt;Multiple sensor workaround using Python&lt;/h2&gt;
&lt;p&gt;One way we can work around this issue is by using a Python script to read the data (you can find an &lt;a href="https://gist.githubusercontent.com/noahcrowley/e40187691338071f52a847bc5194144c/raw/d6f9bb5c4d1effa5ebefa488b87345bafbe2d816/read_multiple_ds18b20.py" rel="nofollow"&gt;example gist here&lt;/a&gt;), and Telegraf’s &lt;code class="language-markup"&gt;exec&lt;/code&gt; plugin to execute the script.&lt;/p&gt;

&lt;p&gt;Download the script and copy it to a more permanent location; for now, let’s drop the file in &lt;code class="language-markup"&gt;/usr/local/bin&lt;/code&gt;. Because we installed Telegraf using the official InfluxData repository, Telegraf runs as the &lt;code class="language-markup"&gt;telegraf&lt;/code&gt; user, which means we’ll also want to change the permissions on the script so it can be executed by Telegraf, as follows:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;sudo chown telegraf:telegraf /usr/local/bin/read_multiple_ds18b20.py
$ sudo chmod 755 /usr/local/bin/read_multiple_ds18b20.py&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we can configure Telegraf’s &lt;code class="language-markup"&gt;exec&lt;/code&gt; plugin to execute the script by enabling the plugin and adding the file to the &lt;code class="language-markup"&gt;commands&lt;/code&gt; parameter:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# # Read metrics from one or more commands that can output to stdout
[[inputs.exec]]
#   ## Commands array
  commands = [
    "/usr/local/bin/read_multiple_ds18b20.py"
  ]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The full configuration file is here, and includes the comments that describe the default values. Since multiple DS18B20s can share a single data line, connecting an additional device is fairly straightforward: it will share the connections to ground, power, and data that the first sensor uses. Restart telegraf and it should start collecting data from each device.&lt;/p&gt;
&lt;h2&gt;Future improvements&lt;/h2&gt;
&lt;p&gt;I have a few applications in mind that use multiple temperature sensors per device, so it would be nice to iterate on the built-in &lt;code class="language-markup"&gt;temp&lt;/code&gt; plugin if possible, rather than relying on our Python script workaround.&lt;/p&gt;

&lt;p&gt;One possibility would be to make a small change to the gopsutil library which would add an additional field to the &lt;code class="language-markup"&gt;SensorKey&lt;/code&gt; struct for the device name (unique for each DS18*20). Telegraf could then use that field to add an additional tag to the data and prevent the points from overwriting each other. I’m going to put together a Pull Request and get some feedback from the gopsutil maintainers. In the meantime, feel free to use my Python script, and reach out on our community site or to me directly at &lt;a href="mailto:noah@influxdata.com"&gt;noah@influxdata.com&lt;/a&gt; or on Twitter &lt;a href="https://twitter.com/noahcrowley" rel="nofollow"&gt;@noahcrowley&lt;/a&gt; if you have any issues!&lt;/p&gt;
</description>
      <pubDate>Thu, 05 Sep 2019 07:00:04 -0700</pubDate>
      <link>https://www.influxdata.com/blog/reading-maxim-1-wire-temperature-sensors/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/reading-maxim-1-wire-temperature-sensors/</guid>
      <category>Use Cases</category>
      <category>Product</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Telegraf Socket Listener Input Plugin</title>
      <description>&lt;p&gt;One of Telegraf’s biggest strengths is the large collection of plugins it offers that can be used to immediately to start collecting data from a variety of applications. This covers a lot of common infrastructure components like databases and web servers, but if you want to get data into Telegraf using your own scripts or applications, there are also a variety of more general-purpose input plugins that you can use. There’s a file plugin, which will read from or tail a file on disk, an exec plugin which will execute your own scripts or commands and parse their output, and plugins to listen for data via HTTP or poll external endpoints (http_listener_v2 and http).&lt;/p&gt;

&lt;p&gt;One of the plugins I end up using most often is the socket_listener plugin, which allows you to send data to Telegraf using UDP, TCP, or Unix sockets. The simplicity of InfluxDB’s line protocol and the ease with which you can write to a socket using most programming languages makes this a powerful tool for both quick prototyping and more long-term solutions.&lt;/p&gt;

&lt;p&gt;Let’s take a look at some examples of the plugin in action. We’ll use a host system running Ubuntu, with &lt;a href="https://docs.influxdata.com/telegraf/v1.11/introduction/installation/#installation" rel="nofollow"&gt;Telegraf&lt;/a&gt; and &lt;a href="https://docs.influxdata.com/influxdb/v1.7/introduction/installation/#installing-influxdb-oss" rel="nofollow"&gt;InfluxDB&lt;/a&gt; installed from the official InfluxData repository.&lt;/p&gt;
&lt;h2&gt;UDP: User Datagram Protocol&lt;/h2&gt;
&lt;p&gt;For this first example, let’s configure the socket_listener plugin to accept UDP packets. The UDP protocol is a connectionless, best-effort service: messages are sent to their recipient with no guarantee that they will be received. One benefit of this is that it means there is less processing overhead for UDP relative to something like TCP, which is more reliable. That makes UDP well-suited for things like interprocess communication or situations in which some loss of data is acceptable.&lt;/p&gt;

&lt;p&gt;In order to set up Telegraf to receive UDP messages, first configure this block in your &lt;code&gt;telegraf.conf&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;[[inputs.socket_listener]]
  service_address = "udp://:8094"
  data_format = "influx"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This configures Telegraf to listen for data on UDP port 8094 in InfluxDB line protocol format. A quick restart of Telegraf and it should be ready to receive data:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;sudo systemctl restart telegraf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we can start writing some data to Telegraf via UDP. To send the data, we’ll use two common command line utilities, echo and nc, or netcat. Enter the following commands into your terminal:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ echo "m1,tag1=tag_value value=1" | nc -u -4 -q localhost 8094
$ echo "m1,tag1=tag_value value=2" | nc -u -4 -q localhost 8094
$ echo "m1,tag1=tag_value value=3" | nc -u -4 -q localhost 8094&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The InfluxDB Line Protocol is a plain text format, which means we can use the echo command to print messages in that format directly to stdout, and use the | character to “pipe” that text into &lt;code&gt;nc&lt;/code&gt;, which will transmit the data over a network connection (in our case, on the same machine via the loopback interface). We provide several arguments to nc: -u, -4, and -q. The first argument tells nc to send data using UDP; the second argument says that we should use IPv4, and the third argument tells nc to quit once the data has been sent.&lt;/p&gt;

&lt;p&gt;Because UDP doesn’t have any guarantees about whether the messages will be delivered, let’s verify that the data has actually arrived in the database using the Influx CLI:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ influx
Connected to http://localhost:8086 version 1.7.4
InfluxDB shell version: unknown
Enter an InfluxQL query
&amp;gt; use database telegraf
&amp;gt; SELECT * FROM mymeasurement WHERE time &amp;gt; now()-5m
name: socketwriter
time                host           tag1       value
----                ----           ----       --------
1562602580414360000 noah-mbp.local tag_value  1
1562602581418350000 noah-mbp.local tag_value  2
1562602582420300000 noah-mbp.local tag_value  3&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Success! Our three datapoints have been written to the database.&lt;/p&gt;
&lt;h2&gt;Unix socket&lt;/h2&gt;
&lt;p&gt;While UDP and TCP are network protocols, the &lt;code class="language-markup"&gt;socket_listener&lt;/code&gt; plugin also has the ability to listen on a Unix socket, which provides a method for exchanging data between two processes on the same host via the kernel. Even when communicating on the same host, IP sockets like TCP and UDP will send data through the loopback networking interface. A Unix socket, on the other hand, can avoid this extra work and send data directly to the receiving socket buffer, which gives it a performance edge when sending data locally. You can read more about the differences between Unix sockets and network sockets in this mailing list post titled &lt;a href="https://lists.freebsd.org/pipermail/freebsd-performance/2005-February/001143.html" rel="nofollow"&gt;unix domain sockets vs. internet sockets&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This time, instead of using command line tools, we’ll write a small Python script that will send one-dimensional &lt;a href="https://en.wikipedia.org/wiki/Random_walk" rel="nofollow"&gt;random walk&lt;/a&gt; data over a Unix socket to Telegraf. First, we’ll configure Telegraf as follows (&lt;a href="https://gist.github.com/noahcrowley/d7f66112f16613bf27769c8d1a8354f5#file-telegraf-socket-conf"&gt;full config here&lt;/a&gt;):&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;[[inputs.socket_listener]]
  service_address = "unixgram:///tmp/telegraf.sock"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then we’ll run Telegraf with the new config:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ telegraf --config socket-telegraf.conf --debug&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can see that Telegraf has created the socket by listing the contents of the &lt;code class="language-markup"&gt;/tmp&lt;/code&gt; directory:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ ls /tmp
telegraf.sock&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Next we’ll create our Python script. The full script can be found &lt;a href="https://gist.github.com/noahcrowley/d7f66112f16613bf27769c8d1a8354f5#file-unix_socket_writer-py"&gt;here&lt;/a&gt;. Following the import statements and an interrupt handler which will close the socket when we use &lt;code class="language-markup"&gt;Ctrl+C&lt;/code&gt; to exit our script, we’ll create a socket object and connect to the socket Telegraf has opened.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# The file handler for the Telegraf process.
telegraf_socket = "/tmp/telegraf.sock"

# Connection to Telegraf, over a network socket.
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)

sock.connect(telegraf_socket)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then we create a loop that first sends the current data point to InfluxDB before updating the position variable for the next run through the loop, and sleeps for a second in order to rate limit the number of points we send:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;while True:
    message = "socketwriter position=%d\n" % x
    print(message)
    sock.send(message.encode('utf8'))
    x = x + random.randint(-1, 1)
    time.sleep(1)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With Telegraf running, let’s start our script:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ python3 unix_socket_writer.py 
socketwriter position=0

socketwriter position=0

socketwriter position=1

socketwriter position=0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once again, we can open up the InfluxDB CLI and verify that our data has been written:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ influx
Connected to http://localhost:8086 version 1.7.4
InfluxDB shell version: unknown
Enter an InfluxQL query
&amp;gt; use database telegraf
&amp;gt; SELECT * FROM socketwriter WHERE time &amp;gt; now()-1m
name: socketwriter
time                host           position
----                ----           --------
1562602580414360000 noah-mbp.local 0
1562602581418350000 noah-mbp.local 0
1562602582420300000 noah-mbp.local 1
1562602583422080000 noah-mbp.local 0&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Looks good!&lt;/p&gt;
&lt;h2&gt;Use it in your own projects!&lt;/h2&gt;
&lt;p&gt;Whether you’re using Unix sockets for their local performance or TCP sockets for their network robustness, Telegraf’s socket_listener plugin provides one of the easiest ways to get data from your scripts and applications and into Telegraf. And if that doesn’t work for you, check out some of the other general-purpose plugins that Telegraf has to offer — you’re sure to find something that suits your needs.&lt;/p&gt;

&lt;p&gt;If you have questions or need help with getting the socket_listener plugin set up, check out some of our community resources, like our public Slack or Discourse forums, or reach out to me directly on Twitter &lt;a href="https://twitter.com/noahcrowey" rel="nofollow"&gt;@noahcrowley&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Fri, 30 Aug 2019 07:00:00 -0700</pubDate>
      <link>https://www.influxdata.com/blog/telegraf-socket-listener-input-plugin/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/telegraf-socket-listener-input-plugin/</guid>
      <category>Use Cases</category>
      <category>Product</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Writing Data to InfluxDB with Python</title>
      <description>&lt;p&gt;One of the questions we see fairly often from Python developers who are using InfluxDB is how to improve the write performance of programs which use the InfluxDB client library. Usually they’re trying to import or transfer large amounts of data and want to make sure it can be inserted into the database quickly enough for their business needs. In this post, we’ll go over the common pitfalls that people encounter, as well as some performance best practices.&lt;/p&gt;
&lt;h2&gt;The script&lt;/h2&gt;
&lt;p&gt;Let’s look at an example of a Python script that writes data to InfluxDB. You can &lt;a href="https://gist.github.com/noahcrowley/941e87422cd6fc43b0e9e8f0d0877836/#file-write_test-py" rel="nofollow"&gt;find it here&lt;/a&gt;. The first part of the script (up until Line 56) is used for creating the data we’ll use to populate our measurements; there is a list of locations, a list of fruits, and a function which generates 1000 UUIDs.&lt;/p&gt;

&lt;p&gt;We create an array, and append the first value to it using our data as follows:&lt;/p&gt;
&lt;div class="highlight highlight-source-python"&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;data = []
data.append("{measurement},location={location},fruit={fruit},id={id} x={x},y={y},z={z}i {timestamp}"
            .format(measurement=measurement_name,
                    location=random.choice(location_tags),
                    fruit=random.choice(fruit_tags),
                    id=random.choice(id_tags),
                    x=round(random.random(),4),
                    y=round(random.random(),4),
                    z=random.randint(0,50),
                    timestamp=data_start_time))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This will append a string that looks like:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;m1,location=location,fruit=fruit,id=id x=10,y=1,z=42i 1562458785618&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At the beginning of the script we defined a variable which contains the number of points we’d like to write: in this case, 250,000. Once that data has been generated and loaded into the array, we can write it to the database as follows:&lt;/p&gt;
&lt;div class="highlight highlight-source-python"&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;client.write_points(data, database='python-throughput', time_precision='ms', batch_size=10000, protocol='line')&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2&gt;Measuring performance&lt;/h2&gt;
&lt;p&gt;Most Unix systems have some version of the &lt;a href="http://man7.org/linux/man-pages/man1/time.1.html" rel="nofollow"&gt;time&lt;/a&gt; command, which measures the amount of time it takes for a process to execute and then prints it to the command line.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ time echo "hello world"
hello world

real	0m0.000s
user	0m0.000s
sys	0m0.000s&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It’s a tool that many Linux users are familiar with, but the issue with measuring write performance this way is that you end up timing the entirety of the program. If you’re generating random data as we are, or parsing a CSV, this can be a meaningful chunk of time. In order to measure individual parts of the program, we’ll make use of the &lt;a href="https://docs.python.org/3/library/time.html" rel="nofollow"&gt;time module&lt;/a&gt;’s &lt;a href="https://docs.python.org/3/library/time.html#time.perf_counter" rel="nofollow"&gt;perf_counter()&lt;/a&gt; function.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;time.perf_counter()&lt;/code&gt; accesses the CPU's hardware performance counter and returns a value in fractional seconds. The performance counter is the highest resolution timer available for your system. It starts when the CPU is powered on, and runs continuously, which means that to measure the elapsed time of something you can get the time of the counter before and after an event occur and then subtract the start value from the end value.&lt;/pre&gt;
&lt;p&gt;Since we want to understand the performance of writing data, we use &lt;code class="language-markup"&gt;time.perf_counter()&lt;/code&gt; to time the &lt;code class="language-markup"&gt;write_points()&lt;/code&gt; function.&lt;/p&gt;
&lt;div class="highlight highlight-source-python"&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;client_write_start_time = time.perf_counter()

client.write_points(data, database='python-throughput', time_precision='ms', batch_size=10000, protocol='line')

client_write_end_time = time.perf_counter()

print("Client Library Write: {time}s".format(time=client_write_end_time - client_write_start_time))&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is perfect for our use case, but if your needs are different, Python also offers a module called &lt;a href="https://docs.python.org/3.7/library/timeit.html" rel="nofollow"&gt;timeit&lt;/a&gt;, which “provides a simple way to time small bits of Python code”. For larger, more complex applications, you might want to &lt;a href="https://docs.python.org/3/library/profile.html" rel="nofollow"&gt;look into using a profiler&lt;/a&gt;, which will give you detailed information about the entirety of your program’s execution.&lt;/p&gt;

&lt;p&gt;Let’s run the script! We’ll go ahead and use the time function to time the execution of the entire script so we can compare that to the execution of the &lt;code class="language-markup"&gt;write_points()&lt;/code&gt; function.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ time python3 write_test.py 
Client Library Write: 3.4734167899999995s

real	0m6.060s
user	0m2.387s
sys	0m0.114s&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I ran the script 5 times, dropping the database and starting fresh between each run: the average write time for 250,000 points was 3.81 seconds on my 2018 dual-core MacBook Pro (which has an admitedly fast SSD), while the average elapsed time for the entire script (including generating the data and the time required to initialize and exit the program) was 6.35 seconds.&lt;/p&gt;
&lt;h2&gt;Favor Line Protocol over JSON&lt;/h2&gt;
&lt;p&gt;The Python client library’s &lt;a href="https://influxdb-python.readthedocs.io/en/latest/api-documentation.html#influxdb.InfluxDBClient.write_points" rel="nofollow"&gt;write_points function&lt;/a&gt; can take data in either JSON or InfluxDB Line Protocol. &lt;a href="https://github.com/influxdata/influxdb-python/blob/d5d12499f3755199d5eedd8b363450f1cf4073bd/influxdb/client.py#L315"&gt;Looking at the code&lt;/a&gt;, though, we discover that any data provided in JSON format gets converted to Line Protocol anyway before being sent to InfluxDB:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;if protocol == 'json':
  data = make_lines(data, precision).encode('utf-8')&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code class="language-markup"&gt;make_lines()&lt;/code&gt; function &lt;a href="https://github.com/influxdata/influxdb-python/blob/d5d12499f3755199d5eedd8b363450f1cf4073bd/influxdb/line_protocol.py#L119"&gt;can be found here&lt;/a&gt;, and does the work of converting from JSON to Line Protocol.&lt;/p&gt;

&lt;p&gt;If we can avoid that work by providing data in Line Protocol to being with, we’ll save some time. Let’s run a few tests and see what the data looks like. You’ll find a &lt;a href="https://gist.githubusercontent.com/noahcrowley/941e87422cd6fc43b0e9e8f0d0877836/raw/4d835e418fdc3c199e8ae09f55eb93b1037f158a/write_test_json.py"&gt;JSON version of the script here&lt;/a&gt;. I ran it 5 times and averaged the results again. With the data in JSON instead of Line Protocol, it took an average of 7.65 seconds to insert all the data, about two times slower than using Line Protocol directly.&lt;/p&gt;
&lt;h2&gt;Optimization 2: Batch Your points&lt;/h2&gt;
&lt;p&gt;InfluxDB performs best when data is written to the database in batches. This helps minimize the network overhead of opening and closing HTTP connections by transmitting more data at once. The ideal batch size for InfluxDB is 5,000-10,000 points.&lt;/p&gt;

&lt;p&gt;By default, the &lt;code class="language-markup"&gt;write_points()&lt;/code&gt; function will transmit all of the points in the array passed to the function, but you can also provide a parameter which defines the batch size. In the example script, we generate 250,000 points up front, and then write those points in batches of 10,000:&lt;/p&gt;
&lt;div class="highlight highlight-source-python"&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;client.write_points(data, database='python-throughput', time_precision='ms', batch_size=10000, protocol='line')&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For comparison, I ran the script with a batch size of 50; with that setting, the write_points portion of our code averaged about 29 seconds! An order of magnitude higher!&lt;/p&gt;
&lt;h2&gt;Next steps: Measure more things!&lt;/h2&gt;
&lt;p&gt;If your program is still executing too slowly for you, it’s always worthwhile to examine other properties of the system where your code is running. How do your resources look? RAM, CPU, disk space? What is the throughput of your network connection, or disk I/O? There are a lot of external factors which can influence the execution of your code: be methodical about testing them and collecting data to rule out the cause.&lt;/p&gt;

&lt;p&gt;If you have more ideas for optimizing write performance with the Python library, we’d love to hear them! Open a pull request, comment on our community forums, or reach out directly to me at &lt;a href="mailto:noah@influxdata.com"&gt;noah@influxdata.com&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Thu, 22 Aug 2019 09:45:24 -0700</pubDate>
      <link>https://www.influxdata.com/blog/writing-data-to-influxdb-with-python/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/writing-data-to-influxdb-with-python/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Working with Irregular Time Series</title>
      <description>&lt;p&gt;&lt;img class="aligncenter wp-image-216895 size-medium" src="/images/legacy-uploads/influxdb-iwi-300x221.png" alt="" width="300" height="221" /&gt;&lt;/p&gt;

&lt;p&gt;One of the benefits of InfluxDB is the ability to store raw events, which might come in at varying intervals, as an irregular time series. However, irregular time series present some unique challenges, and in some cases common operations on the data simply will not work. Fortunately, InfluxDB allows you to convert an irregular time series to a regular one on the fly by calculating an aggregate of individual values for arbitrary windows of time. This gives you the best of both worlds when capturing events from your systems and working with that data.&lt;/p&gt;

&lt;p&gt;We can take a look at a few actual data points in order to get a better understanding of what considerations need to be made when working with irregular time series. For the sake of example, we’ll use five data points, and give them values of 10, 20, 30, 40, and 50.&lt;/p&gt;

&lt;p&gt;If this data if collected at regular intervals, then calculating the mean of the values will also give you the average power usage over time.&lt;/p&gt;

&lt;p&gt;If your data is collected at irregular intervals, however, then calculating the mean of the values will not give you the expected results.&lt;/p&gt;

&lt;p&gt;Adding those data points to InfluxDB and playing around with them will give us a better feel for what is going on. Using the Influx CLI, I inserted those five values into a measurement called &lt;code class="language-markup"&gt;m1&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select * from m1 where time &amp;gt; '2018-08-14T17:22:14Z' and time &amp;lt; '2018-08-14T17:23:20Z'
name: m1
time                         value
----                         -----
2018-08-14T17:22:14.159637Z  10
2018-08-14T17:22:16.3561521Z 20
2018-08-14T17:22:18.2251241Z 30
2018-08-14T17:22:20.18086Z   40
2018-08-14T17:23:19.8976057Z 50&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since I inserted the data manually, the timestamps for the values are not evenly spaced, which is just what we want for this example. The first four occur during the same minute, while the fifth occurs nearly a minute later. We can calculate the mean of these five values:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select mean(*) From m1
name: m1
time                 mean_value
----                 ----------
1970-01-01T00:00:00Z 30&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and we get a result of 30, with the timestamp value in the result being the beginning of the time window for which we’re calculating the mean.&lt;/p&gt;

&lt;p&gt;If this were a regular time series, then an average value of 30 would make sense, intuitively. Because our example is an irregular time series, though, the amount of time between measurements matters when calculating the final result. This becomes more clear when visualizing the values; here is what those points look like on a graph:&lt;/p&gt;

&lt;p&gt;&lt;img class="size-large wp-image-220191 aligncenter" src="/images/legacy-uploads/6451a49040d394204d183fe7eea11c151bf2e1fc-1024x259.png" alt="Our example data graphed using Chronograf." width="1024" height="259" /&gt;&lt;/p&gt;

&lt;p&gt;We can see that the majority of the time is spent between the value of 40 and the value of 50 (we’re doing a linear interpolation between those points to draw a graph). We can make a reasonable guess, then, that the mean over time is probably closer to 40 than it is to 30.&lt;/p&gt;

&lt;p&gt;Clearly, calculating the mean of all the values in an irregular series directly isn’t going to work, since that operation ignores the values’ distribution in time. We need to impose some kind of regularity on our data.&lt;/p&gt;

&lt;p&gt;To do this, we can break up the time range for our data into discreet units using InfluxQL’s &lt;code class="language-markup"&gt;GROUP BY&lt;/code&gt; clause, and then aggregate the values of the data within those windows. Not every interval will have a value, and those that do might have more than one value. We’ll need to make a decision, as users and operators of our systems, about how we want to handle those cases. As is often the case when working with data, human judgement and interpretation play a significant role.&lt;/p&gt;

&lt;p&gt;If we take small enough windows, and use the &lt;code class="language-markup"&gt;mean()&lt;/code&gt; function to calculate aggregates, we should get a fairly accurate representation of our time series. This is what our data looks like after we’ve grouped the points into ten-second intervals and calculated the mean for each group:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select mean(*) from m1 where time &amp;gt; '2018-08-14T17:22:14Z' and time &amp;lt; '2018-08-14T17:23:20Z' group by time(10s)
name: m1
time                 mean_value
----                 ----------
2018-08-14T17:22:10Z 20
2018-08-14T17:22:20Z 40
2018-08-14T17:22:30Z 
2018-08-14T17:22:40Z 
2018-08-14T17:22:50Z 
2018-08-14T17:23:00Z 
2018-08-14T17:23:10Z 50&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the 10-second period beginning 2018-08-14T17:22:10Z, we have three values, 10, 20, and 30, and the mean of those is 20. For the next window, we have a single value, and then we have a number of windows with no value before we see the final value of 50. As before, we’ll have to make a judgement call as to how we want to handle these empty windows.&lt;/p&gt;

&lt;p&gt;The &lt;code class="language-markup"&gt;fill()&lt;/code&gt; option of &lt;code class="language-markup"&gt;GROUP BY&lt;/code&gt; will allow us to fill in data for any of those empty windows. &lt;code class="language-markup"&gt;fill()&lt;/code&gt; can take the options &lt;code class="language-markup"&gt;null&lt;/code&gt;, &lt;code class="language-markup"&gt;previous&lt;/code&gt;, &lt;code class="language-markup"&gt;number&lt;/code&gt;, &lt;code class="language-markup"&gt;none&lt;/code&gt;, or &lt;code class="language-markup"&gt;linear&lt;/code&gt;. In our case, &lt;code class="language-markup"&gt;linear&lt;/code&gt; is the right choice, since we graphed the values using linear interpolation, but if this were real data some of the other options might be more appropriate.&lt;/p&gt;

&lt;p&gt;This is what our data looks like using &lt;code class="language-markup"&gt;fill(linear)&lt;/code&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select mean(*) from m1 where time &amp;gt; '2018-08-14T17:22:14Z' and time &amp;lt; '2018-08-14T17:23:20Z' group by time(10s) fill(linear)
name: m1
time                 mean_value
----                 ----------
2018-08-14T17:22:10Z 20
2018-08-14T17:22:20Z 40
2018-08-14T17:22:30Z 42
2018-08-14T17:22:40Z 44
2018-08-14T17:22:50Z 46
2018-08-14T17:23:00Z 48
2018-08-14T17:23:10Z 50&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can then calculate the mean of our new, regular time series, using &lt;a href="https://docs.influxdata.com/influxdb/v1.6/query_language/data_exploration/#subqueries" rel="nofollow"&gt;subqueries&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select mean(*) from (select mean(*) from m1 where time &amp;gt; '2018-08-14T17:22:14Z' and time &amp;lt; '2018-08-14T17:23:20Z' group by time(10s) fill(linear))
name: m1
time                 mean_mean_value
----                 ---------------
1970-01-01T00:00:00Z 41.42857142857143&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There’s another caveat, though: the window that we choose will have an impact on our final results. What if we use a 1s window instead of a 10s one?&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; select mean(*) from (select mean(*) from m1 where time &amp;gt; '2018-08-14T17:22:14Z' and time &amp;lt; '2018-08-14T17:23:20Z' group by time(1s) fill(linear))
name: m1
time                 mean_mean_value
----                 ---------------
1970-01-01T00:00:00Z 42.95454545454546&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We get a slightly different result! Working with irregular time series isn’t exact, and your approach will vary depending on the data in question. Different methods of aggregation, interval size, and interpolation method will be more appropriate than others.&lt;/p&gt;

&lt;p&gt;If the data in our examples above was some kind of environmental data, perhaps ambient temperature, and the irregularity of our series was due to unreliable data collection, then the approach we used might be appropriate.&lt;/p&gt;

&lt;p&gt;If the data was instead collected whenever there was a state change, perhaps we have a number of LEDs and we’re switching them on in blocks of ten, then the linear fill that we performed in the query no longer makes sense; instead, using &lt;code class="language-markup"&gt;fill(previous)&lt;/code&gt; would be more appropriate based on the behavior of the system that our data intends to model.&lt;/p&gt;

&lt;p&gt;Ultimately, this is the biggest challenge in working with irregular time series: you need to understand your data well enough that you can make educated decisions about how to work with that data.&lt;/p&gt;

&lt;p&gt;If you have questions about your irregular time series, our &lt;a href="https://community.influxdata.com" rel="nofollow"&gt;community site&lt;/a&gt; is a great place to get help from other users of the InfluxData Platform, or feel free to reach out to me directly on Twitter &lt;a href="https://twitter.com/noahcrowley" rel="nofollow"&gt;@noahcrowley&lt;/a&gt;!&lt;/p&gt;
</description>
      <pubDate>Fri, 26 Oct 2018 09:00:06 -0700</pubDate>
      <link>https://www.influxdata.com/blog/working-with-irregular-time-series/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/working-with-irregular-time-series/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Writing Logs Directly to InfluxDB</title>
      <description>&lt;p&gt;&lt;img class="aligncenter wp-image-216824 size-large" src="/images/legacy-uploads/Screen-Shot-2018-07-19-at-2.50.03-PM-1024x528.png" alt="" width="1024" height="528" /&gt;&lt;/p&gt;

&lt;p&gt;Back in June we published a blog on our &lt;a href="https://w2.influxdata.com/blog/influxdata-log-release/"&gt;“metrics-first” approach to log analysis&lt;/a&gt;; we had found that just over a quarter of our users were already using the InfluxData platform for storing logs and non-numerical events. We consider logs to be just another form of time series data, and so we wanted to give those users better tools for ingesting and viewing that data. At the end of the day, logs are extremely valuable for debugging and troubleshooting; they provide detailed insight into the goings-on of your systems, and let you explore problems in ways that predefined dashboards don’t allow.&lt;/p&gt;

&lt;p&gt;We released a plugin for Telegraf that allows you to ingest logs using the syslog protocol, which was based on work we were doing internally, and then back in July, we &lt;a href="https://w2.influxdata.com/blog/chronograf-1-6-released-introducing-log-viewer-and-additional-sharing-capabilities/"&gt;added log viewing functionality to Chronograf&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you’re interested in getting rsyslog and the Telegraf plugin up and running on macOS or Linux, you should check out the &lt;a href="https://w2.influxdata.com/blog/get-your-syslog-on/"&gt;Get Your Syslog On&lt;/a&gt; blog post. Once you start writing data, you’ll be able to explore it through the Log Viewer panel in Chronograf.&lt;/p&gt;

&lt;p&gt;Not everyone wants to run a syslog instance, however, and we’ve gotten a few questions here and there about how to write logs directly to InfluxDB so that they can be viewed in Chronograf, but without using syslog or the Telegraf plugin.&lt;/p&gt;

&lt;p&gt;Good news! This is totally possible!&lt;/p&gt;

&lt;p&gt;First, let’s dig a little deeper into the implementation so we can understand what’s really going on. The first thing to understand is that syslog is a protocol; it describes how messages should be formatted and transmitted. This is described in &lt;a href="https://tools.ietf.org/html/rfc5424" rel="nofollow"&gt;RFC5424 - The Syslog Protocol&lt;/a&gt;. Part of that specification includes details on how to use structured data in your logs, which we strongly encourage!&lt;/p&gt;

&lt;p&gt;When you’re using syslog and Telegraf, the latter is responsible for accepting messages in syslog format and converting them to line protocol to be written to InfluxDB. It inserts all syslog messages into a measurement called &lt;code class="language-markup"&gt;syslog&lt;/code&gt; which is what Chronograf looks for when it is populating the log viewer with data. Since the syslog protocol is well-defined, we know that we’ll always have certain fields and tags present in the data, which is how Chronograf knows how to format everything. The viewer has drop-down menus at the upper right for selecting the InfluxDB instance and database to use.&lt;/p&gt;

&lt;p&gt;Once data has been written to the database, the schema looks like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
 	&lt;li class="line-numbers"&gt;&lt;code class="language-markup"&gt;appname&lt;/code&gt;&lt;/li&gt;
 	&lt;li class="line-numbers"&gt;&lt;code class="language-markup"&gt;facility&lt;/code&gt;&lt;/li&gt;
 	&lt;li class="line-numbers"&gt;&lt;code class="language-markup"&gt;host&lt;/code&gt;&lt;/li&gt;
 	&lt;li class="line-numbers"&gt;&lt;code class="language-markup"&gt;hostname&lt;/code&gt;&lt;/li&gt;
 	&lt;li class="line-numbers"&gt;&lt;code class="language-markup"&gt;severity&lt;/code&gt; (needs to match the syslog &lt;a href="https://en.wikipedia.org/wiki/Syslog#Severity_level" rel="nofollow"&gt;severity level&lt;/a&gt; &lt;em&gt;keyword&lt;/em&gt; to display properly in Chronograf)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Fields: &lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;facility_code&lt;/code&gt; (integer)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;message&lt;/code&gt; (string)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;procid&lt;/code&gt; (string)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;severity_code&lt;/code&gt; (integer)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;timestamp&lt;/code&gt; (integer)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup"&gt;version&lt;/code&gt; (integer)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But there’s no reason why you can’t write data like this directly to the database! All you have to do is write points to InfluxDB that adhere to this schema, and land in the &lt;code class="language-markup"&gt;syslog&lt;/code&gt; database. Once they’re there, they’ll appear in the Log Viewer in Chronograf.&lt;/p&gt;

&lt;p&gt;Here are a few examples of logs in line protocol:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;syslog,appname=myapp,facility=console,host=myhost,hostname=myhost,severity=warning facility_code=14i,message="warning message here",severity_code=4i,procid="12345",timestamp=1534418426076077000i,version=1i&lt;/code&gt;&lt;/pre&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;syslog,appname=mysecondapp,facility=console,host=myhost,hostname=myhost,severity=crit facility_code=14i,message="critical message here",severity_code=2i,procid="12346",timestamp=1534418426076078000i,version=1i&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you want, you can open up the Influx CLI and write these points directly using the &lt;code class="language-markup"&gt;insert&lt;/code&gt; command; just be sure you update the timestamps to something recent so that you don’t have to go searching through history to find the data.&lt;/p&gt;

&lt;p&gt;Some of the fields in the schema above are specific to the syslog format, and help you identify the severity of the logs (are they informational, or critical errors), as well as the applications that wrote them. This is extremely helpful data for troubleshooting, so don’t leave it out! You can get more information on things like severity codes and facilities on the &lt;a href="https://en.wikipedia.org/wiki/Syslog" rel="nofollow"&gt;syslog Wikipedia page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using this approach, you can create logs entries from any application which can make an HTTP connection to InfluxDB. We’ve even got a few users already using this technique in the wild, so if it fits your use case, give it a try! One thing to remember is that InfluxDB works best when you batch up large numbers of points before sending them to the database (5,000-10,000), so if you’re sending lots of individual log lines you might overwhelm the database with HTTP requests.&lt;/p&gt;

&lt;p&gt;If you end up writing logs directly to InfluxDB, or if you have other success stories about integrating metrics and logs, we’d love to hear about it! Tweet us @InfluxDB on Twitter!&lt;/p&gt;
</description>
      <pubDate>Fri, 12 Oct 2018 11:35:58 -0700</pubDate>
      <link>https://www.influxdata.com/blog/writing-logs-directly-to-influxdb/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/writing-logs-directly-to-influxdb/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>OpenCensus Metrics and InfluxDB</title>
      <description>&lt;p&gt;&lt;a href="https://opencensus.io" rel="nofollow"&gt;OpenCensus&lt;/a&gt; is the latest in a series of projects which have emerged from Google as a result of their decades of experience running “planet-scale” systems; it is a collection of libraries, implemented in a number of languages, designed to help developers increase the observability of their systems. OpenCensus provides APIs for gathering metrics and trace data, adding tags, and then sending that data to a back-end for storage, as well as for the creation of zPages, HTTP endpoints which expose additional information about the application in question.&lt;/p&gt;

&lt;p&gt;Instrumentation is a key part of any observability strategy, and the OpenCensus project provides a standards-based approach to adding those features to your codebase. As developers and cloud providers throw their support behind OpenCensus, we wanted to ensure a seamless interaction with the rest of the TICK Stack.&lt;/p&gt;

&lt;p&gt;Fortunately, OpenCensus embraces a number of other open source technologies and standards which make that integration easy. The project provides a number of “exporters”, the component which sends data to the back-end, including one for metrics which uses the Prometheus exposition format and one for traces that uses Zipkin.&lt;/p&gt;

&lt;p&gt;The Prometheus exposition format is something that we’ve supported for some time now in various parts of the TICK Stack, including a Prometheus input plugin for our collection agent, Telegraf, which allows it to scrape metrics from Prometheus-style endpoints.&lt;/p&gt;

&lt;p&gt;As a result, we can easily collect data from any applications that have been instrumented with OpenCensus by making a few configuration changes to the Telegraf configuration file and enabling the Prometheus plugin.&lt;/p&gt;

&lt;p&gt;Let’s dive in! This post assumes that you have &lt;a href="https://docs.influxdata.com/telegraf/v1.7/introduction/" rel="nofollow"&gt;Telegraf&lt;/a&gt; and &lt;a href="https://docs.influxdata.com/influxdb/v1.6/introduction/" rel="nofollow"&gt;InfluxDB&lt;/a&gt; already installed. If you don’t, you can also check out the &lt;a href="https://github.com/influxdata/sandbox"&gt;InfluxData Sandbox&lt;/a&gt; to quickly get up and running with Docker and Docker Compose.&lt;/p&gt;
&lt;h2&gt;&lt;a id="user-content-instrumenting-go-code-with-opencensus" class="anchor" href="https://gist.github.com/noahcrowley/e98198f42b7a34207fe23e17f605710b#instrumenting-go-code-with-opencensus" aria-hidden="true"&gt;&lt;/a&gt;Instrumenting Go Code with OpenCensus&lt;/h2&gt;
&lt;p&gt;First, we need some code to instrument. Fortunately, we can make use of the example provided in the OpenCensus Quickstart guides. The libraries for the Go programming language are probably the farthest along, so we’ll use Go for this blog post.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://opencensus.io/quickstart/go/metrics/" rel="nofollow"&gt;quickstart tutorial&lt;/a&gt; involves building a simple REPL which capitalizes any strings provided to it as input, while collecting metrics about the application. We’ll use this example pretty much line-for-line, with one exception—we’ll replace the the StackDriver exporter with the Prometheus one.&lt;/p&gt;

&lt;p&gt;Working through the tutorial, the first thing we do is create a simple REPL, followed by adding instrumentation code, including metrics and tags, and then recording those metrics. We create a few views and then set up the exporter. You can scroll down to the last snippet of code and then click the “All” tab to grab the full application.&lt;/p&gt;

&lt;p&gt;We’ll need to make a few changes to use the Prometheus exporter; fortunately, OpenCensus provides us some example code for that as part of the &lt;a href="https://opencensus.io/core-concepts/exporters/" rel="nofollow"&gt;documentation on exporters&lt;/a&gt;. We’ll do a bit of code surgery; replacing a few import statements and updating the initialization and registration of the exporter. I added the existing code to a GitHub Gist, then updated it so you can &lt;a href="https://gist.github.com/noahcrowley/dd25ab45e233adc732da51f5c988e3aa/revisions"&gt;view the diff&lt;/a&gt; if you’re interested.&lt;/p&gt;

&lt;p&gt;Save the modified code and we can run the REPL:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;go run repl.go&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enter a few lines into the REPL and then visit &lt;a href="http://localhost:9091" rel="nofollow"&gt;http://localhost:9091&lt;/a&gt;; you should see some metrics exposed in Prometheus format. As you enter new lines into the REPL, those metrics should change.&lt;/p&gt;
&lt;h2&gt;&lt;a id="user-content-collecting-opencensus-metrics" class="anchor" href="https://gist.github.com/noahcrowley/e98198f42b7a34207fe23e17f605710b#collecting-opencensus-metrics" aria-hidden="true"&gt;&lt;/a&gt;Collecting OpenCensus Metrics&lt;/h2&gt;
&lt;p&gt;As I mentioned earlier, Telegraf, the InfluxData collection agent, has built-in support for both scraping and exposing metrics in the Prometheus exposition format. All it takes to enable Prometheus metrics collection is to edit a few lines in the configuration file.&lt;/p&gt;

&lt;p&gt;If you don’t already have a config file, you can generate one with the following command:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;telegraf --sample-config --input-filter prometheus --aggregator-filter --output-filter influxdb&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;code class="language-markup"&gt;--sample-config&lt;/code&gt; argument creates a new config file, while the various &lt;code class="language-markup"&gt;filter&lt;/code&gt; options filter the configuration sections which will be added to the config file. To enable the collection of Prometheus metrics, we’re using &lt;code class="language-markup"&gt;--input-filter prometheus&lt;/code&gt;, which results in an &lt;code class="language-markup"&gt;[[inputs.prometheus]]&lt;/code&gt; section being added to our config.&lt;/p&gt;

&lt;p&gt;We need to edit that section and point it to the URL our local REPL is using as its metrics endpoint, &lt;code class="language-markup"&gt;http://localhost:9091/metrics&lt;/code&gt;. We can use all of the other defaults, as follows:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;[[inputs.prometheus]]
  ## An array of urls to scrape metrics from.
  urls = ["http://localhost:9091/metrics"]

  ## An array of Kubernetes services to scrape metrics from.
  # kubernetes_services = ["http://my-service-dns.my-namespace:9100/metrics"]

  ## Use bearer token for authorization
  # bearer_token = /path/to/bearer/token

  ## Specify timeout duration for slower prometheus clients (default is 3s)
  # response_timeout = "3s"

  ## Optional TLS Config
  # tls_ca = /path/to/cafile
  # tls_cert = /path/to/certfile
  # tls_key = /path/to/keyfile
  ## Use TLS but skip chain &amp;amp; host verification
  # insecure_skip_verify = false&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because we’re using all of the defaults at this point, Telegraf is writing to a &lt;code&gt;telegraf&lt;/code&gt; database, collecting data every 10 seconds and flushing it to the outputs at the same interval. We’re also running InfluxDB on the same machine, so the default InfluxDB output configuration should be sufficient.&lt;/p&gt;

&lt;p&gt;Start Telegraf using the config file:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;telegraf --config telegraf.conf&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see metrics showing up in the &lt;code class="language-markup"&gt;telegraf&lt;/code&gt; database after the first collection interval has elapsed! Let’s verify this using the &lt;code class="language-markup"&gt;influx&lt;/code&gt; command-line tool to execute a query.&lt;/p&gt;

&lt;p&gt;Launch the CLI and use the &lt;code class="language-markup"&gt;telegraf&lt;/code&gt; database:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ influx
Connected to http://localhost:8086 version 1.6.1
InfluxDB shell version: v1.6.1
&amp;gt; USE telegraf
Using database telegraf
&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, run a query to get the last 5m of data for the &lt;code class="language-markup"&gt;demo_demo_latency&lt;/code&gt; measurement:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;&amp;gt; SELECT * FROM demo_demo_latency WHERE time &amp;gt; now()-5m&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see a number of points, depending on how long your application has been running.&lt;/p&gt;
&lt;h2&gt;&lt;a id="user-content-next-steps" class="anchor" href="https://gist.github.com/noahcrowley/e98198f42b7a34207fe23e17f605710b#next-steps" aria-hidden="true"&gt;&lt;/a&gt;Next Steps&lt;/h2&gt;
&lt;p&gt;As you can see, it’s extremely easy to collect metrics from an OpenCensus-instrumented application using Telegraf and the OpenCensus Prometheus exporter. If you already have an application that’s been instrumented with OpenCensus, then you might want to consider &lt;a href="https://docs.influxdata.com/chronograf/v1.6/introduction/installation/" rel="nofollow"&gt;installing Chronograf&lt;/a&gt; and &lt;a href="https://docs.influxdata.com/chronograf/v1.6/guides/create-a-dashboard/" rel="nofollow"&gt;adding a few dashboards&lt;/a&gt;, or &lt;a href="https://docs.influxdata.com/kapacitor/v1.5/introduction/installation/" rel="nofollow"&gt;setting up Kapacitor&lt;/a&gt; and &lt;a href="https://docs.influxdata.com/kapacitor/v1.5/working/alerts/" rel="nofollow"&gt;configuring alerts&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Thu, 06 Sep 2018 09:00:41 -0700</pubDate>
      <link>https://www.influxdata.com/blog/opencensus-metrics-and-influxdb/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/opencensus-metrics-and-influxdb/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>OpenMetrics to Join the CNCF</title>
      <description>&lt;p&gt;&lt;img class="aligncenter wp-image-218295 size-large" src="/images/legacy-uploads/openmetrics-logo-1024x572.png" alt="OpenMetrics Logo" width="1024" height="572" /&gt;&lt;/p&gt;

&lt;p&gt;Last Friday, the &lt;a href="https://cncf.io" rel="nofollow"&gt;Cloud Native Computing Foundation&lt;/a&gt; announced the acceptance of &lt;a href="https://openmetrics.io" rel="nofollow"&gt;OpenMetrics&lt;/a&gt;, an open source metrics exposition format and evolution of the &lt;a href="https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md"&gt;Prometheus exposition format&lt;/a&gt;, into the CNCF Sandbox.&lt;/p&gt;

&lt;p&gt;The CNCF is an “open source software foundation dedicated to making cloud native computing universal and sustainable”; they provide a home and support for a variety of projects that are used for building “cloud-native” software—scalable, durable distributed systems that provide functionality over an internet connection. The first project to “graduate” from the CNCF was Kubernetes; OpenMetrics enters the foundation as a “sandbox” project, their classification for early-stage efforts.&lt;/p&gt;

&lt;p&gt;It’s great to see this kind of effort getting support from the broader community. The &lt;a href="https://www.influxdata.com/glossary/prometheus-metrics/"&gt;Prometheus metrics&lt;/a&gt; exposition format has become the de facto format for pull-based metrics, so it’s nice to see the standard broken out into its own project, opening the door for additional collaboration and further integration into the broader vendor ecosystem.&lt;/p&gt;

&lt;p&gt;The Prometheus exposition format is something we’ve supported in the TICK Stack for some time now, both in &lt;a href="https://w2.influxdata.com/time-series-platform/telegraf/"&gt;Telegraf&lt;/a&gt;, our collection agent, and in &lt;a href="https://w2.influxdata.com/time-series-platform/kapacitor/"&gt;Kapacitor&lt;/a&gt;, our stream and batch processing engine.&lt;/p&gt;

&lt;p&gt;Telegraf has the ability to both scrape and expose metrics in the Prometheus format. Here’s an example of some of Telegraf’s system metrics being exposed via the &lt;code class="language-markup"&gt;/metrics&lt;/code&gt; endpoint:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# HELP system_load1 Telegraf collected metric
# TYPE system_load1 gauge
system_load1{host="demo-host.local"} 2.61
# HELP system_load15 Telegraf collected metric
# TYPE system_load15 gauge
system_load15{host="demo-host.local"} 2.19
# HELP system_load5 Telegraf collected metric
# TYPE system_load5 gauge
system_load5{host="demo-host.local"} 2.23
# HELP system_n_cpus Telegraf collected metric
# TYPE system_n_cpus gauge
system_n_cpus{host="demo-host.local"} 4
# HELP system_n_users Telegraf collected metric
# TYPE system_n_users gauge
system_n_users{host="demo-host.local"} 5
# HELP system_uptime Telegraf collected metric
# TYPE system_uptime counter
system_uptime{host="demo-host.local"} 230446&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Metrics exposed in the Prometheus format can be scraped by enabling the &lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/prometheus/"&gt;Prometheus Input Plugin&lt;/a&gt;, by making sure the following section is present in your config:&lt;/p&gt;
&lt;div class="highlight highlight-source-toml"&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;# Read metrics from one or many prometheus clients
[[inputs.prometheus]]
  ## An array of urls to scrape metrics from.
  urls = [
    "http://localhost:9100/metrics",
    "http://remotehost.com:9100/metrics",
    "http://192.168.1.199:9100/metrics",
  ]

  ## An array of Kubernetes services to scrape metrics from.
  # kubernetes_services = ["http://my-service-dns.my-namespace:9100/metrics"]

  ## Use bearer token for authorization
  # bearer_token = /path/to/bearer/token

  ## Specify timeout duration for slower prometheus clients (default is 3s)
  # response_timeout = "3s"

  ## Optional TLS Config
  # tls_ca = /path/to/cafile
  # tls_cert = /path/to/certfile
  # tls_key = /path/to/keyfile
  ## Use TLS but skip chain &amp;amp; host verification
  # insecure_skip_verify = false&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you need to generate a new Telegraf config for use with Prometheus, you can use the following command, adding in any additional plugins you’d like to enable, such as &lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/system"&gt;the system plugin&lt;/a&gt;, separated by a &lt;code class="language-markup"&gt;:&lt;/code&gt;, as follows:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ telegraf --sample-config --input-filter prometheus:system --output-filter prometheus_client&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Kapacitor can also scrape Prometheus-style endpoints. You can find more information about this functionality in the documentation for &lt;a href="https://docs.influxdata.com/kapacitor/v1.5/working/scraping-and-discovery/#main-nav" rel="nofollow"&gt;Kapacitor Scraping and Discovery&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Moving forward, InfluxData will support the OpenMetrics format as a first-class citizen and work with other open source companies and organizations to move the standard forward. So what can we expect from the future?&lt;/p&gt;

&lt;p&gt;The best way to keep up to date on the project’s progress, and to contribute to the discussion, is via the &lt;a href="https://github.com/OpenObservability/OpenMetrics"&gt;OpenMetrics GitHub page&lt;/a&gt;, and specifically, the &lt;a href="https://github.com/OpenObservability/OpenMetrics/issues"&gt;GitHub Issues&lt;/a&gt;. There are a number of interesting discussions going on at the moment, such as &lt;a href="https://github.com/OpenObservability/OpenMetrics/issues/34"&gt;this discussion about how to version metrics&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://www.cncf.io/blog/2018/08/10/cncf-to-host-openmetrics-in-the-sandbox/" rel="nofollow"&gt;read the full announcement here&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Tue, 21 Aug 2018 12:00:32 -0700</pubDate>
      <link>https://www.influxdata.com/blog/openmetrics-joins-cncf/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/openmetrics-joins-cncf/</guid>
      <category>Use Cases</category>
      <category>Product</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
    <item>
      <title>Running the TICK Stack on a Raspberry Pi</title>
      <description>&lt;p&gt;&lt;img class="wp-image-216296 size-large" src="/images/legacy-uploads/Noah-Crowley-IMG_0159-1024x768.jpg" alt="Two Raspberry Pis and some InfluxData Stickers" width="1024" height="768" /&gt;&amp;lt;figcaption&amp;gt; The Raspberry Pi is a great platform for the TICK Stack!&amp;lt;/figcaption&amp;gt;&lt;/p&gt;

&lt;p&gt;Since its introduction in 2013, the Raspberry Pi platform has grown by leaps and bounds, gaining popularity and showing up in projects all over world, from quick hacks to fully commercialized products. It’s an inexpensive, low power, open-source, single-board computer with a variety of interfaces for connecting with sensors and actuators that can be used to interact with the physical world.&lt;/p&gt;

&lt;p&gt;It’s also a solid choice when you need an always-on device for collecting data, and it’s powerful enough to run the complete TICK Stack. In fact, one of the most popular posts on our community site is about running the TICK Stack on a Raspberry Pi, so we wanted to provide some update instructions for installing and things to consider while operating the stack.&lt;/p&gt;
&lt;h2&gt;The Hardware&lt;/h2&gt;
&lt;h3&gt;Your Choice of Pi&lt;/h3&gt;
&lt;p&gt;The first thing you’ll need to do is decide which Pi you’re going to use. The Raspberry Pi platform has gone through a few iterations since it was first released in 2013:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Cores&lt;/th&gt;
&lt;th&gt;Clock Speed&lt;/th&gt;
&lt;th&gt;RAM&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Zero&lt;/td&gt;
&lt;td&gt;1, 32-bit&lt;/td&gt;
&lt;td&gt;1000 MHz&lt;/td&gt;
&lt;td&gt;512 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A/B/+&lt;/td&gt;
&lt;td&gt;1, 32-bit&lt;/td&gt;
&lt;td&gt;500 MHz&lt;/td&gt;
&lt;td&gt;256 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2B&lt;/td&gt;
&lt;td&gt;4, 32-bit&lt;/td&gt;
&lt;td&gt;900 MHz&lt;/td&gt;
&lt;td&gt;1024 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3B&lt;/td&gt;
&lt;td&gt;4, 64-bit&lt;/td&gt;
&lt;td&gt;1200 MHz&lt;/td&gt;
&lt;td&gt;1024 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3B+&lt;/td&gt;
&lt;td&gt;4, 64-bit&lt;/td&gt;
&lt;td&gt;1400 MHz&lt;/td&gt;
&lt;td&gt;1024 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;There have been some significant architectural improvements over the years, and your best bet is to go with one of the model 3 boards, with quad-core, 64-bit CPUs for the database itself, although I’ve tested running the complete TICK Stack on the model 2 B, 3 B, and 3 B+. In addition, the single-core Zero makes a great platform for collecting sensor data with Telegraf.&lt;/p&gt;
&lt;h3&gt;Storage&lt;/h3&gt;
&lt;p&gt;The storage system on the Raspberry Pi, which uses an SD or microSD card, is the slowest by far relative to the systems on a laptop or desktop computer, so it’s important to keep in mind storage performance when you’re considering a Raspberry Pi for your application. Which SD card you choose will have a major impact on the performance of your Raspberry Pi, especially if you’re planning on running a database like InfluxDB.&lt;/p&gt;

&lt;p&gt;Get at least a Class 10 Card—the faster, the better. But understand that even with the fastest SD card, performance won’t come close to what you would get with an SSD, and this can often be the bottleneck for your applications.&lt;/p&gt;

&lt;p&gt;Some manufacturers are also releasing “High Endurance” SD cards; I haven’t had a chance to do much research about them, but if you plan on writing large volumes of data, it might be worth investigating.&lt;/p&gt;

&lt;p&gt;The Raspberry Pi 3 B and B+ also have the ability to &lt;a href="https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md"&gt;enable a USB boot mode&lt;/a&gt;, although this is a permanent change for your device. While you’ll still be constrained by the speed of a USB 2.0 port, this would enable you to run a large-capacity SSD with better speed and performance.&lt;/p&gt;
&lt;h2&gt;Installation&lt;/h2&gt;
&lt;p&gt;The most common way to use a Pi is with the &lt;a href="https://www.raspbian.org/"&gt;Raspbian&lt;/a&gt; operating system provided by the Raspberry Pi foundation, so that’s what we’ll be using in this blog post. Raspbian is based off the Debian distribution of Linux, with some modifications and utilities like &lt;a href="https://www.raspberrypi.org/documentation/configuration/raspi-config.md"&gt;raspi-config&lt;/a&gt; that contain functionality specific to the hardware. The latest version of Raspbian is April release based on Debian Stretch.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://www.raspberrypi.org/software/" target="_blank" rel="noopener noreferrer"&gt;download Raspbian&lt;/a&gt; and find &lt;a href="https://www.raspberrypi.org/documentation/installation/installing-images/README.md"&gt;installation instructions&lt;/a&gt; on the Raspberry Pi foundation’s website.&lt;/p&gt;
&lt;h3&gt;Recommended: Install from the Official InfluxData Repository&lt;/h3&gt;
&lt;p&gt;The easiest way to install the TICK Stack is to set up the InfluxData package repository (repo) and use your platform’s package manager, which on Raspbian is &lt;code class="language-markup"&gt;apt&lt;/code&gt;. Packages contain the application binaries themselves, as well as some information about where and how to install and configure the application on your system. That means you can get everything up and running with just a few commands, and InfluxData regularly publishes the latest versions of the TICK Stack to its repository, so applying updates is easy as well.&lt;/p&gt;

&lt;p&gt;The first step is to set up the InfluxData repo. You’ll need to identify which version of Raspbian you’re running, which you can do by taking a look at the &lt;code class="language-markup"&gt;/etc/os-release&lt;/code&gt; file. Run the following command:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ cat /etc/os-releases
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We need the version codename, which you can find in the &lt;code class="language-markup"&gt;VERSION&lt;/code&gt; field, in parentheses. For the version I’m running, 9, the code name is &lt;code class="language-markup"&gt;stretch&lt;/code&gt;. We’ll use that when we set up our repo so that we can get the correct versions for our OS.&lt;/p&gt;

&lt;p&gt;Next, add the repo’s GPG key and add the repo itself:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then add the repository:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;$ echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, run &lt;code class="language-markup"&gt;sudo apt-get&lt;/code&gt; update to refresh the package list with data from the new repository, and install the TICK Stack using &lt;code class="language-markup"&gt;sudo apt-get install telegraf influxdb chronograf kapacitor&lt;/code&gt;. If you want to only install some components of the stack, you can exclude the applications you don’t want from that command.&lt;/p&gt;

&lt;p&gt;It’s also possible to download packages and install them yourself, without setting up the InfluxData repository. You probably don’t have a good reason for doing this, but for those who do, head over to our &lt;a href="https://w2.influxdata.com/downloads"&gt;downloads page&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Docker&lt;/h3&gt;
&lt;p&gt;Docker is another great option for running the TICK Stack on a Raspberry Pi, and is what I use at home. Docker is an OS-level virtualization technology, which means that it isolates various applications by making it appear as though they each have their own Linux kernel and environment to run in. This provides isolation for your applications, while the Docker runtime provides easy-to-use tooling for creating and managing containers.&lt;/p&gt;

&lt;p&gt;The recommended method for installing Docker on Raspbian is using the &lt;a href="https://docs.docker.com/install/linux/docker-ce/debian/#install-using-the-convenience-script"&gt;convenience script&lt;/a&gt;; you’ll also probably want to &lt;a href="https://docs.docker.com/install/linux/docker-ce/debian/#install-docker-compose-for-raspbian"&gt;install docker compose&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can refer to my &lt;a href="https://w2.influxdata.com/blog/tips-for-running-the-tick-stack-using-docker/"&gt;Docker blog post&lt;/a&gt; from last week for more details about running TICK in docker containers, and I’ve written a simple &lt;a href="https://gist.github.com/noahcrowley/6c8668683c0b0d7b8ecbe624f2a6333e"&gt;Docker Compose file&lt;/a&gt; to help you get started.&lt;/p&gt;
&lt;h3&gt;Manual Options: Binaries and Building from Source&lt;/h3&gt;
&lt;p&gt;A few other options exist which provide additional level of manual control over how you want to build and install your applications. You can download a Linux binary from &lt;a href="https://w2.influxdata.com/downloads"&gt;influxdata.com/downloads&lt;/a&gt;, or you can visit the respective Git repositories (&lt;a href="http://github.com/influxdata/telegraf/"&gt;Telegraf&lt;/a&gt;, &lt;a href="https://github.com/influxdata/influxdb/"&gt;InfluxDB&lt;/a&gt;, &lt;a href="https://github.com/influxdata/chronograf/"&gt;Chronograf&lt;/a&gt;, and &lt;a href="https://github.com/influxdata/kapacitor/"&gt;Kapacitor&lt;/a&gt;), check out the code, and build the applications yourself.&lt;/p&gt;
&lt;h2&gt;Other Considerations&lt;/h2&gt;
&lt;p&gt;Since the Pi is a relatively constrained computing environment, you might have to make some tradeoffs in terms of how much software you can run and how much data you can process and store.&lt;/p&gt;

&lt;p&gt;One thing to consider is that you don’t have to run Chronograf on the Pi; you can run a local copy on your primary computer, and set it up to talk to the InfluxDB instance on your Raspberry Pi over the network. This is the setup I’m currently running at home, and I find that it gives a nice performance bump over running everything on the Pi.&lt;/p&gt;

&lt;p&gt;Another thing to keep in mind is the amount of storage space you have on your SD card. While InfluxDB is quite efficient at storing data, depending on the size of your card, the other software you have installed, and how much data you’re writing, it is possible to run out of space. You should definitely set up some kind of monitoring and alerting so that you can be informed when you run out of space. Telegraf’s &lt;a href="https://github.com/influxdata/telegraf/blob/master/plugins/inputs/system/README.md"&gt;disk plugin&lt;/a&gt; and Kapacitor’s &lt;a href="https://docs.influxdata.com/kapacitor/v1.5/working/alerts/"&gt;alerts functionality&lt;/a&gt; would be a good fit for this!&lt;/p&gt;

&lt;p&gt;You also might not need to keep your data around forever; a few weeks or months might be good enough for your use case. We often see users taking advantage of into InfluxData’s &lt;a href="https://docs.influxdata.com/influxdb/v1.5/guides/downsampling_and_retention/"&gt;downsampling and retention policy&lt;/a&gt; functionality to reduce the resolution of their data and automatically delete it when it has reached a certain age. For more information on why you might want to do this, check out our recent training webinar, &lt;a href="https://w2.influxdata.com/training/7-downsampling-data/"&gt;Downsampling Your Data&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;That's It!&lt;/h2&gt;
&lt;p&gt;Hopefully this post got you up and running, but if you have any questions or comments please feel free to reach out to me directly on Twitter &lt;a href="https://twitter.com/noahcrowley"&gt;@noahcrowley&lt;/a&gt; or feel free to post your comments on our community site at &lt;a href="https://community.influxdata.com/"&gt;community.influxdata.com&lt;/a&gt;. And if you build something great with Influx, don’t hesitate to &lt;a href="https://w2.influxdata.com/get-hoodie/"&gt;let us know&lt;/a&gt;, there might be a hoodie in it for you!&lt;/p&gt;
</description>
      <pubDate>Tue, 03 Jul 2018 09:00:17 -0700</pubDate>
      <link>https://www.influxdata.com/blog/running-the-tick-stack-on-a-raspberry-pi/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/running-the-tick-stack-on-a-raspberry-pi/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Noah Crowley (InfluxData)</author>
    </item>
  </channel>
</rss>
