Reporting when Logging only the start and end of an outage condition

In a previous post, I had a system to only log the start and end of an outage condition.  To report on the outages, we need to first look at the table where the exceptions get logged:

    CREATE TABLE [dbo].[Exceptions](
        [ExTime] [datetime] NULL CONSTRAINT [DF_Exceptions_ExTime]  
                        DEFAULT (getdate()),
        [Message] [varchar](8000) NULL,
        [StackTrace] [varchar](8000) NULL
      ) ON [PRIMARY]

And a sample of the data:

        SELECT TOP 12 ExTime, Substring(Message,1,60) Message
        FROM Exceptions

 

                  ExTimeMessage
5/5/09 13:21Outage start of error, ErrorGuid: 595f890d-c337-49
5/5/09 13:28Outage end of error, ErrorGuid: 595f890d-c337-493f
5/11/09 18:08dbo.processRequestAll|Thread was being aborted.
5/12/09 14:13The actual number of records in insert did not match the exp
5/15/09 13:00Data Feed FAILED at 5/15/2009 1:00:04 PM
5/15/09 13:00Data Feed Error occurred at 5/15/2009 1:00:04 PM
5/22/09 18:10dbo.saveXML|The DELETE statement conflicted 
5/26/09 11:14The actual number of records in insert did not match the exp
6/3/09 6:39Outage start of error, ErrorGuid: c1c430f0-9a8f-4f
6/3/09 6:41Outage end of error, ErrorGuid: c1c430f0-9a8f-4fca
6/3/09 12:36Outage start of error, ErrorGuid: 06de0545-d152-44
6/3/09 12:39Outage end of error, ErrorGuid: 06de0545-d152-4438

Now, to do the reporting, we create a temp table with just the records we are interested in:

           select ExTime,
           case when charindex('start of',Message) > 0 then 'S'
           else 'E' end a,
           substring(Message,charindex('Guid',Message)+5,40) g  
           into #t
           from Exceptions
           where Message like 'Outage%'

The first column (badly named “a”) is just a flag to say if it is a Start or End record.  The second column (named “g”) is the Guid for the outage event.    

Now create another temp table where the GUID is summarized:

        select g, max(case when a = 'S' then ExTime end) startTime,
        max(case when a = 'E' then ExTime end) endTime into #t2
        from #t
        group by g
        having count(1) = 2

Now we can report on this.

           select startTime,
           CASE DATEPART(weekday,startTime)
           WHEN 1 THEN 'Sunday'
           WHEN 2 THEN 'Monday'
           WHEN 3 THEN 'Tuesday'
           WHEN 4 THEN 'Wednesday'
           WHEN 5 THEN 'Thursday'
           WHEN 6 THEN 'Friday'
           WHEN 7 THEN 'Saturday'
           END,
           round((datediff(ss,startTime,endTime)+0.0)/60,2) Minutes
           from  #t2 t
           where not exists
           (     select 1
                 from #t2 tin
                 where t.startTime between tin.startTime and tin.endTime
                 and t.g <> tin.g)
          and startTime > '05/13/09'
          order by startTime

  This gives us the following report that shows us the start time of the outage and how many minutes it lasted:

 

               StartTimeDay    Minutes
5/27/09 14:38Wednesday9.53
5/28/09 10:06Thursday9.68
5/28/09 13:21Thursday4.52
5/28/09 23:18Thursday9.64
5/30/09 13:21Saturday3.85

Leave a Comment

Your email address will not be published. Required fields are marked *