#15 record device and node statistics once a day
This commit is contained in:
3
Changes
3
Changes
@@ -1,5 +1,8 @@
|
|||||||
2.036003 - TESTING
|
2.036003 - TESTING
|
||||||
|
|
||||||
|
[NEW FEATURES]
|
||||||
|
* #15 record device and node statistics once a day
|
||||||
|
|
||||||
[BUG FIXES]
|
[BUG FIXES]
|
||||||
|
|
||||||
* #322 cease use of Sys::Proctitle
|
* #322 cease use of Sys::Proctitle
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package App::Netdisco::Backend::Worker::Poller::Expiry;
|
|||||||
use Dancer qw/:moose :syntax :script/;
|
use Dancer qw/:moose :syntax :script/;
|
||||||
use Dancer::Plugin::DBIC 'schema';
|
use Dancer::Plugin::DBIC 'schema';
|
||||||
|
|
||||||
|
use Time::Piece;
|
||||||
use App::Netdisco::Backend::Util ':all';
|
use App::Netdisco::Backend::Util ':all';
|
||||||
|
|
||||||
use Role::Tiny;
|
use Role::Tiny;
|
||||||
@@ -50,7 +51,50 @@ sub expire {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return job_done("Checked expiry for all Devices and Nodes");
|
# now update stats
|
||||||
|
my $schema = schema('netdisco');
|
||||||
|
eval { require SNMP::Info };
|
||||||
|
my $snmpinfo_ver = ($@ ? 'n/a' : $SNMP::Info::VERSION);
|
||||||
|
|
||||||
|
# TODO: (when we have the capabilities table?)
|
||||||
|
# $stats{waps} = sql_scalar('device',['COUNT(*)'], {"model"=>"AIR%"});
|
||||||
|
|
||||||
|
$schema->txn_do(sub {
|
||||||
|
$schema->resultset('Statistics')->update_or_create({
|
||||||
|
day => localtime->ymd,
|
||||||
|
|
||||||
|
device_count =>
|
||||||
|
$schema->resultset('Device')->count_rs->as_query,
|
||||||
|
device_ip_count =>
|
||||||
|
$schema->resultset('DeviceIp')->count_rs->as_query,
|
||||||
|
device_link_count =>
|
||||||
|
$schema->resultset('Virtual::DeviceLinks')
|
||||||
|
->count_rs({'me.left_ip' => {'>', \'me.right_ip'}})->as_query,
|
||||||
|
device_port_count =>
|
||||||
|
$schema->resultset('DevicePort')->count_rs->as_query,
|
||||||
|
device_port_up_count =>
|
||||||
|
$schema->resultset('DevicePort')->count_rs({up => 'up'})->as_query,
|
||||||
|
ip_table_count =>
|
||||||
|
$schema->resultset('NodeIp')->count_rs->as_query,
|
||||||
|
ip_count =>
|
||||||
|
$schema->resultset('NodeIp')->search(undef,
|
||||||
|
{columns => 'ip', distinct => 1})->count_rs->as_query,
|
||||||
|
node_table_count =>
|
||||||
|
$schema->resultset('Node')->count_rs->as_query,
|
||||||
|
node_count =>
|
||||||
|
$schema->resultset('Node')->search(undef,
|
||||||
|
{columns => 'mac', distinct => 1})->count_rs->as_query,
|
||||||
|
|
||||||
|
netdisco_ver => $App::Netdisco::VERSION,
|
||||||
|
snmpinfo_ver => $snmpinfo_ver,
|
||||||
|
schema_ver => $schema->schema_version,
|
||||||
|
perl_ver => $],
|
||||||
|
pg_ver => $schema->storage->dbh->{pg_server_version},
|
||||||
|
|
||||||
|
}, { key => 'primary' });
|
||||||
|
});
|
||||||
|
|
||||||
|
return job_done("Checked expiry and updated stats");
|
||||||
}
|
}
|
||||||
|
|
||||||
# expire nodes for a specific device
|
# expire nodes for a specific device
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ __PACKAGE__->load_namespaces(
|
|||||||
);
|
);
|
||||||
|
|
||||||
our # try to hide from kwalitee
|
our # try to hide from kwalitee
|
||||||
$VERSION = 43; # schema version used for upgrades, keep as integer
|
$VERSION = 44; # schema version used for upgrades, keep as integer
|
||||||
|
|
||||||
use Path::Class;
|
use Path::Class;
|
||||||
use File::ShareDir 'dist_dir';
|
use File::ShareDir 'dist_dir';
|
||||||
|
|||||||
46
lib/App/Netdisco/DB/Result/Statistics.pm
Normal file
46
lib/App/Netdisco/DB/Result/Statistics.pm
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
use utf8;
|
||||||
|
package App::Netdisco::DB::Result::Statistics;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use base 'DBIx::Class::Core';
|
||||||
|
__PACKAGE__->table("statistics");
|
||||||
|
__PACKAGE__->add_columns(
|
||||||
|
"day",
|
||||||
|
{ data_type => "date", is_nullable => 0 },
|
||||||
|
|
||||||
|
"device_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"device_ip_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"device_link_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"device_port_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"device_port_up_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"ip_table_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"ip_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"node_table_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"node_count",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
|
||||||
|
"netdisco_ver",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
"snmpinfo_ver",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
"schema_ver",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
"perl_ver",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
"pg_ver",
|
||||||
|
{ data_type => "text", is_nullable => 1 },
|
||||||
|
);
|
||||||
|
|
||||||
|
__PACKAGE__->set_primary_key("day");
|
||||||
|
|
||||||
|
1;
|
||||||
25
share/schema_versions/App-Netdisco-DB-43-44-PostgreSQL.sql
Normal file
25
share/schema_versions/App-Netdisco-DB-43-44-PostgreSQL.sql
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE "statistics" (
|
||||||
|
"day" date NOT NULL DEFAULT CURRENT_DATE,
|
||||||
|
|
||||||
|
"device_count" integer NOT NULL,
|
||||||
|
"device_ip_count" integer NOT NULL,
|
||||||
|
"device_link_count" integer NOT NULL,
|
||||||
|
"device_port_count" integer NOT NULL,
|
||||||
|
"device_port_up_count" integer NOT NULL,
|
||||||
|
"ip_table_count" integer NOT NULL,
|
||||||
|
"ip_count" integer NOT NULL,
|
||||||
|
"node_table_count" integer NOT NULL,
|
||||||
|
"node_count" integer NOT NULL,
|
||||||
|
|
||||||
|
"netdisco_ver" text,
|
||||||
|
"snmpinfo_ver" text,
|
||||||
|
"schema_ver" text,
|
||||||
|
"perl_ver" text,
|
||||||
|
"pg_ver" text,
|
||||||
|
|
||||||
|
PRIMARY KEY ("day")
|
||||||
|
);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
Reference in New Issue
Block a user