diff --git a/lib/App/Netdisco/Backend/Worker/Poller/Expiry.pm b/lib/App/Netdisco/Backend/Worker/Poller/Expiry.pm index 01460826..13222abd 100644 --- a/lib/App/Netdisco/Backend/Worker/Poller/Expiry.pm +++ b/lib/App/Netdisco/Backend/Worker/Poller/Expiry.pm @@ -88,8 +88,9 @@ sub expire { netdisco_ver => $App::Netdisco::VERSION, snmpinfo_ver => $snmpinfo_ver, schema_ver => $schema->schema_version, - perl_ver => $], - pg_ver => $schema->storage->dbh->{pg_server_version}, + perl_ver => pretty_version($], 3), + pg_ver => + pretty_version($schema->storage->dbh->{pg_server_version}, 2), }, { key => 'primary' }); }); @@ -97,6 +98,17 @@ sub expire { 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 sub expirenodes { my ($self, $job) = @_; diff --git a/lib/App/Netdisco/Web/Statistics.pm b/lib/App/Netdisco/Web/Statistics.pm index 3c9d472c..400a5933 100644 --- a/lib/App/Netdisco/Web/Statistics.pm +++ b/lib/App/Netdisco/Web/Statistics.pm @@ -6,79 +6,14 @@ use Dancer::Plugin::Auth::Extensible; get '/ajax/content/statistics' => require_login sub { - my $time1 = time; - my $schema = schema('netdisco'); - my $devices = $schema->resultset('Device'); + my $stats = schema('netdisco')->resultset('Statistics') + ->search(undef, { order_by => { -desc => 'day' }, rows => 1 }); - # used only to get the PostgreSQL version - 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); + $stats = ($stats->count ? $stats->first->hri : undef); var( nav => 'statistics' ); template 'ajax/statistics.tt', - { - 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, - }, + { stats => $stats }, { layout => undef }; };