Add Slow Devices admin report

This commit is contained in:
Oliver Gorwits
2013-11-03 11:32:33 +00:00
parent e5cb093f3e
commit 42e5568370
4 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package App::Netdisco::DB::Result::Virtual::SlowDevices;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('slow_devices');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT a.action, a.device, a.started, a.finished,
justify_interval(extract(epoch FROM (a.finished - a.started)) * interval '1 second') AS elapsed
FROM admin a
INNER JOIN (
SELECT device, action, max(started) AS started
FROM admin
WHERE status = 'done'
AND action IN ('discover','macsuck','arpnip')
GROUP BY action, device
) b
ON a.device = b.device AND a.started = b.started
ORDER BY elapsed desc, action, device
LIMIT 20
ENDSQL
);
__PACKAGE__->add_columns(
"action",
{ data_type => "text", is_nullable => 1 },
"device",
{ data_type => "inet", is_nullable => 1 },
"started",
{ data_type => "timestamp", is_nullable => 1 },
"finished",
{ data_type => "timestamp", is_nullable => 1 },
"elapsed",
{ data_type => "interval", is_nullable => 1 },
);
1;

View File

@@ -0,0 +1,24 @@
package App::Netdisco::Web::Plugin::AdminTask::SlowDevices;
use Dancer ':syntax';
use Dancer::Plugin::Ajax;
use Dancer::Plugin::DBIC;
use Dancer::Plugin::Auth::Extensible;
use App::Netdisco::Web::Plugin;
register_admin_task({
tag => 'slowdevices',
label => 'Slowest Devices',
});
ajax '/ajax/content/admin/slowdevices' => require_role admin => sub {
my $set = schema('netdisco')->resultset('Virtual::SlowDevices');
content_type('text/html');
template 'ajax/admintask/slowdevices.tt', {
results => $set,
}, { layout => undef };
};
true;