my $path = '/home/nodelogs/c405f97667784094bca5cfa52af0bcf1/';
+my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime
+
+my $debug = $ENV{DEBUG} || 0;
+
# select _id,json->'received',time,to_timestamp((json->>'received')::int8/1000) - interval '1 hour' from nodelog ;
my $dbh = DBI->connect("dbi:Pg:dbname=eg5120", "dpavlin", "", { RaiseError => 1 });
-warn "# truncate table nodelog";
+warn "# truncate table nodelog" if $debug;
$dbh->do( qq{ truncate table nodelog } ); # FIXME
my $sth = $dbh->prepare(qq{insert into nodelog (time,json) values (?,?)});
-my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime
foreach my $filename (
sort { -M $a <=> -M $b } (glob("$path/node-red-out*.log")),
) {
last if $last_files-- == 0;
- warn "# $filename";
+ warn "# $filename" if $debug;
open(my $log, '<', $filename);
my $in_json = 0;
my $json;
if ( $_ eq '}' ) {
$in_json = 0;
#warn "- in_json";
- warn ">>> $time [[[[ $json ]]]]";
+ warn ">>> $time [[[[ $json ]]]]" if $debug;
write_file '/dev/shm/json', $json;
$sth->execute( $time, $json );
$json = '';