<?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: Including Indextime in Table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24657#M4574</link>
    <description>&lt;P&gt;First, you do have a timestamp. Splunk &lt;EM&gt;always&lt;/EM&gt; creates a timestamp. If there is no timestamp in the events, Splunk will use the file mod time as the timestamp. If there is no file mod time (for example in a scripted input), Splunk will use the index time. &lt;/P&gt;

&lt;P&gt;Second, I think your searches are more complicated than they need to be. Try these instead:&lt;BR /&gt;&lt;BR /&gt;
Single search:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="D:\testing\*" earliest=-30m@m | stats count as Count by sourcetype | eval Count=Count-1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Combined search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="D:\testing\*" earliest=-30m@m 
| stats count as Count latest(_time) as LatestTime by sourcetype source
| sort -LatestTime
| dedup sourcetype
| eval Count=Count-1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The second search calculates the event count and timestamp for every file (assuming there will be multiple files per sourcetype). It then sorts the table with the most recent sources first. &lt;CODE&gt;dedup&lt;/CODE&gt; keeps only the first (therefore most recent) entry for each sourcetype.&lt;/P&gt;

&lt;P&gt;BTW, the &lt;CODE&gt;count&lt;/CODE&gt; function in the &lt;CODE&gt;stats&lt;/CODE&gt; command will work great if your text file has one-line-per-event, and it is very efficient. However, if you have multi-line events. you can replace "&lt;CODE&gt;count as Count&lt;/CODE&gt;" with "&lt;CODE&gt;sum(linecount) as Count&lt;/CODE&gt;" in order to count actual lines instead of events.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Feb 2013 08:05:58 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-02-08T08:05:58Z</dc:date>
    <item>
      <title>Including Indextime in Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24656#M4573</link>
      <description>&lt;P&gt;I am a fairly new Splunk user..I have 5 different source types.  Each sourcetype represents a unique txt file that generates every half hour. Each of the five txt files are written to subdirectories of D:\testing\. IE, D:\testing\subdir1, D:\testing\subdir2, etc.&lt;/P&gt;

&lt;P&gt;I need to accomplish 4 goals:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Search only the last log file that generated for each &lt;STRONG&gt;Sourcetype&lt;/STRONG&gt; (the -30m&amp;amp;m time timeframe). &lt;/LI&gt;
&lt;LI&gt;Count the number of &lt;STRONG&gt;Lines&lt;/STRONG&gt; in each file (subtracting 1 line from each).&lt;/LI&gt;
&lt;LI&gt;Identify the &lt;STRONG&gt;Indextime&lt;/STRONG&gt; for each of the 5 log files.&lt;/LI&gt;
&lt;LI&gt;Display &lt;STRONG&gt;"Sourcetype"&lt;/STRONG&gt;, &lt;STRONG&gt;"Count"&lt;/STRONG&gt;, and &lt;STRONG&gt;"Indextime"&lt;/STRONG&gt; in one table (sorted by count) for a total of 5 rows and 3 colums of data.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;STRONG&gt;Search #1&lt;/STRONG&gt; - Displays &lt;STRONG&gt;Sourcetype&lt;/STRONG&gt; and &lt;STRONG&gt;Count&lt;/STRONG&gt; in a table with no problems.  &lt;/P&gt;

&lt;P&gt;earliest=-30m@m | search source="D:\\testing\\*" | stats sum(linecount) as "linecount" by sourcetype | eval Count=linecount-1 | sort 0 - "Count" | table "sourcetype" "Count"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Search #2&lt;/STRONG&gt; - Displays &lt;STRONG&gt;Sourcetype&lt;/STRONG&gt; and &lt;STRONG&gt;Indextime&lt;/STRONG&gt; in a table with no problems.&lt;/P&gt;

&lt;P&gt;earliest=-30m@m | search source="D:\\testing\\*" | eval "Indextime"=strftime(_indextime,"%+")| table "sourcetype" "Indextime"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Search #3&lt;/STRONG&gt; - When I try to combine both searches into one, I get results similar to Search #1 but with no data in the Indextime column.&lt;/P&gt;

&lt;P&gt;earliest=-30m@m | search source="D:\\testing\\*" | stats sum(linecount) as "linecount" by sourcetype | eval Count=linecount-1 | eval "Indextime"=strftime(_indextime,"%+") | sort 0 "Count" | table "sourcetype" "Count" "Indextime"&lt;/P&gt;

&lt;P&gt;I've been struggling with this for a couple of days and would appreciate it if someone could help me come up with a solution that I can try.&lt;/P&gt;

&lt;P&gt;Note that I have no choice but to use Indextime because there are no timestamps in these txt files.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2013 01:38:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24656#M4573</guid>
      <dc:creator>dbastidas</dc:creator>
      <dc:date>2013-02-08T01:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Including Indextime in Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24657#M4574</link>
      <description>&lt;P&gt;First, you do have a timestamp. Splunk &lt;EM&gt;always&lt;/EM&gt; creates a timestamp. If there is no timestamp in the events, Splunk will use the file mod time as the timestamp. If there is no file mod time (for example in a scripted input), Splunk will use the index time. &lt;/P&gt;

&lt;P&gt;Second, I think your searches are more complicated than they need to be. Try these instead:&lt;BR /&gt;&lt;BR /&gt;
Single search:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="D:\testing\*" earliest=-30m@m | stats count as Count by sourcetype | eval Count=Count-1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Combined search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="D:\testing\*" earliest=-30m@m 
| stats count as Count latest(_time) as LatestTime by sourcetype source
| sort -LatestTime
| dedup sourcetype
| eval Count=Count-1 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The second search calculates the event count and timestamp for every file (assuming there will be multiple files per sourcetype). It then sorts the table with the most recent sources first. &lt;CODE&gt;dedup&lt;/CODE&gt; keeps only the first (therefore most recent) entry for each sourcetype.&lt;/P&gt;

&lt;P&gt;BTW, the &lt;CODE&gt;count&lt;/CODE&gt; function in the &lt;CODE&gt;stats&lt;/CODE&gt; command will work great if your text file has one-line-per-event, and it is very efficient. However, if you have multi-line events. you can replace "&lt;CODE&gt;count as Count&lt;/CODE&gt;" with "&lt;CODE&gt;sum(linecount) as Count&lt;/CODE&gt;" in order to count actual lines instead of events.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2013 08:05:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24657#M4574</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-02-08T08:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Including Indextime in Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24658#M4575</link>
      <description>&lt;P&gt;I was looking to use linecount, since one txt file=one event.  You lead me in the right direction, thanks!  Here is the search that I used that allowed me to accomplishes all 4 goals.&lt;/P&gt;

&lt;P&gt;earliest=-30m@m | search source="D:\testing\*"&lt;BR /&gt;
| stats sum(linecount) as Count latest(_time) as LatestTime by sourcetype&lt;BR /&gt;
| sort -Count&lt;BR /&gt;
| dedup sourcetype&lt;BR /&gt;
| eval Count=Count-1&lt;BR /&gt;
| eval Timestamp=strftime(LatestTime,"%D %H:%M %Z") &lt;BR /&gt;
| table sourcetype Count Timestamp&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2013 20:39:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24658#M4575</guid>
      <dc:creator>dbastidas</dc:creator>
      <dc:date>2013-02-08T20:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: Including Indextime in Table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24659#M4576</link>
      <description>&lt;P&gt;You are not getting the latest count, you are getting the largest count. Look at your sort command. If that's what you want, then okay. But to test it, run the command with and without the &lt;CODE&gt;dedup&lt;/CODE&gt; in it. You can see that the sorting will be largest count first, and &lt;CODE&gt;dedup&lt;/CODE&gt; keeps the first event and discards the rest of the same sourcetype...&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 08:51:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Including-Indextime-in-Table/m-p/24659#M4576</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-02-14T08:51:34Z</dc:date>
    </item>
  </channel>
</rss>

