This is a discussion on SQL query to get UP and Down jobs ignoring subseqent dups within the MySQL Database forums, part of the Database Forums category; Here is the trouble I need to track system outages based on batched jobs. I have the following data in ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Here is the trouble I need to track system outages based on batched
jobs. I have the following data in tables (headers) Job, Start Date, Start Time,End Date, End Time This is a batch schedule with jobs that make a system unavailable. Now there are two types of batch jobs, a start and an end so we get the following: --job log table-- ENVSTAT,8/26/2007,08:17:12,8/26/2007,8:18:28 ENVSTPM,8/26/2007,19:25:46,8/26/2007,19:26:06 ENVSTAM,8/26/2007,19:51:13,8/26/2007,19:51:33 ENVSTPA,8/27/2007,09:23:09,8/27/2007,9:35:24 ENVSTPA,8/28/2007,16:00:41,8/28/2007,16:12:49 ENVSTPM,8/28/2007,19:15:18,8/28/2007,19:15:38 ENVSTAM,8/28/2007,20:19:04,8/28/2007,20:19:26 ENVSTAC,8/28/2007,20:23:46,8/28/2007,20:24:07 ENVSTPA,8/29/2007,00:06:20,8/29/2007,0:18:22 ENVSTA1,8/29/2007,01:05:33,8/29/2007,1:17:57 ENVSTPM,8/29/2007,19:12:34,8/29/2007,19:13:05 ENVSTAM,8/29/2007,19:55:31,8/29/2007,19:55:51 ENVSTPB,8/29/2007,20:12:00,8/29/2007,20:27:57 ENVSTAB,8/29/2007,20:42:18,8/29/2007,20:54:45 ENVSTPM,8/30/2007,19:16:49,8/30/2007,19:17:11 ENVSTAM,8/30/2007,19:50:03,8/30/2007,19:50:23 ENVSTPB,8/30/2007,20:36:10,8/30/2007,20:52:05 ENVSTAB,8/30/2007,21:11:34,8/30/2007,21:24:01 ENVSTPA,8/31/2007,03:59:12,8/31/2007,4:15:59 ENVSTA1,8/31/2007,05:42:03,8/31/2007,5:54:53 ENVSTPM,8/31/2007,19:10:33,8/31/2007,19:10:54 ENVSTAM,8/31/2007,19:41:28,8/31/2007,19:41:48 ENVSTPB,8/31/2007,19:41:59,8/31/2007,19:54:38 ENVSTAB,8/31/2007,20:13:28,8/31/2007,20:25:53 ENVSTPA,9/1/2007,00:46:02,9/1/2007,1:02:49 ENVSTA1,9/1/2007,02:23:23,9/1/2007,2:35:54 ENVSTPM,9/1/2007,19:37:23,9/1/2007,19:37:45 ENVSTAM,9/1/2007,21:14:19,9/1/2007,21:14:39 Now certain jobs will make the system unavailable (down jobs) and some will bring them up. We need to ignore batches that do not bring environments down (in the above example C and T jobs do nothing to us.) What I am after is the down time. I am going to store in a separate table (jobdef) the up and down jobs for reference. The trick is they are linked in pairs (STPM,STAM ; STPA, STA1 ; etc.) but can run concurrently so if an M batch brings the environment down at say noon to 1. But an A batch brings it down from 1:30 to 2 then the real down time is from noon to 2 (See how this is tricky?) But if M brings things down from noon to 1 and A brings is down from 2 to 4 that is a new second down time. // EXAMPLE On the 26th the M Batch took the system down from 19:25:46 to 19:51:33 BUT on the 31st the M batch took the system down at 19:10:33 but it finally came back up at 20:25:53 (The B batch continued the outage). The current way I'd record the outages is from 19:00 to 20:00 (rounding to 30 min blocks.) which is not accurate IMHO. The question is this: How do I get the start time and date of the FIRST down job, ignoring subsequent down jobs (it's already down) and get the end time of the FIRST up job ignoring subseqent up jobs (because it's already up.) but taking into account overlapping down periods. I currently do this by hand and it takes hours upon hours and I do it in 15 min increments (not accurate but faster). I want "to the minute" accuracy and no human contamination in recording the availability so I am going to put this into a MYSQL database initially and make a report via a web page rather then hacking this manually via Excel (we're talking days worth of my life doing this.) I believe in working smarter, no harder but I cannot for the life of me figure out the SQL needed to pull this out for graphing. The main reason is I compare the sum of the down time against a schedule and report the difference but I have to show it graphically. Here is my best psuedocode FOR A GIVEN TIME PERIOD STARTING AT X AND ENDING AT Y MAKE a TEMP RECORD with the START TIME of the FIRST DOWN JOB AND the END TIME of the LAST UP JOB that went down DURING THE FIRST DOWN JOB. // in short we have to take into account overlapping batches In the end I should have just a list of downtime windows like temp1,01/01/07,8:00AM.9:45PM Oh and one last gotchya, given this is reasonably in realtime we have to assume that the system is down to NOW() if we have a down job but no start job at the end. I am lost on this and have been trying to tinker with it for over a year and haven't gotten very far. I need my weekends back, help! :) |