php: find missing "times" in a series of times

zimu

Diamond Member
Jun 15, 2001
6,209
0
0
just put together a small makeshift "uptime" monitor.

basically- cron job every 10 mins that opens a php page. php page enters current time into a mysql database. every 24 hours, another cron runs that takes the total number of "check ins" and gives you a % uptime, since there should be 144 check ins in a day.

so its all good, i have that script running. so my database looks like (the date i'm entering this way, but its really stored in the now() format, so yyyy-mm-dd 00:00:00 format):

7-july-05 10:00am
7-july-05 10:10am
7-july-05 10:20am

ok, so that's perfect. HOWEVER, lets say i get to this:

7-july-05 10:20am
7-july-05 10:40am
7-july-05 10:50am

the server didn't "check in" at 10:30, hence there was an issue with the web service, the php service, or the mysql service, which i count as 'downtime'.

question is, how in the world can i "detect" this exact time, rather than just see that there were only 143 checkings today and throw out a percentage?

so i want a table which will show the above times chronologically, and instead of just 'skipping' the blank spot i want it to say 7-july-05 10:30am in red font or something, to show it was down.

thanks guys, hope someone can help!
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
for( each time that is suppsoed to be there){
check database to see if entry exists
if(entry exists){
print time in black
}
else{
print time in red
}
}
 

zimu

Diamond Member
Jun 15, 2001
6,209
0
0
managed to figure it out.
pretty much what notfred said, except instead of checking the database every single time it retrieves records from the db in sequential order and processes accordingly. less processor intensive.

pseudocode, in case anyone cares at all:

set time for 1st database entry in temp variable

<start do-while loop, which has as input each row of the table in the db (i'll call that db_row)>
- see if temp time == db_row
- if yes, print out the temp var, say "ok" (alternatively print out db_row)
- if not, start another loop that outputs the temp time in red, saying its down, increments temp time by 10 mins, and re-compares it to db_row. if there's a match, prints out the "ok" db_row, and continues on its way. if still no match, does the loop again, saying for the new temp time its down, incrementing 10 mins, etc.

thats it :)