<?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 How to use the map command to add the total event times between created beginning and end times? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611206#M212521</link>
    <description>&lt;P&gt;I want to use the map command to add the total event times for each day during the time interval from 6am-6pm.&lt;BR /&gt;&lt;BR /&gt;For each day....&lt;BR /&gt;the "earliest" token in my map command = start of each day+6hours (Start1)&lt;BR /&gt;the "latest" token in my map command = start of each day+18 hours(End 1)&lt;BR /&gt;&lt;BR /&gt;Using the tokens I use the map command to search over my set Splunk search timeframe. In my map command...&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;1. For each day, I subtract each events&amp;nbsp; Endtime from its starttime = Diff&lt;BR /&gt;&amp;nbsp; &amp;nbsp;2. To get the total event time for each day, I sum the time differences (sum(diff)) to get&amp;nbsp;&amp;nbsp;the "total_time_of_events"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;3. Next I take the info_max_time - info_min_time for each search (for each earliest and latest token searches) to get the time value for each 12 hour day.&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; Finally I divide the total_event_time by the (search_time_span*100) for each search to get the total time percentage of events being pulled into Splunk by day&lt;BR /&gt;&lt;BR /&gt;YET it is not working!! My search returns "No results found". May I please have help? What am I doing wrong?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;CODE:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;|table BLANK hour date_mday date_month date_year&lt;BR /&gt;|bin span=1d _time&lt;BR /&gt;|eval Month=case(date_month="august","8")&lt;BR /&gt;|eval Start=Month+"/"+date_mday+"/"+date_year&lt;BR /&gt;|eval start= strptime(Start,"%m/%d/%y")&lt;BR /&gt;|&lt;STRONG&gt;eval Start1=start+21600&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;|eval End1=start+64800&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;|map search="search (index...) &lt;STRONG&gt;earliest=$Start1$ latest=$End1$ &lt;FONT color="#339966"&gt;|bin span=1d _time&lt;/FONT&gt;&lt;/STRONG&gt;|dedup _time&lt;BR /&gt;|eval timeend=strptime(DateEnd,\"%m/%d%Y %I:%M:%S %p\")&lt;BR /&gt;|eval timestart=strptime(DateStart,\"%m/%d/%Y %I:%M:%S %p\")&lt;BR /&gt;|eval diff=round(timeend-timestart)|stats sum(diff) as&amp;nbsp;total_time_of_events by BLANK&lt;BR /&gt;|addinfo |eval IntTime= info_max_time-info_min_time&lt;BR /&gt;|eval prcntUsed=round((total_time_of_events/(IntTime))*100)&lt;BR /&gt;|rename prcntUsed as Percent_of_event_time"&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 20:24:45 GMT</pubDate>
    <dc:creator>ichesla1111</dc:creator>
    <dc:date>2022-08-29T20:24:45Z</dc:date>
    <item>
      <title>How to use the map command to add the total event times between created beginning and end times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611206#M212521</link>
      <description>&lt;P&gt;I want to use the map command to add the total event times for each day during the time interval from 6am-6pm.&lt;BR /&gt;&lt;BR /&gt;For each day....&lt;BR /&gt;the "earliest" token in my map command = start of each day+6hours (Start1)&lt;BR /&gt;the "latest" token in my map command = start of each day+18 hours(End 1)&lt;BR /&gt;&lt;BR /&gt;Using the tokens I use the map command to search over my set Splunk search timeframe. In my map command...&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;1. For each day, I subtract each events&amp;nbsp; Endtime from its starttime = Diff&lt;BR /&gt;&amp;nbsp; &amp;nbsp;2. To get the total event time for each day, I sum the time differences (sum(diff)) to get&amp;nbsp;&amp;nbsp;the "total_time_of_events"&lt;BR /&gt;&amp;nbsp; &amp;nbsp;3. Next I take the info_max_time - info_min_time for each search (for each earliest and latest token searches) to get the time value for each 12 hour day.&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; Finally I divide the total_event_time by the (search_time_span*100) for each search to get the total time percentage of events being pulled into Splunk by day&lt;BR /&gt;&lt;BR /&gt;YET it is not working!! My search returns "No results found". May I please have help? What am I doing wrong?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;CODE:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;|table BLANK hour date_mday date_month date_year&lt;BR /&gt;|bin span=1d _time&lt;BR /&gt;|eval Month=case(date_month="august","8")&lt;BR /&gt;|eval Start=Month+"/"+date_mday+"/"+date_year&lt;BR /&gt;|eval start= strptime(Start,"%m/%d/%y")&lt;BR /&gt;|&lt;STRONG&gt;eval Start1=start+21600&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;|eval End1=start+64800&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;|map search="search (index...) &lt;STRONG&gt;earliest=$Start1$ latest=$End1$ &lt;FONT color="#339966"&gt;|bin span=1d _time&lt;/FONT&gt;&lt;/STRONG&gt;|dedup _time&lt;BR /&gt;|eval timeend=strptime(DateEnd,\"%m/%d%Y %I:%M:%S %p\")&lt;BR /&gt;|eval timestart=strptime(DateStart,\"%m/%d/%Y %I:%M:%S %p\")&lt;BR /&gt;|eval diff=round(timeend-timestart)|stats sum(diff) as&amp;nbsp;total_time_of_events by BLANK&lt;BR /&gt;|addinfo |eval IntTime= info_max_time-info_min_time&lt;BR /&gt;|eval prcntUsed=round((total_time_of_events/(IntTime))*100)&lt;BR /&gt;|rename prcntUsed as Percent_of_event_time"&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 20:24:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611206#M212521</guid>
      <dc:creator>ichesla1111</dc:creator>
      <dc:date>2022-08-29T20:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the map command to add the total event times between created beginning and end times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611315#M212550</link>
      <description>&lt;P&gt;generally speaking, when your search doesn't have any results, then a good approach is start at the end and remove lines until you have results.&amp;nbsp; In your case, maybe ensure the "top" search works the way you want.&amp;nbsp; And make sure the mapped search works the way you want (w/o the map, just the search,including earliest/latest formatted the same way as the vars).&amp;nbsp; And if either don't work, troubleshoot them.&amp;nbsp; If they both work, then try making the top search create a single row for testing and then troubleshoot the mapped search from there.&amp;nbsp; And then add additional rows in the top search once the mapped search works. That would be my approach at least.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that said, do you need map for this?&amp;nbsp; looks like you're just gathering stats per day and doing some calcuations from there?&amp;nbsp; seems like you could incorporate the logic from the top search into the main search the map is using?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=whatevs
| eval start=relative_time(_time,"@d+6h"), end=relative_time(_time,"@d+18h"), day=strftime(_time,"%D %T")
| where _time &amp;gt;= start AND _time &amp;lt;= end
| eval timeend=strptime(DateEnd,"%m/%d%Y %I:%M:%S %p")
| eval timestart=strptime(DateStart,"%m/%d/%Y %I:%M:%S %p")
| eval event_time = round(timeend - timestart)
| stat sum(event_time) as event_time by day&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 14:05:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611315#M212550</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2022-08-30T14:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the map command to add the total event times between created beginning and end times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611353#M212557</link>
      <description>&lt;P&gt;Thank you!!! It worked! A lot more efficient then mine hahaha.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 18:06:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-map-command-to-add-the-total-event-times-between/m-p/611353#M212557</guid>
      <dc:creator>ichesla1111</dc:creator>
      <dc:date>2022-08-30T18:06:26Z</dc:date>
    </item>
  </channel>
</rss>

