<?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 timechart day offset in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/timechart-day-offset/m-p/28731#M5717</link>
    <description>&lt;P&gt;I am trying to run a timechart against a summary index (the summary is populated once an hour) and split into 24 hour segments:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary search_name=my_summary earliest=-30d@h latest=@h
| timechart span=24h count by target
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I set &lt;STRONG&gt;span=1d&lt;/STRONG&gt; the buckets are split at midnight. I really want them to be split into 24 hour buckets that align with the search when run though... whether I set &lt;STRONG&gt;span=24h&lt;/STRONG&gt; or &lt;STRONG&gt;span=1440m&lt;/STRONG&gt; or &lt;STRONG&gt;span=86400s&lt;/STRONG&gt; though, the segment is split at &lt;STRONG&gt;8pm&lt;/STRONG&gt; each day (regardless of when the search is run), resulting in 31 bins (29 with 24 events per target, and 2 with whatever adds up to 24 (11+13 for instance) at the beginning and end of the span.&lt;/P&gt;

&lt;P&gt;I've also tried &lt;STRONG&gt;bins=30&lt;/STRONG&gt; by itself (2 bins split at month markers) and &lt;STRONG&gt;span=24h bins=30&lt;/STRONG&gt; (bins ignored).&lt;/P&gt;

&lt;P&gt;Splunk 4.3&lt;/P&gt;

&lt;P&gt;Any thoughts or sanity checks welcome and appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2013 13:42:39 GMT</pubDate>
    <dc:creator>jeff</dc:creator>
    <dc:date>2013-05-09T13:42:39Z</dc:date>
    <item>
      <title>timechart day offset</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-day-offset/m-p/28731#M5717</link>
      <description>&lt;P&gt;I am trying to run a timechart against a summary index (the summary is populated once an hour) and split into 24 hour segments:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=summary search_name=my_summary earliest=-30d@h latest=@h
| timechart span=24h count by target
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I set &lt;STRONG&gt;span=1d&lt;/STRONG&gt; the buckets are split at midnight. I really want them to be split into 24 hour buckets that align with the search when run though... whether I set &lt;STRONG&gt;span=24h&lt;/STRONG&gt; or &lt;STRONG&gt;span=1440m&lt;/STRONG&gt; or &lt;STRONG&gt;span=86400s&lt;/STRONG&gt; though, the segment is split at &lt;STRONG&gt;8pm&lt;/STRONG&gt; each day (regardless of when the search is run), resulting in 31 bins (29 with 24 events per target, and 2 with whatever adds up to 24 (11+13 for instance) at the beginning and end of the span.&lt;/P&gt;

&lt;P&gt;I've also tried &lt;STRONG&gt;bins=30&lt;/STRONG&gt; by itself (2 bins split at month markers) and &lt;STRONG&gt;span=24h bins=30&lt;/STRONG&gt; (bins ignored).&lt;/P&gt;

&lt;P&gt;Splunk 4.3&lt;/P&gt;

&lt;P&gt;Any thoughts or sanity checks welcome and appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 13:42:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-day-offset/m-p/28731#M5717</guid>
      <dc:creator>jeff</dc:creator>
      <dc:date>2013-05-09T13:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: timechart day offset</title>
      <link>https://community.splunk.com/t5/Splunk-Search/timechart-day-offset/m-p/28732#M5718</link>
      <description>&lt;P&gt;You may be able to do this mathematically by decomposing &lt;CODE&gt;timechart&lt;/CODE&gt; and manipulating &lt;CODE&gt;_time&lt;/CODE&gt; somewhere in the middle.&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;timechart&lt;/CODE&gt; command is very close to this sequence of individual commands:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | bucket span=XX _time | chart count over _time by target
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It is the &lt;CODE&gt;bucket&lt;/CODE&gt; command (or its equivalent within &lt;CODE&gt;timechart&lt;/CODE&gt;) that is "rounding down" to the nearest value of &lt;CODE&gt;span&lt;/CODE&gt;.  What you may be able to do is something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | bucket span=1h _time 
| addinfo
| &amp;lt;STUFF&amp;gt;
| timechart span=1d count by target
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The "STUFF" is the tricky part. You'll need to do some &lt;CODE&gt;eval&lt;/CODE&gt; magic to add-or-subtract from &lt;CODE&gt;_time&lt;/CODE&gt; to shift events forward or backward in time.  The &lt;CODE&gt;addinfo&lt;/CODE&gt; command will introduce a couple of new fields to assist with this, specifically &lt;CODE&gt;info_search_time&lt;/CODE&gt; which will be a &lt;CODE&gt;time_t&lt;/CODE&gt; type value (seconds since 1970) of when the search was started.&lt;/P&gt;

&lt;P&gt;So, the "STUFF" might start out something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval hour_of_search=strftime("%H",info_search_time)
| eval hour_of_time=strftime("%H",_time)
| eval hourshift=if(hour_of_time &amp;gt; hour_of_search,(24-hour_of_search),0)
| eval _time=_time + hourshift*3600
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note I have no idea if the algebra there is right or not.  It's just to demonstrate the general idea that &lt;CODE&gt;_time&lt;/CODE&gt; is mutable, and if you can mathematically work out how to get what you want you can fuzz events forward or backward in time as needed to put them in the "same day" as you define your day.&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2013 15:03:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/timechart-day-offset/m-p/28732#M5718</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2013-05-09T15:03:44Z</dc:date>
    </item>
  </channel>
</rss>

