Commit 3bfcfe9f authored by Kirk Webb's avatar Kirk Webb
Browse files

This commit includes a script to clean old idle data from the emulab

database (iddata_clean), and a script to generate fake idle entries for
testing scripts on the minibed (idloadup.pl).

iddata_clean, by default, removes all idle entries older than 36 hours.
This can be changed by providing -m <maxage> (in seconds) to it.

idloadup.pl adds random idle data at time offsets from now, to 5 days
prior (1 sec granularity).  It adds anywhere from 1 to 10 entries per
PC to the node_idlestats page, and from 1 - 10 x # interfaces to
the iface_counters table.
parent 30fa4cb7
#!/usr/bin/perl
# iddata_clean - script to purge the aged slothd data from the emulab
# database.
use lib '/usr/testbed/lib';
use libdb;
use English;
use Getopt::Long;
use strict;
my %opts = ();
GetOptions(\%opts,'h','m=i');
sub usage() {
print "Usage:\n$0 -h This message.\n".
"$0 -m <maxage> Maximum idle data age to leave (in seconds).\n";
}
if ($opts{'h'}) {
exit &usage;
}
# security check.
my @whgrp = getgrnam("wheel");
my $uname = getpwuid($UID);
my $maxage = $opts{'m'} ? $opts{'m'} : 129600; # default is 36 hours
if (!TBAdmin($UID) && !($whgrp[3] =~ /$uname/)) {
print "You must either be a testbed admin, or in the wheel group\n".
"to run this script.\n";
exit 1;
}
print "Idlestats cleaner script started..\n\n";
clean_node_idlestats_table();
clean_iface_counters_table();
exit 0;
sub clean_node_idlestats_table() {
my $qres;
if ($qres = DBQueryFatal("delete from node_idlestats ".
"where unix_timestamp(now()) - ".
"unix_timestamp(tstamp) > $maxage")) {
print "Number of rows deleted from node_idlestats: ".
$qres->numrows() ."\n";
return 1;
}
return 0;
}
sub clean_iface_counters_table() {
my $qres;
if ($qres = DBQueryFatal("delete from iface_counters ".
"where unix_timestamp(now()) ".
"- unix_timestamp(tstamp) > $maxage")) {
print "Number of rows deleted from iface_counters: ".
$qres->numrows() ."\n";
return 1;
}
return 0;
}
#!/usr/bin/perl
# You don't want to run this script unless you want to fatten up the DB
# for idle-detection testing
use lib '/usr/testbed/lib';
use libdb;
use English;
use Getopt::Long;
use strict;
my %opts = ();
my $numnodes;
GetOptions(\%opts,'n=i','r');
# security check.
my @whgrp = getgrnam("wheel");
my $uname = getpwuid($UID);
if (!TBAdmin($UID) && !($whgrp[3] =~ /$uname/)) {
print "You must either be a testbed admin, or in the wheel group\n".
"to run this script.\n";
exit 1;
}
srand(time());
my @currow;
my $qres = DBQuery("SELECT node_id FROM nodes WHERE node_id LIKE 'pc%'");
print "number of nodes: ". $qres->numrows ."\n";
while (@currow = $qres->fetchrow_array()) {
my $curnode = $currow[0];
my $qmac = DBQuery("SELECT mac FROM interfaces ".
"WHERE node_id = '$curnode'");
my @macs = ();
while (my @macrow = $qmac->fetchrow_array()) {
push @macs, $macrow[0];
}
print "adding random idle data entries for $curnode\n";
for (my $i = Rand() % 10 + 1; $i > 0; --$i) {
my $maddr;
my $now = time();
my $randtime = $now - (Rand() % 432000);
my $randidle = $randtime - (Rand() % $randtime);
DBQuery("INSERT INTO node_idlestats VALUES ('$curnode', ".
"FROM_UNIXTIME($randtime), ".
"FROM_UNIXTIME($randidle), ".
Rand() % 100 .", ".
Rand() % 100 .", ".
Rand() % 100 .")");
foreach $maddr (@macs) {
DBQuery("INSERT INTO iface_counters VALUES ('$curnode', ".
"FROM_UNIXTIME($randtime), ".
"'$maddr', ".
Rand() .", ".
Rand() .")");
}
}
}
sub Rand() {
return int(rand(2**32));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment