<?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: string to time and then timechart in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96353#M24892</link>
    <description>&lt;P&gt;Looks like I waited a bit too long and got second place in this race &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jul 2012 10:22:34 GMT</pubDate>
    <dc:creator>kallu</dc:creator>
    <dc:date>2012-07-12T10:22:34Z</dc:date>
    <item>
      <title>string to time and then timechart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96350#M24889</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I am trying to extract the timestamps from the log file name (source) and then find how many logs are produced at a span of 5 min - using "timechart span=5min". But i couldnt do it. It seems the timechart work only with field "_time". I have tried rename the log_time (extarcetd from the source) to _time. &lt;/P&gt;

&lt;P&gt;| eval _time=log_time&lt;/P&gt;

&lt;P&gt;But failed.............&lt;/P&gt;

&lt;P&gt;I got it correct upto "&lt;CODE&gt;| fields log_time log_type&lt;/CODE&gt;" command correctly. but the timechart seems to be failing.&lt;/P&gt;

&lt;P&gt;Also tried chart but span seems to be not working.&lt;/P&gt;

&lt;P&gt;Can any one please help me with ?&lt;/P&gt;

&lt;P&gt;source file name - &lt;/P&gt;

&lt;P&gt;/var/log/we_accesslog_extsqu_10.10.10.01_20111121_233000_32365&lt;BR /&gt;
/var/log/mms_export_e_wms_90_10.10.10.02_20111121_232500_09678&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata type=sources index="cds_*" NOT index="cds_sysl*" 
| fields source 
| dedup source 
| rex field=source "^(?P&amp;lt;path&amp;gt;[^\_]+)\/(?P&amp;lt;log_type&amp;gt;[^\/1]+)\_(?P&amp;lt;ip&amp;gt;[^\_]+)\_(?P&amp;lt;date&amp;gt;[^\_]+)\_(?P&amp;lt;time&amp;gt;[^\_]+)" 
| eval log_time=round(strptime(time, "%H%M%S"), 0) | convert timeformat="%H:%M:%S" ctime(log_time) 
| eval log_date=round(strptime(date, "%Y%m%e"), 0)  | convert timeformat="%e/%m/%Y" ctime(log_date) 
| fields log_time log_type 

| timechart span=5min count by log_type                ---------  not working

| chart count over log_time by log_type  span=5min    ---------- not working
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:03:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96350#M24889</guid>
      <dc:creator>KarunK</dc:creator>
      <dc:date>2020-09-28T12:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: string to time and then timechart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96351#M24890</link>
      <description>&lt;P&gt;What's not working with your second attempt using &lt;CODE&gt;chart&lt;/CODE&gt;? It looks OK to me, but I wonder whether you checked that your &lt;CODE&gt;log_time&lt;/CODE&gt; field was actually created correctly?&lt;/P&gt;

&lt;P&gt;I simplified your search a bit:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| metadata type=sources index="cds_*" NOT index="cds_sysl*" 
| dedup source 
| rex field=source "^(?&amp;lt;path&amp;gt;[^_]+)/(?&amp;lt;log_type&amp;gt;[^/1]+)_(?&amp;lt;ip&amp;gt;[^_]+)_(?&amp;lt;date&amp;gt;[^_]+)_(?&amp;lt;time&amp;gt;[^_]+)" 
| eval log_time=strptime(time, "%H%M%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(note that &lt;CODE&gt;log_time&lt;/CODE&gt; gets an epoch value. This way you can &lt;CODE&gt;eval&lt;/CODE&gt; it to &lt;CODE&gt;_time&lt;/CODE&gt;.)&lt;/P&gt;

&lt;P&gt;Then after that you could either use &lt;CODE&gt;timechart&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval _time=log_time | timechart span=5m count by log_type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or &lt;CODE&gt;chart&lt;/CODE&gt;, using &lt;CODE&gt;fieldformat&lt;/CODE&gt; to show a pretty timestamp instead of the actual epoch value.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| bucket log_time span=5m | fieldformat log_time=strftime(log_time, "%H:%M:%S") | chart count over log_time by log_type
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Jul 2012 09:33:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96351#M24890</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-07-12T09:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: string to time and then timechart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96352#M24891</link>
      <description>&lt;P&gt;I think the problem is you try to assign "human readable time" into _time while it should be seconds from epoch. Good news is, you already have it from strptime(), ie you don't need those "convert ..." cmds unless you want log_time and log_date for some other purposes.&lt;/P&gt;

&lt;P&gt;Maybe this would work better&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
 ... | rex field=source "^(?P&amp;lt;path&amp;gt;[^\_]+)\/(?P&amp;lt;log_type&amp;gt;[^\/1]+)\_(?P&amp;lt;ip&amp;gt;[^\_]+)\_(?P&amp;lt;datetime&amp;gt;[^\_]+\_[^\_]+)" | eval _time=strptime(datetime, "%d/%m/%Y_%H:%M:%S") | timechart span=5min count by log_type&lt;BR /&gt;
&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;If you want use only log_time (ie sum all dates into one) then bucket -cmd could help you. Simply dropping date from above example will make Splunk assume it's current date.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 10:17:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96352#M24891</guid>
      <dc:creator>kallu</dc:creator>
      <dc:date>2012-07-12T10:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: string to time and then timechart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96353#M24892</link>
      <description>&lt;P&gt;Looks like I waited a bit too long and got second place in this race &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 10:22:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/string-to-time-and-then-timechart/m-p/96353#M24892</guid>
      <dc:creator>kallu</dc:creator>
      <dc:date>2012-07-12T10:22:34Z</dc:date>
    </item>
  </channel>
</rss>

