<?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: Service down time stats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115605#M30651</link>
    <description>&lt;P&gt;Sure, this is done by using a &lt;CODE&gt;stats&lt;/CODE&gt; or &lt;CODE&gt;chart&lt;/CODE&gt; instead of &lt;CODE&gt;table&lt;/CODE&gt;, use this at the end instead of table:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| stats values(time_of_change) AS time_of_change values(last_service_status) AS last_service_status values(current_service_status)  AS current_service_status values(duration) AS duration by service&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;btw: you're welcome, please tick the tick to mark this as answered&lt;/P&gt;</description>
    <pubDate>Thu, 03 Apr 2014 18:26:05 GMT</pubDate>
    <dc:creator>MuS</dc:creator>
    <dc:date>2014-04-03T18:26:05Z</dc:date>
    <item>
      <title>Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115602#M30648</link>
      <description>&lt;P&gt;Ok guys, I'm trying to figure out how to basically create a report of service down time durations. &lt;/P&gt;

&lt;P&gt;Let say I run the report for the past 48 hours, and this report would bring up each instance and the columns of the table would look like this:&lt;BR /&gt;
outage start,outage stop,total duration (in minutes),host,service name&lt;/P&gt;

&lt;P&gt;Let's say there were two instances where services were down, and two different times in the day. &lt;/P&gt;

&lt;P&gt;The report would pull up both of them as individual rows within the table. &lt;/P&gt;

&lt;P&gt;I'm pretty sure I'm going to be using buckets somehow, but I'm searching for the easiest way to pull up each of the 'down' instances, and their duration in a table for a period of time. &lt;/P&gt;

&lt;P&gt;To give you some more information, I am just looking for a 'State' change, from 'up' to 'down' and the duration of it until the next 'up' change. I have the field extracted within each event already. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;I have tried the answer below, and it's almost what i'm after. &lt;/P&gt;

&lt;P&gt;I'm trying to keep it as simple as possible so basically i'm looking for the following fields for each 'outage'&lt;/P&gt;

&lt;P&gt;Start time, Stop Time, duration, service name. &lt;/P&gt;

&lt;P&gt;This is the query I am using:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=WMI:Service Name=&amp;lt;servicename&amp;gt; | streamstats current=false last(State) as last_service_status last(_time) as time_of_change by Name | where State!="last_service_status" | eval outage=now()-time_of_change | eval duration=strftime(outage, "%H:%M") | rename State as current_service_status | table time_of_change, Name, last_service_status, current_service_status, duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this is an image of the results. &lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://answers.splunk.com//storage/search4_2.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Is there a way to peel these fields out into a table of the 'outages' and duration's by service name? &lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2014 21:49:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115602#M30648</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2014-04-01T21:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115603#M30649</link>
      <description>&lt;P&gt;Hi tmarlette,&lt;/P&gt;

&lt;P&gt;this will be tricky to answer without knowing the real data of your events, but I show you some example. Here I assume that the events contain the following data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time, service_name, service_status
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should have a &lt;CODE&gt;time&lt;/CODE&gt; field, some service name field and at least one status field if the service is up or down.&lt;/P&gt;

&lt;P&gt;Now we start some &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.2/SearchReference/Streamstats"&gt;&lt;CODE&gt;streamstats&lt;/CODE&gt;&lt;/A&gt;-Fu:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourBaseSearchHere 
| streamstats current=false last(service_status) as last_servcie_status last(_time) as time_of_change by service_name 
| where service_status!=last_service_status 
| eval outage=now()-time_of_change 
| eval duration=strftime(outage, "%H:%M") 
| rename service_status as current_service_status 
| table time_of_change, service, last_service_status, current_service_status, duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will show a table with the time of the status changes for each service and how long the time between the status changes was, so you would get not only down time but also up times as well.&lt;/P&gt;

&lt;P&gt;Don't nail me on the two eval's for the time operations, it just an example and you would have to adapt to match your real world events.&lt;/P&gt;

&lt;P&gt;Hope this helps to get you started ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 06:22:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115603#M30649</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-02T06:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115604#M30650</link>
      <description>&lt;P&gt;Thank you sir! I will give this a shot. you are accurate in your assuming of the event data. Those are the only fields of interest for this exercise.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2014 17:35:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115604#M30650</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2014-04-03T17:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115605#M30651</link>
      <description>&lt;P&gt;Sure, this is done by using a &lt;CODE&gt;stats&lt;/CODE&gt; or &lt;CODE&gt;chart&lt;/CODE&gt; instead of &lt;CODE&gt;table&lt;/CODE&gt;, use this at the end instead of table:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| stats values(time_of_change) AS time_of_change values(last_service_status) AS last_service_status values(current_service_status)  AS current_service_status values(duration) AS duration by service&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;btw: you're welcome, please tick the tick to mark this as answered&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2014 18:26:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115605#M30651</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-04-03T18:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115606#M30652</link>
      <description>&lt;P&gt;I would, but this isn't quite answered yet. This looks like it's giving me the duration of each minute (likely because we poll once a minute). I think I have to massage this a bit still in order to get what I'm looking for. Every minute is too much data for suits to look at, and i'm attempting to appease them.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2014 21:18:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115606#M30652</guid>
      <dc:creator>tmarlette</dc:creator>
      <dc:date>2014-04-11T21:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Service down time stats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115607#M30653</link>
      <description>&lt;P&gt;Try this (add rename at the end per your need)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search  | streamstats current=false last(State) as last_service_status last(_time) as time_of_down by Name,host | where State!=last_service_status AND NOT State="Down" | streamstats current=false last(_time) as time_of_up by Name,host  | where isnotnull(time_of_up) | eval duration=time_of_up - time_of_down | convert ctime(time_of_*) | table host, Name, time_of_*,duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Apr 2014 21:45:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Service-down-time-stats/m-p/115607#M30653</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-04-11T21:45:54Z</dc:date>
    </item>
  </channel>
</rss>

