Merge pull request #105 from pv2b/fix-extractstats-schema

Fix per-link stats in extractstats
This commit is contained in:
Manuel Kasper 2023-04-24 19:04:05 +02:00 committed by GitHub
commit 697d0358e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,7 +38,7 @@ my %knownlinks;
read_knownlinks(); read_knownlinks();
my @links = values %knownlinks; my @links = sort values %knownlinks;
# If the DB has it, get latest check timestamp for every ASN we are aware of # If the DB has it, get latest check timestamp for every ASN we are aware of
my $db_version = 1; my $db_version = 1;
@ -50,8 +50,23 @@ try {
} }
$db = DBI->connect("dbi:SQLite:dbname=$statsfile.tmp", '', ''); $db = DBI->connect("dbi:SQLite:dbname=$statsfile.tmp", '', '');
# Check if table has expected schema
my $sth = $db->prepare("SELECT name FROM PRAGMA_TABLE_INFO('stats')") or die ("can't check stats table schema");
$sth->execute();
($sth->fetchrow_array eq 'asn') or die('schema mismatch');
($sth->fetchrow_array eq 'checked_at') or die('schema mismatch');
foreach my $link (@links) {
($sth->fetchrow_array eq "${link}_in") or die('schema mismatch');
($sth->fetchrow_array eq "${link}_out") or die('schema mismatch');
($sth->fetchrow_array eq "${link}_v6_in") or die('schema mismatch');
($sth->fetchrow_array eq "${link}_v6_out") or die('schema mismatch');
}
# Make sure there are no more unexpected fields
!defined $sth->fetchrow_array or die('schema mismatch');
# Get last check timestamps # Get last check timestamps
my $sth = $db->prepare("SELECT asn, checked_at FROM stats") or die('field missing'); $sth = $db->prepare("SELECT asn, checked_at FROM stats") or die('field missing');
$sth->execute(); $sth->execute();
while(my($item, $data) = $sth->fetchrow_array()) { while(my($item, $data) = $sth->fetchrow_array()) {
$as_list->{$item} = $data; $as_list->{$item} = $data;
@ -59,7 +74,7 @@ try {
$db_version = 2; $db_version = 2;
} catch ($e) { } catch ($e) {
print("Previously generated database not found or checked_at field is missing, proceed with all RRD files. ($e)\n"); print("Previously generated database not found or database schema mismatch, proceed with all RRD files. ($e)\n");
} }
# walk through all RRD files in the given path and extract stats for all links # walk through all RRD files in the given path and extract stats for all links