<?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: Get Latest event per month? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322817#M96380</link>
    <description>&lt;P&gt;Good catch, I only tested the first part of my suggestion and then combined it with what TISKAR had, it should indeed be stats by month, not date_month in my suggestion. I've updated the code in my post.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Apr 2018 14:58:12 GMT</pubDate>
    <dc:creator>FrankVl</dc:creator>
    <dc:date>2018-04-09T14:58:12Z</dc:date>
    <item>
      <title>Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322801#M96364</link>
      <description>&lt;P&gt;I am trying to show a graph of the latest events per month. My search query is: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=1month latest(availability) by application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I thought this would grab the latest availability of the applications per month but its not grabbing the latest event for each month. The events are produced every day to get up to date information on availabilities so I want to show the latest to graph per month ( I want to graph it having the x-axis be the month and the lines being each application, showing the latest availability per month so its up to date). Is there a way to dedup per month? Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322801#M96364</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T13:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322802#M96365</link>
      <description>&lt;P&gt;I'm not sure I understand your end goal entirely, but if you want a stats table with the latest value for the field &lt;CODE&gt;availability&lt;/CODE&gt; by &lt;CODE&gt;application&lt;/CODE&gt; from each month, this should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(availability) AS availability BY application, date_month
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:44:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322802#M96365</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T13:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322803#M96366</link>
      <description>&lt;P&gt;my end goal it to show a graph that spans per month and shows the applications availability per month. so i want to do a timechart function&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 13:48:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322803#M96366</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T13:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322804#M96367</link>
      <description>&lt;P&gt;Those stats give me the correct numbers but I want to graph it having the x-axis be the month and the lines being each application&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:30:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322804#M96367</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T14:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322805#M96368</link>
      <description>&lt;P&gt;Is availability a number?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322805#M96368</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T14:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322806#M96369</link>
      <description>&lt;P&gt;yes it is a number&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:36:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322806#M96369</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T14:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322807#M96370</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;You can Try this,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats latest(availability) AS availability BY application, date_month
| xyseries date_month application availability  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:42:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322807#M96370</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-06T14:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322808#M96371</link>
      <description>&lt;P&gt;Great, then the answer @TISKAR provided below should work!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:47:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322808#M96371</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T14:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322809#M96372</link>
      <description>&lt;P&gt;By "latest event per month" do you mean the one that application last ran before the end of the month?  Because that's what your code is trying to do.&lt;/P&gt;

&lt;P&gt;Honestly, I don't think you are presenting any useful information.  An application that was unavailable on every day of March up until the 30th, but was available on March 31 would show availability on the 31st.  &lt;/P&gt;

&lt;P&gt;So what?  It was down most of the month.&lt;/P&gt;

&lt;P&gt;You probably want to show how MANY days the application was available, possibly as a percentage.&lt;/P&gt;

&lt;P&gt;That would go something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rename COMMENT as "always limit the search to the fields you need.  _time is internal, so it doesn't need to be listed."
| fields application
| bin _time span=1d

| rename COMMENT as "first we count up the number of records for each application for each day"
| stats count as mycount by _time application

| rename COMMENT as "now we add one zero record for each application for each day"
| appendpipe 
   [| stats min(_time) as mintime max(_time) as maxtime by application
    | eventstats min(mintime) as mintime max(maxtime) as maxtime
    | eval maxtime=maxtime+1
    | eval mycount=0      
    | eval myfan=mvrange(mintime,maxtime,86400)
    | mvexpand myfan
    | rename myfan as _time
    | table _time application mycount
    ]

| rename COMMENT as "now we stats again so that there is only one record for each application for each day"
| stats sum(mycount) as mycount by _time application

| rename COMMENT as "now we are ready to count monthly percentages.  We will present in whole numbers."
| rename COMMENT as "so we set the daily value to zero or 100, then round the result."
| eval mycount=if(mycount&amp;gt;0,100,0)
| bin _time span=1mon
| stats avg(mycount) as Monthly_Uptime_Percent by _time application
| eval Monthly_Uptime_Percent=round(Monthly_Uptime_Percent,0)

| rename COMMENT as "for presentation, you could use a timechart with a line for each application"
| timechart span=1mon max(Monthly_Uptime_Percent) by application
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you wanted to present the user with a stacked chart of the number of uptime days versus downtime days, you could do something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename COMMENT as "now we are ready to count monthly up or down days.  We will set available based on whether there were any records found."
| eval available=if(mycount&amp;gt;0,"up","down")
| bin _time span=1mon
| stats count as Monthly_Uptime_Count by _time application available

| rename COMMENT as "I would tend to show this using trellis, one panel per application, with a stacked bar chart"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:50:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322809#M96372</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-04-06T14:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322810#M96373</link>
      <description>&lt;P&gt;sorry i shouldve been more clear, availability is a percentage. its not a number that means up or down. its a percentage that is calculated every day to determine that app's availability 0-100%. so the numbers change every day based on if it was up or down. starts at 100 then decreases if there was an outage. so an application will always have an availability percentage because it resets to 100 every day to calculate the availability for today then we can calculate for the month. so the way the query is set up is its showing the availability total for the month based on the past however days the month has had and i want to graph by the month so i wanted to grab the latest calculation because that is the final availability calculation per app per month if that makes sense&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 16:22:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322810#M96373</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T16:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322811#M96374</link>
      <description>&lt;P&gt;For some reason when I do this the months are not in normal order. They're all out of order for some reason. Do you know why this is? thanks!!!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 17:49:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322811#M96374</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T17:49:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322812#M96375</link>
      <description>&lt;P&gt;Theres a query im running in the background to calculate the availability for the current month based on the previous days. so the availability for today is from April 1-6th and its a percentage. So im trying to grab the latest for that month so that on the graph for april, itll show whatever the latest is so the availability that was calculated for today (april 6th) and the previous months should be the last day of the moth but, its not grabbing the latest. it looks like its grabbing the first of each month&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 17:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322812#M96375</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-06T17:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322813#M96376</link>
      <description>&lt;P&gt;They are probably being sorted alphabetically. &lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 19:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322813#M96376</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T19:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322814#M96377</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;Yes you can use this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | eval month=strftime(_time,"%m")
    | eval date_month=month."-".date_month
    | stats latest(availability) AS availability BY application, date_month
    | xyseries date_month application availability  
    | rex field=date_month mode=sed "s/(\d+-)//g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Apr 2018 09:16:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322814#M96377</guid>
      <dc:creator>TISKAR</dc:creator>
      <dc:date>2018-04-09T09:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322815#M96378</link>
      <description>&lt;P&gt;Rather than concatenating and then stripping again, a more elegant solution would be to use the &lt;CODE&gt;fieldformat&lt;/CODE&gt; command, to show the text value, while keeping the numerical month value under the hood for the sorting.&lt;/P&gt;

&lt;P&gt;So:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval month=strftime(_time,"%m-%B")
| fieldformat month=substr(month,4)
| stats latest(availability) AS availability BY application, month
| xyseries month application availability
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Apr 2018 10:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322815#M96378</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-09T10:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322816#M96379</link>
      <description>&lt;P&gt;@FrankVI , you never use the month variable in the stats? I assumed it was supposed to be month instead of date_month because that query didnt work. Using the month it puts it from January-December but I want the latest month on the right to be the current month. Sorry please let me know if you have any suggestions.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 14:43:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322816#M96379</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-09T14:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322817#M96380</link>
      <description>&lt;P&gt;Good catch, I only tested the first part of my suggestion and then combined it with what TISKAR had, it should indeed be stats by month, not date_month in my suggestion. I've updated the code in my post.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 14:58:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322817#M96380</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-09T14:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322818#M96381</link>
      <description>&lt;P&gt;@FrankVI ok but im still running into the issue that its displaying January-December when I would like it to display the current month last. So have the graph show May-April&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 15:42:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322818#M96381</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-09T15:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322819#M96382</link>
      <description>&lt;P&gt;Right, that should be a matter of adding the year into the month field (and then stripping that off again in the fieldformat). Eg:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval month=strftime(_time,"%Y%m-%B")
 | fieldformat month=substr(month,8)
 | stats latest(availability) AS availability BY application, month
 | xyseries month application availability
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Apr 2018 15:50:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322819#M96382</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2018-04-09T15:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Get Latest event per month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322820#M96383</link>
      <description>&lt;P&gt;Thanks so much! this worked! if you want to put this as an answer so I can accept it thatd be great!&lt;/P&gt;</description>
      <pubDate>Mon, 09 Apr 2018 17:49:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Get-Latest-event-per-month/m-p/322820#M96383</guid>
      <dc:creator>kdimaria</dc:creator>
      <dc:date>2018-04-09T17:49:06Z</dc:date>
    </item>
  </channel>
</rss>

