<?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: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258835#M77565</link>
    <description>&lt;P&gt;Try like this (run anywhere sample, adjust per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=_internal sourcetype=* earliest=-12h@h by _time sourcetype span=1h | eval period=floor((now()-_time)/3600) | eval period=if(period=0,"Now","-".period."h" )| chart limit=0 sum(count) over sourcetype by period | table sourcetype Now "-1h" "-2h" "-3h"...list all other hours. needed this table command for sorting of columns...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt;&lt;BR /&gt;
To use the table command with dynamic name of fields for hour bins. This requires that the time range is set in the time-range picker and not provided in-line in the search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=_internal sourcetype=* by _time sourcetype span=1h | eval period=floor((now()-_time)/3600) | eval period=if(period=0,"Now","-".period."h") | chart limit=0 sum(count) over sourcetype by period | table sourcetype [| gentimes start=-1 | addinfo | eval t=mvrange(info_min_time,info_max_time,3600) | table t | mvexpand t | eval t=floor((now()-t)/3600) | reverse| eval t=if(t=0,"Now","-".t."h") | stats list(t) as search delim="," | nomv search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Jan 2017 17:13:13 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-01-24T17:13:13Z</dc:date>
    <item>
      <title>How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258834#M77564</link>
      <description>&lt;P&gt;Is it possible to write a search to show &lt;STRONG&gt;count values per hour '_time' bins&lt;/STRONG&gt; for the last 12 hours &lt;STRONG&gt;as columns&lt;/STRONG&gt;, sorted by a specific field.  I also need to do this via tstats. What I want would look like the following...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Field  | Now    | -1h    | -2h    | -3h    | -4h    | -5h    | ...
value1 | count0 | count1 | count2 | count3 | count4 | count5 | ...
value2 | count0 | count1 | count2 | count3 | count4 | count5 | ...
value3 | count0 | count1 | count2 | count3 | count4 | count5 | ...
value4 | count0 | count1 | count2 | count3 | count4 | count5 | ...
value5 | count0 | count1 | count2 | count3 | count4 | count5 | ...
...    | ...    | ...    | ...    | ...    | ...    | ...    | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2017 17:02:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258834#M77564</guid>
      <dc:creator>matthewb4</dc:creator>
      <dc:date>2017-01-24T17:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258835#M77565</link>
      <description>&lt;P&gt;Try like this (run anywhere sample, adjust per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=_internal sourcetype=* earliest=-12h@h by _time sourcetype span=1h | eval period=floor((now()-_time)/3600) | eval period=if(period=0,"Now","-".period."h" )| chart limit=0 sum(count) over sourcetype by period | table sourcetype Now "-1h" "-2h" "-3h"...list all other hours. needed this table command for sorting of columns...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt;&lt;BR /&gt;
To use the table command with dynamic name of fields for hour bins. This requires that the time range is set in the time-range picker and not provided in-line in the search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=_internal sourcetype=* by _time sourcetype span=1h | eval period=floor((now()-_time)/3600) | eval period=if(period=0,"Now","-".period."h") | chart limit=0 sum(count) over sourcetype by period | table sourcetype [| gentimes start=-1 | addinfo | eval t=mvrange(info_min_time,info_max_time,3600) | table t | mvexpand t | eval t=floor((now()-t)/3600) | reverse| eval t=if(t=0,"Now","-".t."h") | stats list(t) as search delim="," | nomv search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jan 2017 17:13:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258835#M77565</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-24T17:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258836#M77566</link>
      <description>&lt;P&gt;so do I need to change sourcetype in this case to my desired field name? I'm using a datamodel&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 17:20:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258836#M77566</guid>
      <dc:creator>matthewb4</dc:creator>
      <dc:date>2017-01-24T17:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258837#M77567</link>
      <description>&lt;P&gt;yes... you would need to change the WHERE clause to use your data model as well. The use of _time and span shoudl remain same.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 17:42:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258837#M77567</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-24T17:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258838#M77568</link>
      <description>&lt;P&gt;Is there any way I could make the last part (static strings)  &lt;STRONG&gt;dynamic&lt;/STRONG&gt; (Now "-1h" "-2h" "-3h"...) so that if I use this query for a dashboard and have inputs for either bin or earliest, it could change these on the fly?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 18:07:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258838#M77568</guid>
      <dc:creator>matthewb4</dc:creator>
      <dc:date>2017-01-24T18:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258839#M77569</link>
      <description>&lt;P&gt;If you don't do that, the sort order would be different. It'll show columns &lt;CODE&gt;sourcetype Now -1h -10h -11h -12h -2h -3h -4h...&lt;/CODE&gt;. If thats ok, you can replace last table command with &lt;CODE&gt;| table sourcetype Now *&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 19:04:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258839#M77569</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-24T19:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258840#M77570</link>
      <description>&lt;P&gt;Well I was thinking there might be a way to do it with a for each loop or something like it to append the period values together to create a giant string then use that as the parameters in the table command (which would be in correct order)... but i couldn't get it to work, idk&lt;/P&gt;

&lt;P&gt;Only reason I ask is because if I want different time bins or to go back further than 12h I wouldn't want to have to re-edit the dashboard's query every time, I would want to use inputs for this.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 19:22:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258840#M77570</guid>
      <dc:creator>matthewb4</dc:creator>
      <dc:date>2017-01-24T19:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to show count values per hour _time bins for the last 12 hours as columns, sorted by a specific field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258841#M77571</link>
      <description>&lt;P&gt;How about you give updated answer a try.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2017 20:02:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-show-count-values-per-hour-time-bins/m-p/258841#M77571</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-01-24T20:02:46Z</dc:date>
    </item>
  </channel>
</rss>

