<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help optimising a query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469830#M132202</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 
| streamstats count 
| eval _time=relative_time(_time,-1*count."d@d") 
| makecontinuous _time span=45min 
| eval count=random() % 6, monitor.name=mvindex(split("A,B,C,D,E,F",","),count), monitor.status=mvindex(split("up,down",","),(count % 2)) 
| rename COMMENT as "this is sample data. check this. from here, the logic"
| stats latest(monitor.status) as status BY monitor.name 
| stats count as "TOTAL" count(eval(status=="up")) as "UP" count(eval(status=="down")) as "DOWN" values(eval("value")) as fn 
| transpose header_field=fn column_name=category 
| eval color = case(category=="TOTAL", "#006d9c", category=="UP", "#00AA00",category=="DOWN", "#dc4e41") 
| eval icon = case(category=="TOTAL", "server", category=="UP", "check", category=="DOWN", "times-circle") 
| eval sorter = case(category=="TOTAL", 1, category=="UP", 2, category=="DOWN", 3) 
| stats last(value) as value last(icon) as icon last(color) as color last(sorter) as sorter by category
| sort sorter
| fields - sorter
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, your query is good. There are not many changes.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;the Status Indicator visualisation to show a Trellis view&lt;/CODE&gt;&lt;BR /&gt;
&lt;EM&gt;Trellis&lt;/EM&gt; visualization needs aggregation.( &lt;CODE&gt;stats&lt;/CODE&gt; , &lt;CODE&gt;chart&lt;/CODE&gt; , &lt;CODE&gt;timechart&lt;/CODE&gt;)&lt;/P&gt;</description>
    <pubDate>Wed, 08 Apr 2020 19:54:10 GMT</pubDate>
    <dc:creator>to4kawa</dc:creator>
    <dc:date>2020-04-08T19:54:10Z</dc:date>
    <item>
      <title>Help optimising a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469829#M132201</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;

&lt;P&gt;I'm fairly new to Splunk, and still very much learning (its a small hobby), and I recently found Elastic Beats works great for monitoring my home servers and network, then to add a cherry, the output is easily imported into Splunk.  I've got it running some ICMP PINGs against my network interfaces, and in its simplest form, generates data such as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;NAME   STATUS  PING 
site1  up      10
site2  up      10
site2  down    0
site3  up      10
site1  down    10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm using the Status Indicator visualisation to show a Trellis view of Total Devices, Total Up, Total Down. I've hacked together the following query, which works, but there has got to be a more optimised way of doing this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="beats" "monitor.type"=icmp "tags{}"=external 
| stats latest(monitor.name) as name 
        latest(monitor.status) as status 
        BY monitor.name

| stats count(name) as "   TOTAL"
        sum(eval(if(status=="up",1,0))) as "  UP"
        sum(eval(if(status=="down",1,0))) as    " DOWN"

| eval fn = "value"
| transpose column_name="category" header_field=fn

| eval color = if(category=="   TOTAL", "#006d9c", if(category=="  UP", "#00AA00", "#dc4e41"))
| eval icon = if(category=="   TOTAL", "server", if(category=="  UP", "check", "times-circle"))
| sort category
| stats last(value) as value  last(icon) as icon last(color) as color by category
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which effective does the following:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Pull back the latest record for each unique "monitor.name"&lt;/LI&gt;
&lt;LI&gt;Then counts the Total, Total Up, Total Down (Note spaces in the as-names, a hack so I can sort them into a desired order (Total -&amp;gt; UP -&amp;gt; Down)&lt;/LI&gt;
&lt;LI&gt;The above totals are columns, so I transpose to a list with "category" (aka name) and "value"&lt;/LI&gt;
&lt;LI&gt;Use EVAL to set the colour and icons for the visualisation&lt;/LI&gt;
&lt;LI&gt;Sort into the order I want (Total -&amp;gt; UP -&amp;gt; Down)&lt;/LI&gt;
&lt;LI&gt;Then re-apply stats - I honestly don't know why this is needed, but without it, the Status Indicator visualisation doesn't work, though looking at the statistics tab, the results are exactly the same without it&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I'd really appreciate any advise on how I could re-work this, improve it, also any insight into why step 6 appears to be needed.&lt;/P&gt;

&lt;P&gt;Many Thanks&lt;BR /&gt;
K&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 01:25:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469829#M132201</guid>
      <dc:creator>kwestlake</dc:creator>
      <dc:date>2020-04-08T01:25:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help optimising a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469830#M132202</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=2 
| streamstats count 
| eval _time=relative_time(_time,-1*count."d@d") 
| makecontinuous _time span=45min 
| eval count=random() % 6, monitor.name=mvindex(split("A,B,C,D,E,F",","),count), monitor.status=mvindex(split("up,down",","),(count % 2)) 
| rename COMMENT as "this is sample data. check this. from here, the logic"
| stats latest(monitor.status) as status BY monitor.name 
| stats count as "TOTAL" count(eval(status=="up")) as "UP" count(eval(status=="down")) as "DOWN" values(eval("value")) as fn 
| transpose header_field=fn column_name=category 
| eval color = case(category=="TOTAL", "#006d9c", category=="UP", "#00AA00",category=="DOWN", "#dc4e41") 
| eval icon = case(category=="TOTAL", "server", category=="UP", "check", category=="DOWN", "times-circle") 
| eval sorter = case(category=="TOTAL", 1, category=="UP", 2, category=="DOWN", 3) 
| stats last(value) as value last(icon) as icon last(color) as color last(sorter) as sorter by category
| sort sorter
| fields - sorter
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, your query is good. There are not many changes.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;the Status Indicator visualisation to show a Trellis view&lt;/CODE&gt;&lt;BR /&gt;
&lt;EM&gt;Trellis&lt;/EM&gt; visualization needs aggregation.( &lt;CODE&gt;stats&lt;/CODE&gt; , &lt;CODE&gt;chart&lt;/CODE&gt; , &lt;CODE&gt;timechart&lt;/CODE&gt;)&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 19:54:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469830#M132202</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-04-08T19:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help optimising a query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469831#M132203</link>
      <description>&lt;P&gt;Thank you - Especially for the explanation on the Trellis.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 13:09:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-optimising-a-query/m-p/469831#M132203</guid>
      <dc:creator>kwestlake</dc:creator>
      <dc:date>2020-04-14T13:09:30Z</dc:date>
    </item>
  </channel>
</rss>

