<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>InfluxData Blog - Adam Silverman</title>
    <description>Posts by Adam Silverman on the InfluxData Blog</description>
    <link>https://www.influxdata.com/blog/author/adam-silverman/</link>
    <language>en-us</language>
    <lastBuildDate>Thu, 02 Dec 2021 08:49:41 -0700</lastBuildDate>
    <pubDate>Thu, 02 Dec 2021 08:49:41 -0700</pubDate>
    <ttl>1800</ttl>
    <item>
      <title>TL;DR InfluxDB Tech Tips – Visualizing Uptime with Flux deadman() Function in InfluxDB Dashboards</title>
      <description>&lt;p&gt;A common DevOps use case involves alerting when hosts stop reporting metrics, aka a deadman alert. This can be done using the &lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman() Flux function&lt;/a&gt;. One can easily create a deadman (or threshold) check in the &lt;a href="https://docs.influxdata.com/influxdb/cloud/monitor-alert/checks/create/"&gt;InfluxDB UI Alerts&lt;/a&gt; section or craft a custom task to alert as well. Check out &lt;a href="https://www.influxdata.com/blog/influxdbs-checks-and-notifications-system/"&gt;InfluxDB’s Checks and Notifications system&lt;/a&gt; post for more details. It’s also possible to use the &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman()&lt;/a&gt;&lt;/strong&gt; function directly in a dashboard cell.&lt;/p&gt;
&lt;h2&gt;What the deadman() function does&lt;/h2&gt;
&lt;p&gt;The deadman function keeps the most recent row for each group (host), adding a &lt;strong&gt;dead&lt;/strong&gt; column that is set to &lt;strong&gt;false&lt;/strong&gt; if the most recent record happened after the time period to check for the deadman, or &lt;strong&gt;true&lt;/strong&gt; if it happened before this time period, indicating a deadman.&lt;/p&gt;

&lt;p&gt;Before going over the Flux query, it’s necessary to explain why using the &lt;strong&gt;deadman()&lt;/strong&gt; function is required. Without it, any host that stopped writing in would not be included in the table that is returned.&lt;/p&gt;
&lt;h2&gt;Writing a Flux query to use in a dashboard cell&lt;/h2&gt;
&lt;p&gt;Let’s say we want to create a dashboard cell that displays a list of hosts and the current uptime or “offline” if it’s not returning metrics.&lt;/p&gt;

&lt;p&gt;First we import two packages:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;import "influxdata/influxdb/monitor"
import "experimental"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The monitor package is used in the &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman()&lt;/a&gt; &lt;/strong&gt;function, and the experimental package is used in the &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/experimental/subduration/"&gt;experimental.subDuration()&lt;/a&gt;&lt;/strong&gt; function to request a time period in the past that we want to check for.&lt;/p&gt;

&lt;p&gt;Next, we bring back tables with the latest point for each host within the past 7 days:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;from(bucket: "bucket_name")
    |&amp;gt; range(start: -7d)
    |&amp;gt; filter(fn: (r) =&amp;gt; r["_measurement"] == "system")
    |&amp;gt; filter(fn: (r) =&amp;gt; r["_field"] == "uptime")
    |&amp;gt; group(columns: ["host"]
    |&amp;gt; last()&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The returned data includes the latest record for each &lt;strong&gt;host&lt;/strong&gt; with the uptime field &lt;strong&gt;_value&lt;/strong&gt; and &lt;strong&gt;_time&lt;/strong&gt; columns:&lt;/p&gt;

&lt;p&gt;&lt;img class="alignnone size-full wp-image-261158 aligncenter" src="/images/legacy-uploads/visualizing-uptime-flux.png" alt="Visualizing uptime using Flux query and scripting language" width="1014" height="159" /&gt;&lt;/p&gt;

&lt;p&gt;In order to check whether the host is a deadman; i.e., hasn’t written any data within the past hour, we’ll call the &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman()&lt;/a&gt; &lt;/strong&gt;function:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;|&amp;gt; monitor.deadman(t: experimental.subDuration(d: 1h, from: now()))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice the additional &lt;strong&gt;dead&lt;/strong&gt; column:&lt;/p&gt;

&lt;p&gt;&lt;img class="alignnone size-full wp-image-261159 aligncenter" src="/images/legacy-uploads/influxdb-deadman-alert.png" alt="Flux - monitor.deadman function" width="1017" height="151" /&gt;&lt;/p&gt;

&lt;p&gt;Hosts with a &lt;strong&gt;dead&lt;/strong&gt; record set to &lt;strong&gt;false&lt;/strong&gt; indicate they are actively sending in data. Likewise, hosts set to &lt;strong&gt;true&lt;/strong&gt; indicate a deadman; i.e., no data was written in the past hour.&lt;/p&gt;

&lt;p&gt;In order to make it more understandable in a dashboard cell, we add a &lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/universe/map/"&gt;map()&lt;/a&gt; to display “offline” hosts, otherwise, display the current uptime:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-javascript"&gt;|&amp;gt; map(fn: (r) =&amp;gt; ({ r with _value: if r.dead == true then "Offline" else string(v: r._value) }))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To display a more understandable uptime duration, we can convert seconds to days or hours:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;|&amp;gt; map(fn: (r) =&amp;gt; ({ r with _value: if r.dead == true then "Offline" else if 
                                           r._value &amp;gt; 86400 then 
                                                string(v: r._value / 86400) + " days" else
                                                string(v: r._value / 3600) + " hours"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The dashboard cell looks like:&lt;/p&gt;

&lt;p&gt;&lt;img class="alignnone size-full wp-image-261160 aligncenter" src="/images/legacy-uploads/visualize-uptime-flux-influxdb.png" alt="Displaying uptime duration" width="1020" height="209" /&gt;&lt;/p&gt;

&lt;p&gt;The complete query is:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;import "influxdata/influxdb/monitor"
import "experimental"

from(bucket: "bucket_name")
    |&amp;gt; range(start: -7d)
    |&amp;gt; filter(fn: (r) =&amp;gt; r["_measurement"] == "system")
    |&amp;gt; filter(fn: (r) =&amp;gt; r["_field"] == "uptime")
    |&amp;gt; monitor.deadman(t: experimental.subDuration(d: 1h, from: now()))
    |&amp;gt; map(fn: (r) =&amp;gt; ({ r with uptime: if r.dead == true then "Offline" else if 
                                           r._value &amp;gt; 86400 then 
                                                string(v: r._value / 86400) + " days" else
                                                string(v: r._value / 3600) + " hours"
                       }))
    |&amp;gt; group()
    |&amp;gt; keep(columns: ["uptime", "host"])&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note that &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/universe/last/"&gt;last()&lt;/a&gt;&lt;/strong&gt; is not required as &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman()&lt;/a&gt;&lt;/strong&gt; returns the latest point for each host. The &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/universe/group/"&gt;group()&lt;/a&gt; &lt;/strong&gt;ungroups the data so it’s in one table for display purposes. To make it sortable, another column can be added with the original uptime value, adding 0 instead of “offline” with &lt;a href="https://docs.influxdata.com/influxdb/v2.0/query-data/flux/conditional-logic/"&gt;conditional logic&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-javascript"&gt;|&amp;gt; map(fn: (r) =&amp;gt; ({ r with uptime_sort: if r.dead == true then 0 else r._value }))&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Conclusion on using the Flux deadman() function in InfluxDB Dashboards&lt;/h2&gt;
&lt;p&gt;I hope this post helps you realize that the Flux &lt;strong&gt;&lt;a href="https://docs.influxdata.com/flux/v0.x/stdlib/influxdata/influxdb/monitor/deadman/"&gt;monitor.deadman()&lt;/a&gt; &lt;/strong&gt;function is not just for alerts and tasks but can be used in dashboards as well.&lt;/p&gt;

&lt;p&gt;If you are new to Flux, or are migrating your InfluxQL queries to Flux and need help, please ask on our  &lt;a href="https://community.influxdata.com/"&gt;community site&lt;/a&gt; or &lt;a href="https://influxdata.com/slack"&gt;Slack&lt;/a&gt;  channel. If you’re developing a cool IoT application on top of InfluxDB, we’d love to hear about it, so make sure to &lt;a href="https://www.influxdata.com/get-hoodie/"&gt;share your story!&lt;/a&gt; Additionally, please share your thoughts, concerns or questions in the comments section. We’d love to get your feedback and help you with any problems you run into!&lt;/p&gt;
</description>
      <pubDate>Thu, 02 Dec 2021 08:49:41 -0700</pubDate>
      <link>https://www.influxdata.com/blog/tldr-influxdb-tech-tips-visualizing-uptime-flux-deadman-function-influxdb-dashboards/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/tldr-influxdb-tech-tips-visualizing-uptime-flux-deadman-function-influxdb-dashboards/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Adam Silverman (InfluxData)</author>
    </item>
    <item>
      <title>Track Fortnite Player Performance with InfluxDB, Telegraf and Python</title>
      <description>&lt;p&gt;Although I’m not much of a gamer, ever since my middle-school-aged son introduced me to the online game &lt;a href="https://www.epicgames.com/fortnite/en-US/home"&gt;Fortnite&lt;/a&gt;, I’ve been having a blast as I improve my skills week by week. It turns out I’m not alone as my old college friends, now with kids of their own, team up with us as we battle other players from around the world while catching up with each other. No wonder why Fortnite, produced by Epic Games, has over 350 million players and is considered one of the most popular online video games ever made.&lt;/p&gt;

&lt;p&gt;Although there are plenty of third-party Fortnite trackers, most of them provide current stats with limited time series visualizations. This makes it hard, if not impossible, to view Fortnite match history. By using a time series database, &lt;strong&gt;&lt;a href="https://w2.influxdata.com/products/influxdb-overview/"&gt;InfluxDB&lt;/a&gt;&lt;/strong&gt;, I set out to build real-time dashboards to visualize and alert on our progress and gain insight into how we perform compared to other players.&lt;/p&gt;
&lt;h2&gt;Overview of my Fortnite tracker&lt;/h2&gt;
&lt;p&gt;There are three main components that I focused on to develop this Fortnite player tracking system:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li&gt;&lt;strong&gt;Data gathering&lt;/strong&gt;: The first part involved data gathering, which uses &lt;a href="https://w2.influxdata.com/time-series-platform/telegraf/"&gt;Telegraf&lt;/a&gt; and Python to retrieve the data and send it to &lt;a href="https://cloud2.influxdata.com/signup"&gt;InfluxDB Cloud&lt;/a&gt;.&lt;/li&gt;
 	&lt;li&gt;&lt;strong&gt;Dashboards&lt;/strong&gt;: The second part focused on developing dashboards using &lt;a href="https://v2.docs.influxdata.com/v2.0/query-data/get-started/"&gt;Flux&lt;/a&gt; queries and &lt;a href="https://v2.docs.influxdata.com/v2.0/visualize-data/variables/variable-types/#query"&gt;query variables&lt;/a&gt; in the InfluxDB Script Editor to visualize player performance.&lt;/li&gt;
 	&lt;li&gt;&lt;strong&gt;Alerting&lt;/strong&gt;: The last component dealt with alerting since I wanted to be notified when my friends and family win matches. The smile my son gave when I congratulated him at dinnertime one evening for winning a solo match made this feature worthwhile!&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Although all three dashboards provide useful information to track player performance, my favorite dashboard is the &lt;strong&gt;Fortnite - Player Comparison Dashboard&lt;/strong&gt;, which displays a match-up analysis between any two players, with the winner crowned with a giant celebratory emoji. See how you stack up against your friends, family, or the pros!&lt;/p&gt;

&lt;p&gt;&lt;img class="wp-image-249255 size-full" src="/images/legacy-uploads/Fortnite-player-comparison-dashboard.jpg" alt="Fortnite player comparison dashboard" width="980" height="667" /&gt;&amp;lt;figcaption&amp;gt; One of the dashboards that we’ll be setting up in your InfluxDB Cloud account&amp;lt;/figcaption&amp;gt;&lt;/p&gt;

&lt;p&gt;Here’s a detailed, step-by-step tutorial of how to build Fortnite leaderboards using an unofficial Fortnite API and InfluxDB Cloud.&lt;/p&gt;
&lt;h2&gt;How to use the Fortnite API to show leaderboard stats&lt;/h2&gt;
&lt;p&gt;First, sign up for a &lt;strong&gt;&lt;a href="https://fortniteapi.io"&gt;free unofficial Fortnite API account&lt;/a&gt;&lt;/strong&gt; to get a &lt;a href="https://dashboard.fortniteapi.io/"&gt;Fortnite API token&lt;/a&gt;. The free account is good enough; you don’t need the paid account unless you’re doing over 10,000 requests per day. This limit of 10k requests lets you poll once every ten seconds, which is more than enough to use the free API for Fortnite without getting access denied.&lt;/p&gt;

&lt;p&gt;Then, go into Fortnite itself, and make sure the &lt;strong&gt;Show on Career Leaderboard&lt;/strong&gt; option is set to ON in the &lt;strong&gt;Account&lt;/strong&gt; &lt;strong&gt;and Privacy&lt;/strong&gt; section. Each of your friends whose stats you want to track will need to do this, as well.&lt;/p&gt;

&lt;p&gt;&lt;img class="wp-image-249253 size-full" src="/images/legacy-uploads/Fortnite-account-and-privacy-settings.jpg" alt="Fortnite account and privacy settings" width="980" height="533" /&gt;&amp;lt;figcaption&amp;gt; Fortnite Account and Privacy settings&amp;lt;/figcaption&amp;gt;&lt;/p&gt;
&lt;h2&gt;Set up your computer&lt;/h2&gt;
&lt;p&gt;Just to be clear, this tutorial works if you have a Mac or Linux box. (My apologies to all you Windows users out there!)&lt;/p&gt;

&lt;p&gt;Make sure you have the &lt;strong&gt;&lt;a href="https://curl.haxx.se/"&gt;curl&lt;/a&gt; &lt;/strong&gt;terminal command installed on your computer, since we’ll use that to interact with the Fortnite API. Here’s &lt;a href="http://macappstore.org/curl/"&gt;how to install curl on macOS&lt;/a&gt;, and &lt;a href="https://www.tecmint.com/install-curl-in-linux/"&gt;how to install curl on Linux&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We’ll be using &lt;strong&gt;Python&lt;/strong&gt;, too, in order to run a Python script. You’ll want the latest version, version 3. Here’s &lt;a href="https://docs.python-guide.org/starting/install3/osx/"&gt;how to install Python 3 on Mac&lt;/a&gt;, and &lt;a href="https://docs.python-guide.org/starting/install3/linux/"&gt;how to install Python on Linux&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Download and install &lt;strong&gt;&lt;a href="https://portal.influxdata.com/downloads/"&gt;Telegraf&lt;/a&gt;&lt;/strong&gt;, our open source data collection agent, available on macOS and Linux (&lt;a href="https://w2.influxdata.com/blog/using-telegraf-on-windows/"&gt;and Windows&lt;/a&gt;, though that’s out of scope for this post). Here’s &lt;a href="https://docs.influxdata.com/telegraf/v1.15/introduction/installation/"&gt;how to install Telegraf&lt;/a&gt;. If you’re on a Mac and use &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt;, just run the following command in Terminal:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;brew install telegraf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once Telegraf is installed, note which directory it is located in. You might want to &lt;a href="https://medium.com/@imstudio/path-macos-best-practice-for-path-environment-variables-on-mac-os-35ec4076a486"&gt;put that path location into your $PATH as well&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Next, get the &lt;strong&gt;&lt;a href="https://portal.influxdata.com/downloads/"&gt;InfluxDB v2.0.0-beta CLI&lt;/a&gt;&lt;/strong&gt;, available on macOS or Linux, which you’ll run in a terminal to import the &lt;a href="https://github.com/influxdata/community-templates/tree/master/fortnite"&gt;InfluxDB template for Fortnite&lt;/a&gt;. To do that:&lt;/p&gt;
&lt;ol&gt;
 	&lt;li&gt;Go to &lt;a href="https://portal.influxdata.com/downloads/"&gt;https://portal.influxdata.com/downloads/&lt;/a&gt;&lt;/li&gt;
 	&lt;li&gt;Click on the &lt;strong&gt;InfluxDB 2.0&lt;/strong&gt; button:

&lt;img class="wp-image-249252 size-full" src="/images/legacy-uploads/InfluxDB-2.0-button.png" alt="InfluxDB-2.0 button" width="333" height="190" /&gt;&lt;figcaption&gt; Choose InfluxDB 2.0&lt;/figcaption&gt;&lt;/li&gt;
 	&lt;li&gt;Choose "CLI Only" for Mac or Linux. This gives you access to commands that you can run in a terminal to interact with InfluxDB Cloud, without having to download InfluxDB OSS bits that you won't be using.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img class="wp-image-249251 size-full" src="/images/legacy-uploads/Options-fro-downloading-InfluxDB.png" alt="Options for downloading InfluxDB" width="594" height="776" /&gt;&amp;lt;figcaption&amp;gt; Options for downloading InfluxDB&amp;lt;/figcaption&amp;gt;&lt;/p&gt;
&lt;h2&gt;How to get InfluxDB Cloud&lt;/h2&gt;
&lt;p&gt;Sign up for a &lt;a href="https://cloud2.influxdata.com/signup"&gt;&lt;strong&gt;free InfluxDB Cloud account&lt;/strong&gt;. &lt;/a&gt;This will provide you with a time series database that you don’t need to set up or maintain.&lt;/p&gt;

&lt;p&gt;Once you’ve done so, create and copy your &lt;a href="https://v2.docs.influxdata.com/v2.0/security/tokens/"&gt;InfluxDB authentication token&lt;/a&gt; from the Data / Tokens section of the InfluxDB Cloud UI. To see the actual token value, click on the token name in the UI.&lt;/p&gt;

&lt;p&gt;&lt;img class="wp-image-249250 size-full" src="/images/legacy-uploads/Get-the-token-value.jpg" alt="Get the token value" width="980" height="527" /&gt;&amp;lt;figcaption&amp;gt; Click on the token name to get the token value&amp;lt;/figcaption&amp;gt;&lt;/p&gt;
&lt;h2&gt;How to get data from Fortnite using curl&lt;/h2&gt;
&lt;p&gt;First, you need to get the Fortnite player ID. To do this, open a Terminal window (here’s how to do that on &lt;a href="https://support.apple.com/guide/terminal/open-or-quit-terminal-apd5265185d-f365-44cb-8b09-71a064a42125/mac"&gt;Mac&lt;/a&gt;, and on &lt;a href="https://maker.pro/linux/tutorial/basic-linux-commands-for-beginners"&gt;Linux&lt;/a&gt;) and run the following curl command on the Fortnite API:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-bash"&gt;curl --request GET 'https://fortniteapi.io/lookup?username=&amp;lt;USERNAME&amp;gt;' \
       --header 'Authorization: &amp;lt;API_KEY&amp;gt;'&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example, if the username is &lt;strong&gt;JohnDoe&lt;/strong&gt;, and your Fortnite API key is &lt;strong&gt;08fd8613a&lt;/strong&gt;, you’d enter:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-bash"&gt;curl --request GET 'https://fortniteapi.io/lookup?username=JohnDoe' \
       --header 'Authorization: 08fd8613a'&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the username exists, the output shows:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-json"&gt;{"result":true,"account_id":"4735ce913"}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And if the username doesn’t exist, the output shows:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-json"&gt;{"result":false,"error":"This account does not exist"}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to check whether the account is returning metrics:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;curl --location --request GET 'https://fortniteapi.io/stats?account=&amp;lt;PLAYER_ID&amp;gt;&amp;amp;season=&amp;lt;SEASON&amp;gt;' --header 'Authorization: &amp;lt;API-KEY&amp;gt;'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Using the previous example, and the current season, 13, you’d enter:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;curl --location --request GET 'https://fortniteapi.io/stats?account=JohnDoe'&amp;amp;season=13' --header 'Authorization: &lt;strong&gt;08fd8613a&lt;/strong&gt;''&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the account is returning metrics, you’ll see something like:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-json"&gt;..."account":{"level":241,"progress_pct":89},"global_stats":{"squad":{"placetop1":75…&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the account is not returning metrics, you’ll see:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-json"&gt;..."account":{"level":null,"progress_pct":null},"global_stats":null...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As mentioned previously, if the account is not returning metrics, this indicates the player has &lt;strong&gt;Show on Career Leaderboard&lt;/strong&gt; set to &lt;strong&gt;OFF&lt;/strong&gt; in the &lt;strong&gt;Account and Privacy&lt;/strong&gt; section of their profile.&lt;/p&gt;

&lt;p&gt;In order to access performance metrics, the Fortnite API expects to be fed the various player IDs that you’re interested in, in the form of a CSV file with the player IDs.&lt;/p&gt;

&lt;p&gt;Download &lt;strong&gt;players.csv&lt;/strong&gt; from &lt;a href="https://raw.githubusercontent.com/influxdata/community-templates/master/fortnite/players.csv"&gt;the community template&lt;/a&gt;, and save it on your machine as &lt;strong&gt;players.csv&lt;/strong&gt; (all lowercase) in your &lt;strong&gt;/etc/telegraf&lt;/strong&gt; directory. Then open your local copy of players.csv with a text editor (such as &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt;, &lt;a href="https://www.vim.org/"&gt;vim&lt;/a&gt;, or &lt;a href="https://support.apple.com/guide/textedit/open-documents-txte51413d09/mac"&gt;TextEdit&lt;/a&gt; on Macs).&lt;/p&gt;

&lt;p&gt;You’ll see players.csv is seeded with several professional Fortnite players and the second field, &lt;strong&gt;pro&lt;/strong&gt;. The reason we have a field called “pro” is that the metrics for professional and amateur players are so divergent. As a Fortnite player, I like to watch my favorite pro players on YouTube and Twitch, and I also have my set of amateur friends/family who I also want to track. But I don’t want to group them together because their metrics differ too much to visualize cleanly on a single graph.&lt;/p&gt;

&lt;p&gt;So to be clear: whether an account is considered “pro” or not is for you to determine manually; the Fortnite API doesn’t provide this information.&lt;/p&gt;

&lt;p&gt;In subsequent lines, enter the player ID (which you got from the curl command above), whether they are a pro player or not, and their username. Each line should look like this:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-markup"&gt;4735ce913,yes,Ninja&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Putting this all together, you should end up with a CSV file that looks similar to this:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-markup"&gt;acct_id,pro,player_name
4735ce9132924caf8a5b17789b40f79c,yes,Ninja
827abb1cd9fb4618991425c2d3ba9b76,yes,bugha
8a3a179679194354b1eae7e3a4620ded,yes,LazarLazar
d44eaa65d78c444abccc7129a0a06a79,yes,Cloak&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Save this CSV file as &lt;strong&gt;players.csv&lt;/strong&gt; (all lowercase) in your &lt;strong&gt;/etc/telegraf&lt;/strong&gt; directory.&lt;/p&gt;

&lt;p&gt;The above CSV file includes some well-known professional Fortnite players &lt;a href="https://en.wikipedia.org/wiki/Ninja_(gamer)"&gt;Ninja&lt;/a&gt;, &lt;a href="https://fortnite-esports.gamepedia.com/Bugha"&gt;Bugha&lt;/a&gt;, &lt;a href="https://fortnite-esports.gamepedia.com/LazarLazar"&gt;LazarLazar&lt;/a&gt;, and &lt;a href="https://fortnite-esports.gamepedia.com/Cloakzy"&gt;Cloak&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;How to load the InfluxDB Template for Fortnite&lt;/h2&gt;
&lt;p&gt;Now that we have our CSV file, use the &lt;strong&gt;&lt;a href="https://v2.docs.influxdata.com/v2.0/reference/cli/influx/"&gt;influxdb CLI&lt;/a&gt;&lt;/strong&gt;, to import all the Fortnite resources in &lt;a href="https://github.com/influxdata/community-templates/tree/master/fortnite"&gt;this InfluxDB template for Fortnite&lt;/a&gt;. This includes the &lt;a href="https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md"&gt;Telegraf config&lt;/a&gt;, &lt;a href="https://v2.docs.influxdata.com/v2.0/visualize-data/dashboards/"&gt;InfluxDB dashboards&lt;/a&gt;, &lt;a href="https://v2.docs.influxdata.com/v2.0/visualize-data/variables/"&gt;variables&lt;/a&gt;, &lt;a href="https://v2.docs.influxdata.com/v2.0/monitor-alert/"&gt;alerts&lt;/a&gt; and Python script. To do that, run the following command from your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;influx apply -u &lt;a href="https://raw.githubusercontent.com/influxdata/community-templates/master/fortnite/fn-template.yml"&gt;https://raw.githubusercontent.com/influxdata/community-templates/master/fortnite/fn-template.yml&lt;/a&gt; --env-ref=fn_bucket=fortnite&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command pulls the Fortnite player leaderboard template from GitHub and into your InfluxDB Cloud instance. It also creates a bucket called &lt;em&gt;fortnite&lt;/em&gt; if necessary. If you’d like to use a different bucket, you can change it as well. Keep in mind that if another bucket is used, the bucket name will need to be updated in the InfluxDB Task called &lt;em&gt;wins&lt;/em&gt;, and the InfluxDB query variables called &lt;em&gt;player&lt;/em&gt;, &lt;em&gt;player2&lt;/em&gt; and season.&lt;/p&gt;

&lt;p&gt;Another change you need to make: the &lt;em&gt;Fortnite - All Players&lt;/em&gt; dashboard displays a URL drilldown to the &lt;em&gt;Fortnite - Individual Stats&lt;/em&gt; dashboard. This URL must be changed in the &lt;em&gt;Friends &amp;amp; Family&lt;/em&gt; and &lt;em&gt;Pros&lt;/em&gt; cells:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-markup"&gt;&amp;lt;INFLUX_HOST&amp;gt;/orgs/&amp;lt;INFLUX_ORG_ID&amp;gt;/dashboards/&amp;lt;FORTNITE_INDIVIDUAL_STATS_DASHBOARD_ID&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;… where:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;code class="language-markup" style="font-style: inherit; font-weight: inherit;"&gt;&amp;lt;INFLUX_HOST&amp;gt;&lt;/code&gt; is your &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/urls/#influxdb-cloud-urls"&gt;InfluxDB Cloud URL&lt;/a&gt;&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup" style="font-style: inherit; font-weight: inherit;"&gt;&amp;lt;INFLUX_ORG_ID&amp;gt;&lt;/code&gt; is your &lt;a href="https://v2.docs.influxdata.com/v2.0/organizations/view-orgs/"&gt;InfluxDB Cloud org ID&lt;/a&gt; (not your email; a hexadecimal number)&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-markup" style="font-style: inherit; font-weight: inherit;"&gt;&amp;lt;FORTNITE_INDIVIDUAL_STATS_DASHBOARD_ID&amp;gt;&lt;/code&gt; is the ID of the Fortnite individual stats dashboard, which is displayed right after "dashboards" in its URL, like this:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img class="wp-image-249249 size-full aligncenter" src="/images/legacy-uploads/ID-of-the-Fortnite-individual-stats.png" alt="ID of the Fortnite individual stats" width="716" height="37" /&gt;&lt;/p&gt;

&lt;p&gt;To get the full link, open the &lt;em&gt;Fortnite - Individual Stats&lt;/em&gt; dashboard and copy the URL up to but not including the “?”. Once you’ve done this, you’ll see some Fortnite-related dashboards in InfluxDB — but without any data. To get data into those dashboards, read on.&lt;/p&gt;
&lt;h2&gt;How to get data from Fortnite using Python&lt;/h2&gt;
&lt;p&gt;The InfluxDB Fortnite template depends on the Python script below, which takes the CSV file you previously copied and edited as an input, and gets stats for each user. To create this script, copy the text of &lt;a href="https://github.com/influxdata/community-templates/blob/master/fortnite/get_fn_stats.py"&gt;this Python script&lt;/a&gt; into a text editor, then save the file as &lt;strong&gt;get_fn_stats.py&lt;/strong&gt; (all lowercase) in your &lt;strong&gt;/etc/telegraf&lt;/strong&gt; directory.&lt;/p&gt;

&lt;p&gt;What this Python script does is loop through each ID and retrieve the performance metrics for each player using the API for Fortnite. I’m not going to paste the entire Python script here, since it’s around 100 lines long. The most interesting section is below; read through the comments to see what each line does.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-python"&gt;# Open the csv file /etc/telegraf/players.csv
with open('/etc/telegraf/players.csv', newline='') as csvfile:
    reader = csv.DictReader(csvfile)

    # For each row in our csv file...
    for row in reader:
        # Get the account ID field
        acct_id = row['acct_id']

        # Get the pro field
        pro = row['pro']
        
        # Set up our HTTP request
        response = requests.get(url,
                        	     headers = {'Authorization': FORTNITE_API_TOKEN},
                                params={'account': acct_id,
                                        'season': season
                                       }
                               )
        # Make our HTTP request, and store the response in data
        data = response.json()
        # Access the Python dictionary (list of name/value pairs)
        data_api_dict = parse_data(data)

        # Find the name/value entry for the current account ID
        data_api_dict['acct_id'] = acct_id
        data_api_dict['pro'] = pro

        # Append the stats for the current account ID to our list of stats
        data_api_list.append(data_api_dict.copy())

# Once we call our stats, write it in JSON to the api_output variable.
api_output = json.dumps(data_api_list)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(For those not familiar with Python: be sure to keep the indentation exactly as written above. Unlike other languages, Python treats the amount of &lt;a href="https://www.geeksforgeeks.org/indentation-in-python/"&gt;indentation to specify different code blocks&lt;/a&gt;. The lines of code with eight spaces of indentation all run within our &lt;code class="language-python"&gt;&lt;strong&gt;for&lt;/strong&gt;&lt;/code&gt; loop.)&lt;/p&gt;
&lt;h2&gt;How to run the Python script in Telegraf&lt;/h2&gt;
&lt;p&gt;Using the &lt;strong&gt;&lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec"&gt;Telegraf exec input plugin&lt;/a&gt;&lt;/strong&gt;, you can schedule the above Python script, which you saved at /etc/telegraf/get_fn_stats.py, to run hourly. With this plugin, you can mark account names, IDs, pro status and season as tags for InfluxDB to index for faster queries by putting the following into your &lt;a href="https://v2.docs.influxdata.com/v2.0/write-data/no-code/use-telegraf/manual-config/"&gt;Telegraf configuration file&lt;/a&gt;, which you can modify with a text editor:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[inputs.exec]]
          commands = [ "/etc/telegraf/get_fn_stats.py" ]
          data_format = "json"
          interval = "1h"
          tag_keys = [ "name", "acct_id", "pro", "season" ]&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here’s what each line above means:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;[[inputs.exec]]&lt;/code&gt; tells Telegraf to load the &lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec"&gt;exec plugin&lt;/a&gt;&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;commands = [ "/etc/telegraf/get_fn_stats.py" ]&lt;/code&gt; tells the exec plugin to run the Python file we just created&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;data_format = "json"&lt;/code&gt; tells the exec plugin to output in &lt;a href="https://en.wikipedia.org/wiki/JSON"&gt;JSON format&lt;/a&gt;&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;interval = "1h"&lt;/code&gt; tells the exec plugin to run once an hour. This is equivalent to "60m". You can also use other values like 10m for 10 minutes, 2h for two hours, and so on.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;tag_keys = [ "name", "acct_id", "pro", "season" ]&lt;/code&gt; tells the exec plugin to add the player name, account ID, pro status (yes or no), and season as tags to each row of &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/syntax/line-protocol/"&gt;line protocol&lt;/a&gt; sent to InfluxDB.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Save your Telegraf configuration file as &lt;strong&gt;/etc/telegraf/telegraf.conf&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;How to send data to InfluxDB Cloud&lt;/h2&gt;
&lt;p&gt;Also in your Telegraf configuration file, you’ll want to specify where your data is going: which InfluxDB Cloud instance, which account, and which bucket. To do that, add the following to your Telegraf config file:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;[[outputs.influxdb_v2]]
  urls = ["$INFLUX_HOST"]
  token = "$INFLUX_TOKEN"
  organization = "$INFLUX_ORG"
  bucket = "$INFLUX_BUCKET"
  namepass = ["exec_fortnite"]
  timeout = "20s"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here’s what each line above does:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;[[outputs.influxdb_v2]]&lt;/code&gt; tells Telegraf to write to InfluxDB 2.0 (if you're writing to InfluxDB 1.x, use the &lt;a href="https://github.com/influxdata/telegraf/tree/master/plugins/outputs/influxdb"&gt;influxdb output plugin&lt;/a&gt;, without the _v2 at the end).&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;urls = ["$INFLUX_HOST"]&lt;/code&gt; is the &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/urls/"&gt;URL of the InfluxDB database&lt;/a&gt; you're sending to.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;token = "$INFLUX_TOKEN"&lt;/code&gt; is your &lt;a href="https://v2.docs.influxdata.com/v2.0/security/tokens/"&gt;InfluxDB access token&lt;/a&gt;.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;organization = "$INFLUX_ORG"&lt;/code&gt; is your &lt;a href="https://v2.docs.influxdata.com/v2.0/organizations/view-orgs/"&gt;InfluxDB organization&lt;/a&gt;.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;bucket = "$INFLUX_BUCKET"&lt;/code&gt; is the &lt;a href="https://v2.docs.influxdata.com/v2.0/organizations/buckets/view-buckets/"&gt;InfluxDB bucket&lt;/a&gt; that you're writing to.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;namepass = ["exec_fortnite"]&lt;/code&gt; is useful if you have multiple InfluxDB output plugins in your Telegraf configuration. It directs Telegraf to only send metrics named exec_fortnite. If you only have one InfluxDB output plugin in your Telegraf config, you can safely remove this line.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;timeout = "20s"&lt;/code&gt; tells Telegraf to wait 20 seconds before timing out when writing data.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The dollar signs in front of &lt;code class="language-ini"&gt;$INFLUX_HOST&lt;/code&gt;, &lt;code class="language-ini"&gt;$INFLUX_TOKEN&lt;/code&gt;, &lt;code class="language-ini"&gt;$INFLUX_ORG&lt;/code&gt; and &lt;code class="language-ini"&gt;$INFLUX_BUCKET&lt;/code&gt; direct Telegraf to look for environment variables with each of those names. Let’s set those up now.&lt;/p&gt;
&lt;h2&gt;How to set up environment variables for InfluxDB&lt;/h2&gt;
&lt;p&gt;The Telegraf configuration requires the following environment variables to be set for InfluxDB Cloud 2:&lt;/p&gt;
&lt;ul&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;INFLUX_HOST&lt;/code&gt; - the &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/urls/"&gt;URL&lt;/a&gt; of your InfluxDB 2 instance&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;INFLUX_TOKEN&lt;/code&gt; - The &lt;a href="https://v2.docs.influxdata.com/v2.0/security/tokens/"&gt;token&lt;/a&gt; with the permissions to read Telegraf configs and write data to the &lt;code class="language-bash" style="font-style: inherit; font-weight: inherit;"&gt;&amp;lt;FORTNITE&amp;gt;&lt;/code&gt; bucket&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;INFLUX_ORG&lt;/code&gt; - The name of your &lt;a href="https://v2.docs.influxdata.com/v2.0/organizations/view-orgs/"&gt;organization&lt;/a&gt; found on the InfluxDB profile page.&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;INFLUX_BUCKET&lt;/code&gt; - The name of the &lt;a href="https://v2.docs.influxdata.com/v2.0/organizations/buckets/view-buckets/"&gt;bucket&lt;/a&gt; to write to&lt;/li&gt;
 	&lt;li&gt;&lt;code class="language-ini" style="font-style: inherit; font-weight: inherit;"&gt;FORTNITE_API_TOKEN&lt;/code&gt; - The &lt;a href="https://fortniteapi.io/"&gt;Fortnite API&lt;/a&gt; token&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Information on using environment variables can be found in the &lt;a href="https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#environment-variables"&gt;Telegraf configuration documentation&lt;/a&gt;. (If you’re not familiar with how to set environment variables, here’s &lt;a href="https://medium.com/@youngstone89/setting-up-environment-variables-in-mac-os-28e5941c771c"&gt;how to set them on Mac&lt;/a&gt;, and &lt;a href="https://www.redhat.com/sysadmin/linux-environment-variables"&gt;on Linux&lt;/a&gt;.)&lt;/p&gt;
&lt;h2&gt;How to run Telegraf&lt;/h2&gt;
&lt;p&gt;In your terminal, type:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;/path/to/telegraf --config /etc/telegraf/telegraf.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;(Replace “/path/to” with the actual path to Telegraf, of course!)&lt;/p&gt;

&lt;p&gt;You’ll see output similar to:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-bash"&gt;2020-08-05T01:34:54Z I! Starting Telegraf 1.15.2
2020-08-05T01:34:54Z I! Loaded inputs: exec
2020-08-05T01:34:54Z I! Loaded outputs: influxdb_v2&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If so, your Telegraf agent is running and should be sending data to InfluxDB. To stop Telegraf, hit ctrl-c on your keyboard.&lt;/p&gt;
&lt;h2&gt;How to run Telegraf as a service&lt;/h2&gt;
&lt;p&gt;If you’d like Telegraf to be run as a service, even if you close your terminal window, you should run it as a service. To do this, add the following variables to &lt;strong&gt;/etc/default/telegraf&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-ini"&gt;INFLUX_TOKEN=your_influxdb_token
INFLUX_ORG=your_email@company.com
INFLUX_BUCKET=fortnite
FORTNITE_API_TOKEN=your_fortnite_api_token&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then run one of the following sets of commands, depending on whether you’re on Mac or Linux:&lt;/p&gt;

&lt;p&gt;To run Telegraf as a service on a &lt;strong&gt;Mac&lt;/strong&gt;, this command will have &lt;a href="https://medium.com/swlh/how-to-use-launchd-to-run-services-in-macos-b972ed1e352"&gt;launchd&lt;/a&gt; start telegraf at next login:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;ln -sfv /usr/local/opt/telegraf/*.plist ~/Library/LaunchAgents&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To load Telegraf now:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;launchctl load ~/Library/LaunchAgents/homebrew.mxcl.telegraf.plist&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To check the status of your Telegraf service on Mac:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;launchctl list | grep telegraf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If Telegraf is running, you’ll see it listed in the output. If it’s not, you won’t see anything. More in the &lt;a href="https://ss64.com/osx/launchctl.html"&gt;launchctl man pages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And to run Telegraf as a service on &lt;strong&gt;Linux&lt;/strong&gt;, use the &lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units"&gt;systemctl command&lt;/a&gt;, which comes with Linux distros that support &lt;a href="https://en.wikipedia.org/wiki/Systemd"&gt;systemd&lt;/a&gt;, including Ubuntu, Debian, Red Hat, and Centos:&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-bash"&gt;sudo systemctl restart telegraf # (Re)start Telegraf as a service 
sudo systemctl enable telegraf  # Run Telegraf as a service at boot&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To check the status of your Telegraf service on Linux:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;sudo systemctl status telegraf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://docs.influxdata.com/telegraf/latest/introduction/installation/"&gt;Telegraf installation page&lt;/a&gt; provides more details.&lt;/p&gt;
&lt;h2&gt;How to use InfluxDB Dashboards&lt;/h2&gt;
&lt;p&gt;The great thing about InfluxDB Templates is that they automatically create dashboards (and other assets) for you, &lt;a href="https://w2.influxdata.com/blog/influxdb-templates-share-monitoring-expertise/"&gt;saving you hours if not days of time&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For instance, here is the custom metric Flux script to determine the winner of a one-on-one stats matchup:&lt;/p&gt;

&lt;p&gt;&lt;img class="wp-image-249248 size-full" src="/images/legacy-uploads/Flux-code-in-InfluxDB-query-editor.jpg" alt="Flux code in InfluxDB query editor" width="980" height="856" /&gt;&amp;lt;figcaption&amp;gt; Flux code in InfluxDB query editor&amp;lt;/figcaption&amp;gt;&lt;/p&gt;

&lt;p&gt;The InfluxDB query variables &lt;strong&gt;v.player&lt;/strong&gt; in the above example is used in the dashboard dropdowns and referenced in Flux scripts across dashboards and cells.&lt;/p&gt;

&lt;p&gt;If all is working well, you should see dashboards that look like the following:&lt;/p&gt;

&lt;p&gt;&lt;img class="wp-image-249246 size-full" src="/images/legacy-uploads/Fortnite-dashboard-in-InfluxDB.jpg" alt="Fortnite dashboard in InfluxDB" width="980" height="590" /&gt;&amp;lt;figcaption&amp;gt; Fortnite dashboard in InfluxDB&amp;lt;/figcaption&amp;gt;&lt;/p&gt;

&lt;p&gt;Screenshots of all our Fortnite dashboards are in the &lt;a href="https://github.com/influxdata/community-templates/tree/master/fortnite"&gt;Fortnite community template&lt;/a&gt; readme.&lt;/p&gt;
&lt;h2&gt;How to securely integrate InfluxDB with Slack&lt;/h2&gt;
&lt;p&gt;In the &lt;a href="https://github.com/influxdata/community-templates/blob/master/fortnite/fn-template.yml"&gt;InfluxDB Template for Fornite&lt;/a&gt;, I created a custom &lt;a href="https://v2.docs.influxdata.com/v2.0/process-data/"&gt;InfluxDB Task&lt;/a&gt; with the &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/flux/stdlib/slack/message/"&gt;HTTP Slack endpoint&lt;/a&gt; and check built-in. The benefit is that this approach provides you with more control than using an &lt;a href="https://v2.docs.influxdata.com/v2.0/monitor-alert/"&gt;InfluxDB Alert&lt;/a&gt;. The tradeoff is that InfluxDB Alerts require less coding knowledge.&lt;/p&gt;

&lt;p&gt;To use this InfluxDB task, you need to save the &lt;a href="https://api.slack.com/messaging/webhooks"&gt;Slack webhook&lt;/a&gt; as an &lt;a href="https://v2.docs.influxdata.com/v2.0/reference/cli/influx/secret/"&gt;InfluxDB secret&lt;/a&gt;. An InfluxDB secret is some kind of sensitive information, such as login credentials, account information, or (in this case) a secret URL for your Slack webhook.&lt;/p&gt;

&lt;p&gt;You should store your Slack webhook using this InfluxDB CLI command:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;influx secret update -k SLACK_WEBHOOK&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After running this command you’ll be prompted for a value; enter:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;https://hooks.slack.com/services/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&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is our InfluxDB community Slack sandbox, which anyone can use. To access it, go to&lt;a href="https://influxcommunity.slack.com"&gt; https://influxcommunity.slack.com&lt;/a&gt;, register for Slack if needed, and go to the #notifications-testing channel to see your alerts. You should see something like the following in the Slack UI when your alerts fire:&lt;/p&gt;

&lt;p&gt;&lt;img class="aligncenter wp-image-249245 size-full" src="/images/legacy-uploads/UI-alert.png" alt="UI alert" width="800" height="120" /&gt;&lt;/p&gt;

&lt;p&gt;Granted, your alerts will be mixed in with everyone else’s sandbox alerts. But for simple testing, this should work fine. Please be a good community member, and turn off this alert once you’ve validated that it works.&lt;/p&gt;

&lt;p&gt;Once you’ve validated that your Slack notifications are working, you’ll want to &lt;a href="https://api.slack.com/messaging/webhooks#posting_with_webhooks"&gt;set up your own incoming webhooks for your own Slack instance&lt;/a&gt;. Because that’s your own secret webhook URL, you’ll definitely want to store it in an InfluxDB secret.&lt;/p&gt;

&lt;p&gt;At this point, your Fortnite dashboards and alerts should be populated and running correctly. But let’s go a bit deeper to understand more about how this works.&lt;/p&gt;
&lt;h2&gt;How to use InfluxDB Tasks to send Slack alerts&lt;/h2&gt;
&lt;p&gt;Let’s examine the InfluxDB task for alerting. This task was automatically created when you loaded the InfluxDB Template for Fortnite in the step above, using the influx apply CLI command. You can see this code in the &lt;a href="https://github.com/influxdata/community-templates/blob/master/fortnite/fn-template.yml"&gt;template yaml file&lt;/a&gt;; just search for “slack_webhook”.&lt;/p&gt;

&lt;p&gt;So, you don’t need to do anything to create this task, but it’s instructive to review the Flux code below.&lt;/p&gt;
&lt;pre class="line-numbers"&gt;&lt;code class="language-javascript"&gt;// Retrieve the secret Slack webhook URL
webhook = secrets.get(key: "SLACK_WEBHOOK")

// Define the Slack messaging function
sendSlackMessage = (text) =&amp;gt;
	(slack.message(
		url: webhook,
		token: "",
		channel: "",
		text: text,
		color: "good",
	))

// Retrieve wins from previous period from our fortnite bucket
from(bucket: "fortnite")
	// Look at data starting from 30 to 120 minute ago
	|&amp;gt; range(start: -2h, stop: -30m)
	// Look only for measurements from the Telegraf exec plugin
	// that are related to fortnite.
	|&amp;gt; filter(fn: (r) =&amp;gt;
		(r["_measurement"] == "exec_fortnite"))
	// Look for the fields squad_placetop1, solo_placetop1 &amp;amp; duo_placetop1
	|&amp;gt; filter(fn: (r) =&amp;gt;
		(r["_field"] == "squad_placetop1" or r["_field"] == "solo_placetop1" or r["_field"] == "duo_placetop1"))
	// Ensure that "pro" is properly defined one way or the other
	|&amp;gt; filter(fn: (r) =&amp;gt;
		(r["pro"] == "no" or r["pro"] == "yes"))
	// Group all rows by player name and _field
	|&amp;gt; group(columns: ["name", "_field"])
	// We don't need the start time, stop time, or "is a pro" columns
	|&amp;gt; drop(columns: ["_start", "_stop", "pro"])
	|&amp;gt; difference()
	|&amp;gt; group(columns: ["_time", "name"])
	|&amp;gt; filter(fn: (r) =&amp;gt;
		(r["_value"] == 1))
	// Create a new column with text of Slack message
	|&amp;gt; map(fn: (r) =&amp;gt;
		({r with newColumn: if r["_value"] == 1 then 
                            sendSlackMessage(text: 
                                "Congratulations to *${string(v: r.name)}* for winning a Fortnite *${strings.trimSuffix(v: r._field, suffix: "_placetop1")}* match! :boom: :boom: :boom:") else 
                            100}))&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When a player wins a match, the Slack message I showed you above is automatically sent.&lt;/p&gt;

&lt;p&gt;The alert condition can be customized so that only friends and family trigger alerts:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-javascript"&gt;|&amp;gt; filter(fn: (r) =&amp;gt; (r["pro"] == "no"))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or only one particular player:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-javascript"&gt;|&amp;gt; filter(fn: (r) =&amp;gt; (r["name"] == "Ninja"))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When you look in the &lt;a href="https://github.com/influxdata/community-templates/blob/master/fortnite/fn-template.yml"&gt;template yaml file&lt;/a&gt;, you’ll see that I’ve set this task to run once an hour:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-yaml"&gt;every: 1h0m0s&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;Creating the InfluxDB Template&lt;/h2&gt;
&lt;p&gt;I’ve been tracking and alerting Fortnite since the beginning of &lt;strong&gt;Chapter 2 - Season 3&lt;/strong&gt; in June and have enjoyed watching how my son and I have been progressing throughout the season. When my Fortnite-playing friends check it out, the first thing they ask is how they can get access, so I decided to create a template that includes everything required for your own Fortnite tracking system. This includes the dashboards, query variables, alerts and Telegraf configuration. Since all assets are labeled &lt;strong&gt;fortnite&lt;/strong&gt;, exporting this as a template is straightforward:&lt;/p&gt;

&lt;p&gt;&lt;code class="language-bash"&gt;influx export all --filter=labelName=fortnite -f fn-template.yml&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can use this same approach to export your own InfluxDB templates, and &lt;a href="https://w2.influxdata.com/blog/influxdb-templates-share-monitoring-expertise/"&gt;easily share your monitoring expertise&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;Putting it all together&lt;/h2&gt;
&lt;p&gt;Here’s a video of how to follow many of the steps above so you can build your own Fortnite player tracking dashboard:&lt;/p&gt;

&lt;iframe src="https://www.youtube.com/embed/sbDHDWG0lfE" width="900" height="506" frameborder="0" allowfullscreen="allowfullscreen"&gt;&lt;span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"&gt;?&lt;/span&gt;&lt;/iframe&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Flux and the InfluxDB UI allowed me to quickly iterate to develop a visualization and alerting solution to track Fortnite player performance over time. If you’d like the same, register for a free &lt;a href="https://cloud2.influxdata.com/signup" target="_blank" rel="noopener"&gt;InfluxDB Cloud account&lt;/a&gt; and install the &lt;a href="https://github.com/influxdata/community-templates/tree/master/fortnite" target="_blank" rel="noopener"&gt;Fortnite community template&lt;/a&gt; so you can start tracking and alerting in no time!&lt;/p&gt;

&lt;p&gt;And if you have questions, please ask on our &lt;a href="https://w2.influxdata.com/slack"&gt;InfluxDB community Slack&lt;/a&gt; and &lt;a href="https://community.influxdata.com/"&gt;community website&lt;/a&gt;.&lt;/p&gt;
</description>
      <pubDate>Wed, 12 Aug 2020 06:00:53 -0700</pubDate>
      <link>https://www.influxdata.com/blog/track-fortnite-player-performance-influxdb-telegraf-python/</link>
      <guid isPermaLink="true">https://www.influxdata.com/blog/track-fortnite-player-performance-influxdb-telegraf-python/</guid>
      <category>Product</category>
      <category>Use Cases</category>
      <category>Developer</category>
      <author>Adam Silverman (InfluxData)</author>
    </item>
  </channel>
</rss>
