<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>influx on foosel.net</title><link>https://foosel.net/tags/influx/</link><description>Recent content in influx on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Thu, 26 Dec 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/influx/feed.xml" rel="self" type="application/rss+xml"/><item><title>TIL: How to fetch additional data for a flux query from a json file</title><link>https://foosel.net/til/2024-12-26-how-to-fetch-additional-data-for-a-flux-query-from-a-json-file/</link><pubDate>Thu, 26 Dec 2024 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2024-12-26-how-to-fetch-additional-data-for-a-flux-query-from-a-json-file/</guid><description>&lt;p&gt;My buddy Romses is currently taking care of the &lt;a href="https://datagnome.de"&gt;Datenzwerg deployment&lt;/a&gt; at 38c3, and like at every event where we deploy them I&amp;rsquo;m updating our page and &lt;a href="https://grafana.datagnome.de"&gt;Grafana dashboard&lt;/a&gt; with the locations of the gnomes.&lt;/p&gt;
&lt;p&gt;So far the latter was always quite annoying: We have only the names of the gnomes in our influx data, and adding the location/deployment status to the graph thus meant having something like this for every single graph:&lt;/p&gt;</description><content:encoded><![CDATA[<p>My buddy Romses is currently taking care of the <a href="https://datagnome.de">Datenzwerg deployment</a> at 38c3, and like at every event where we deploy them I&rsquo;m updating our page and <a href="https://grafana.datagnome.de">Grafana dashboard</a> with the locations of the gnomes.</p>
<p>So far the latter was always quite annoying: We have only the names of the gnomes in our influx data, and adding the location/deployment status to the graph thus meant having something like this for every single graph:</p>
<pre tabindex="0"><code class="language-flux" data-lang="flux">import &#34;strings&#34;
import &#34;dict&#34;

locations = [
    &#34;Bashful&#34;: &#34;Uptime Bar&#34;,
    &#34;Dopey&#34;: &#34;c3cat&#34;,
    &#34;Grumpy&#34;: &#34;Späti&#34;,
    &#34;Happy&#34;: &#34;Kidspace&#34;,
    &#34;Hefty&#34;: &#34;HASS Assembly&#34;,
    &#34;Moopsy&#34;: &#34;Chaospost&#34;,
    &#34;Kinky&#34;: &#34;Eventphone&#34;,
    &#34;Nerdy&#34;: &#34;House of Tea&#34;,
    &#34;Sleepy&#34;: &#34;DDOS Bar&#34;,
    &#34;Sneezy&#34;: &#34;Wohnzimmer&#34;
]

from(bucket: &#34;datagnome&#34;)
  [...]
  |&gt; map(fn: (r) =&gt; ({r with device: r.device + &#34; (&#34; + dict.get(dict: locations, key: r.device, default: &#34;?&#34;) + &#34;)&#34;}))
</code></pre><p>Which of course means that I had to update this <code>locations</code> dict for every single panel, on every single deployment, at least twice (start and end of the event).</p>
<p>I finally decided I had to solve this differently and just now figured out how to keep the deployment info in <a href="https://github.com/romses/Datenzwerg/blob/main/docs/deployment.json">a JSON file on our git repo</a> and then querying <em>that</em> from the graphs, instead of manually keeping the lookup data updated in more than one place:</p>
<pre tabindex="0"><code class="language-flux" data-lang="flux">import &#34;strings&#34;
import &#34;dict&#34;
import &#34;http/requests&#34;
import &#34;experimental/json&#34;

response = requests.get(url: &#34;https://raw.githubusercontent.com/romses/Datenzwerg/refs/heads/main/docs/deployment.json&#34;)
data = json.parse(data: response.body)
locations = dict.fromList(pairs: data)

from(bucket: &#34;datagnome&#34;)
  [...]
  |&gt; map(fn: (r) =&gt; ({r with device: r.device + &#34; (&#34; + dict.get(dict: locations, key: r.device, default: &#34;?&#34;) + &#34;)&#34;}))
</code></pre><p>So far seems to work well, and I&rsquo;m very happy to be able to do this faster now (and also more easily from my phone, should I need to).</p>
<p>Next step: Figuring out how to use that JSON file to also keep the event box on the home page updated. But that&rsquo;s for another day :)</p>
]]></content:encoded></item></channel></rss>