2
2
3
3
//current filename
4
4
date_default_timezone_set ('America/New_York ' );
5
- $ dt_est = new DateTimeImmutable ($ date );
5
+ $ dt_est = new DateTimeImmutable ();
6
6
$ dt_utc = $ dt_est ->setTimeZone (new DateTimeZone ("UTC " ));
7
7
$ fn = './archives/ ' . $ dt_utc ->format ("Y-m-d_H\U.\s16 " );
8
8
$ dt_last = $ dt_utc ->sub (new DateInterval ("PT1H " ));
9
9
$ last_fn = './archives/ ' . $ dt_last ->format ("Y-m-d_H\U.\s16 " );
10
10
11
11
//seconds elasped in current hour
12
+ clearstatcache ();
12
13
$ seconds = time () % 3600 ;
13
14
14
15
$ seconds_behind = 0 ;
15
16
16
- function verify_amount_of_data ($ fn , $ seconds , $ threshold ) {
17
+ function verify_amount_of_data ($ fn , $ seconds_file , $ threshold ) {
17
18
//for signed 16, amount of data should be 48000 Hz * 4 bytes/sample * seconds elasped
18
- clearstatcache ();
19
- $ seconds_behind = ($ seconds - filesize ($ fn ) / 48000 / 4 );
19
+ $ seconds_behind = ($ seconds_file - filesize ($ fn ) / 48000 / 4 );
20
20
$ GLOBALS ['seconds_behind ' ] = $ seconds_behind ;
21
21
//to allow for SMB and cache flushing, allow $threshold seconds
22
22
return ($ seconds_behind <= $ threshold );
@@ -27,15 +27,19 @@ function verify_amount_of_data($fn, $seconds, $threshold) {
27
27
if ($ seconds <= 120 && file_exists ($ last_fn )) {
28
28
echo "OK: Current file not yet written, last file present, within threshold " ;
29
29
} else {
30
- header ($ _SERVER ["SERVER_PROTOCOL " ]." 503 Internal Server Error " , true , 503 );
30
+ header ($ _SERVER ["SERVER_PROTOCOL " ]." 404 Archive File Not Found " , true , 404 );
31
31
echo "ERROR: Neither current nor previous recording file present. " ;
32
32
}
33
33
} else {
34
- if (verify_amount_of_data ($ fn , $ seconds , 120 )) {
34
+ $ seconds_file = filemtime ($ fn ) % 3600 ;
35
+ $ trailing_seconds = $ seconds - $ seconds_file ;
36
+ if (verify_amount_of_data ($ fn , $ seconds_file , 120 )) {
35
37
echo "OK: System Normal<br> " ;
36
- echo "Stats: disk recording trails timestamp by $ seconds_behind seconds which is within threshold " ;
38
+ echo "Stats: disk recording trails timestamp by $ seconds_behind seconds which is within threshold<br> " ;
39
+ echo "Filemtime trails current time by $ trailing_seconds " ;
37
40
} else {
38
41
header ($ _SERVER ["SERVER_PROTOCOL " ]." 503 Internal Server Error " , true , 503 );
39
- echo "ERROR: Archive file present but shorter than expected " ;
42
+ echo "ERROR: Archive file present but shorter than expected:<br> " ;
43
+ echo "filemtime: $ seconds_file trails current time by $ trailing_seconds and the file is $ seconds_behind smaller than it should be. " ;
40
44
}
41
45
}
0 commit comments