half work of updating web stats page to use stats table

This commit is contained in:
Oliver Gorwits
2017-06-28 13:16:52 +01:00
parent 47bf38568e
commit ccd279d918
2 changed files with 18 additions and 71 deletions

View File

@@ -88,8 +88,9 @@ sub expire {
netdisco_ver => $App::Netdisco::VERSION, netdisco_ver => $App::Netdisco::VERSION,
snmpinfo_ver => $snmpinfo_ver, snmpinfo_ver => $snmpinfo_ver,
schema_ver => $schema->schema_version, schema_ver => $schema->schema_version,
perl_ver => $], perl_ver => pretty_version($], 3),
pg_ver => $schema->storage->dbh->{pg_server_version}, pg_ver =>
pretty_version($schema->storage->dbh->{pg_server_version}, 2),
}, { key => 'primary' }); }, { key => 'primary' });
}); });
@@ -97,6 +98,17 @@ sub expire {
return job_done("Checked expiry and updated stats"); return job_done("Checked expiry and updated stats");
} }
# take perl or pg versions and make pretty
sub pretty_version {
my ($version, $seglen) = @_;
return unless $version and $seglen;
$version =~ s/\.//g;
$version = (join '.', reverse map {scalar reverse}
unpack("(A${seglen})*", reverse $version));
$version =~ s/\.0+/\./g;
return $version;
}
# expire nodes for a specific device # expire nodes for a specific device
sub expirenodes { sub expirenodes {
my ($self, $job) = @_; my ($self, $job) = @_;

View File

@@ -6,79 +6,14 @@ use Dancer::Plugin::Auth::Extensible;
get '/ajax/content/statistics' => require_login sub { get '/ajax/content/statistics' => require_login sub {
my $time1 = time; my $stats = schema('netdisco')->resultset('Statistics')
my $schema = schema('netdisco'); ->search(undef, { order_by => { -desc => 'day' }, rows => 1 });
my $devices = $schema->resultset('Device');
# used only to get the PostgreSQL version $stats = ($stats->count ? $stats->first->hri : undef);
my $users = $schema->resultset('User')->search(
{},
{ select => [ { version => '' } ],
as => [qw/ version /],
}
);
my $device_count = $devices->count;
my $device_port_count = $schema->resultset('DevicePort')->count;
my $device_ip_count = $schema->resultset('DeviceIp')
->search( undef, { columns => [qw/ alias /] } )->count;
my $nodes = $schema->resultset('Node')->search(
{},
{ columns => [qw/mac/],
distinct => 1
}
);
my $node_count = $nodes->count;
my $node_table_count = $schema->resultset('Node')->count;
my $nodes_ips = $schema->resultset('NodeIp')->search(
{},
{ columns => [qw/ip/],
distinct => 1
}
);
my $ip_count = $nodes_ips->count;
my $ip_table_count
= $schema->resultset('NodeIp')->search( {}, { columns => [qw/ip/] } )
->count;
my $device_links = $schema->resultset('DevicePort')
->search( { 'remote_ip' => { '!=', undef } } )->count;
my $schema_version = $schema->get_db_version;
my $target_version = $schema->schema_version;
my $time2 = time;
my $process_time = $time2 - $time1;
my $disco_ver = $App::Netdisco::VERSION;
my $db_version = $users->next->get_column('version');
my $dbi_ver = $DBI::VERSION;
my $dbdpg_ver = $DBD::Pg::VERSION;
eval { require SNMP::Info };
my $snmpinfo_ver = ($@ ? 'n/a' : $SNMP::Info::VERSION);
var( nav => 'statistics' ); var( nav => 'statistics' );
template 'ajax/statistics.tt', template 'ajax/statistics.tt',
{ { stats => $stats },
device_count => $device_count,
device_ip_count => $device_ip_count,
device_links => $device_links,
device_port_count => $device_port_count,
ip_count => $ip_count,
ip_table_count => $ip_table_count,
node_count => $node_count,
node_table_count => $node_table_count,
process_time => $process_time,
disco_ver => $disco_ver,
db_version => $db_version,
dbi_ver => $dbi_ver,
dbdpg_ver => $dbdpg_ver,
snmpinfo_ver => $snmpinfo_ver,
schema_ver => $schema_version,
},
{ layout => undef }; { layout => undef };
}; };