2008-09-16 15:27:42 +00:00
|
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
#package xCAT_monitoring::performance;
|
|
|
|
|
BEGIN
|
|
|
|
|
{
|
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
|
}
|
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
|
use xCAT::NodeRange;
|
|
|
|
|
use Sys::Hostname;
|
|
|
|
|
use Socket;
|
|
|
|
|
use xCAT::Utils;
|
2012-08-14 11:48:59 +00:00
|
|
|
|
use xCAT::TableUtils;
|
|
|
|
|
use xCAT::NetworkUtils;
|
2008-09-16 15:27:42 +00:00
|
|
|
|
use xCAT::GlobalDef;
|
|
|
|
|
use xCAT_monitoring::monitorctrl;
|
|
|
|
|
use xCAT::MsgUtils;
|
2008-09-30 14:39:59 +00:00
|
|
|
|
use xCAT_monitoring::xcatmon;
|
2008-09-16 15:27:42 +00:00
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
1;
|
|
|
|
|
performance();
|
|
|
|
|
sub performance
|
|
|
|
|
{ #opening subroutine
|
|
|
|
|
|
2008-10-06 18:02:07 +00:00
|
|
|
|
my $noderef=xCAT_monitoring::monitorctrl->getMonHierarchy();
|
2008-09-16 15:27:42 +00:00
|
|
|
|
#identification of this node
|
2012-08-14 11:48:59 +00:00
|
|
|
|
my @hostinfo=xCAT::NetworkUtils->determinehostname();
|
2008-09-16 15:27:42 +00:00
|
|
|
|
#print "hosT:@hostinfo\n";
|
|
|
|
|
my $isSV=xCAT::Utils->isServiceNode();
|
|
|
|
|
#print "is sv is:$isSV \n";
|
|
|
|
|
my %iphash=();
|
|
|
|
|
foreach(@hostinfo) {$iphash{$_}=1;}
|
|
|
|
|
if (!$isSV) { $iphash{'noservicenode'}=1;}
|
|
|
|
|
|
|
|
|
|
my @children;
|
2008-10-06 18:02:07 +00:00
|
|
|
|
my $str;
|
2008-09-16 15:27:42 +00:00
|
|
|
|
|
|
|
|
|
foreach my $key (keys (%$noderef))
|
|
|
|
|
{ #opening foreach1
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "opening foreach1 \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
#print "key is: $key \n";
|
2009-03-20 17:50:09 +00:00
|
|
|
|
my @key_a=split(':', $key);
|
2008-10-06 18:02:07 +00:00
|
|
|
|
if (! $iphash{$key_a[0]}) { next;}
|
2008-09-16 15:27:42 +00:00
|
|
|
|
my $mon_nodes=$noderef->{$key};
|
|
|
|
|
|
|
|
|
|
foreach(@$mon_nodes)
|
|
|
|
|
{ #opening foreach2
|
|
|
|
|
my $node=$_->[0];
|
|
|
|
|
my $nodetype=$_->[1];
|
|
|
|
|
#print "node=$node, nodetype=$nodetype\n";
|
|
|
|
|
if (($nodetype) && ($nodetype =~ /$::NODETYPE_OSI/))
|
|
|
|
|
{
|
|
|
|
|
push(@children,$node);
|
|
|
|
|
}
|
|
|
|
|
} #closing foreach2
|
|
|
|
|
} #closing foreach1
|
2008-10-06 18:02:07 +00:00
|
|
|
|
|
|
|
|
|
#print "children:@children\n";
|
|
|
|
|
my $count_child=@children;
|
|
|
|
|
if($count_child > 0)
|
|
|
|
|
{ #opening if count_child 1
|
|
|
|
|
#print "number of children is $count_child \n";
|
|
|
|
|
no strict;
|
|
|
|
|
no warnings;
|
|
|
|
|
#my $i=0;
|
|
|
|
|
my @inactive_children;
|
|
|
|
|
for ($i = 0;$i < $count_child;$i++)
|
|
|
|
|
{ #opening if count_child 2
|
|
|
|
|
$str=`pmdumptext -c $::XCATROOT/lib/perl/xCAT_monitoring/pcp/pcpmon.config -d<> -s1 -h$children[$i] -f%D:%H:%M:%S 2>&1`;
|
|
|
|
|
#print "before split is $str \n";
|
|
|
|
|
#if ($str =~ /\s*No\s*route\s*to\s*host/)
|
|
|
|
|
if ($str =~ /pmdumptext:\s*Error:\s*host\s*"\w*":/)
|
|
|
|
|
{
|
|
|
|
|
#print "host unreachable \n";
|
|
|
|
|
@inactive_children=$children[$i];
|
|
|
|
|
#print "inactive children is @inactive_children \n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
2008-09-30 14:39:59 +00:00
|
|
|
|
{
|
|
|
|
|
#print "into elso loop \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
$str =~ s/\n//g;
|
|
|
|
|
#print "before split_1 is $str \n";
|
|
|
|
|
my @spl1=split(/<2F>/,$str);
|
|
|
|
|
#print "splitted and #printing \n";
|
|
|
|
|
#print @spl1;
|
|
|
|
|
my $count_spl1=@spl1;
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "the array has $count_spl1 elements \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
#print "@spl1[0] \n";
|
|
|
|
|
#print "@spl1[1] \n";
|
2008-10-14 18:13:00 +00:00
|
|
|
|
#my $count3= `cat $::XCATROOT/lib/perl/xCAT_monitoring/pcp/pcpmon.config | wc -l`;
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "the number of lines in the file is count3:$count3 \n";
|
|
|
|
|
#`tr "\n" "<22>" <$::XCATROOT/lib/perl/xCAT_monitoring/pcp/pcpmon.config> $::XCATROOT/lib/perl/xCAT_monitoring/pcp/pcpmon.config.tr`;
|
2008-10-14 18:13:00 +00:00
|
|
|
|
my $fname;
|
|
|
|
|
if (-e "/var/log/pcpmon.config")
|
|
|
|
|
{
|
|
|
|
|
#print "config under /var/log \n";
|
|
|
|
|
$fname="/var/log/pcpmon.config";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#print "config not under /var/log \n";
|
|
|
|
|
$fname = "$::XCATROOT/lib/perl/xCAT_monitoring/pcp/pcpmon.config";
|
|
|
|
|
}
|
|
|
|
|
print "config file is in $fname \n";
|
2008-10-06 18:02:07 +00:00
|
|
|
|
unless ( open( CONF, $fname ))
|
|
|
|
|
{
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
my @raw_data = <CONF>;
|
|
|
|
|
close( CONF );
|
|
|
|
|
#print "before chopping @raw_data \n";
|
|
|
|
|
chop(@raw_data);
|
|
|
|
|
#print "raw data after chopping is @raw_data \n";
|
|
|
|
|
my $raw_data = join('<27>', @raw_data);
|
|
|
|
|
#print "the contents of the config file are $raw_data \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
my @spl2=split(/<2F>/,$raw_data);
|
|
|
|
|
#print "splitted and #printing \n";
|
|
|
|
|
#print @spl2;
|
|
|
|
|
my $count_spl2=@spl2;
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "the array has $count_spl2 elements \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
#print @spl2[0] ;
|
|
|
|
|
#print @spl2[1] ;
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "updating table \n";
|
2008-09-16 15:27:42 +00:00
|
|
|
|
my $table1=xCAT::Table->new("performance", -create => 1,-autocommit => 1);
|
|
|
|
|
#print "table created \n";
|
|
|
|
|
my $j;
|
|
|
|
|
#my $k;
|
|
|
|
|
my $l=$j+1;
|
|
|
|
|
#print "l is $l \n";
|
|
|
|
|
my %setting_hash=();
|
|
|
|
|
for ($j=0;$j<$count_spl2 ;$j++)
|
|
|
|
|
{
|
|
|
|
|
|
2008-10-06 18:02:07 +00:00
|
|
|
|
#print "inside j loop \n";
|
|
|
|
|
#print "spl1[0] is $spl1[0] \n";
|
|
|
|
|
my %key_col1 = (timestamp=>$spl1[0]);
|
|
|
|
|
#print "time stamp updated \n";
|
|
|
|
|
#print "node is $children[$i] \n";
|
|
|
|
|
$key_col1{node}=$children[$i];
|
|
|
|
|
#print "children updatesd \n";
|
|
|
|
|
#print "spl2 is $spl2[$j] \n";
|
|
|
|
|
$key_col1{attrname} = $spl2[$j];
|
|
|
|
|
#$setting_hash{attrname}=$spl2[$j];
|
|
|
|
|
#print "spl1 is $spl1[$j+1] \n";
|
|
|
|
|
$setting_hash{attrvalue}=$spl1[$j+1];
|
|
|
|
|
$table1->setAttribs(\%key_col1, \%setting_hash);
|
2008-09-16 15:27:42 +00:00
|
|
|
|
}
|
2008-10-06 18:02:07 +00:00
|
|
|
|
$table1->close();
|
2008-09-30 14:39:59 +00:00
|
|
|
|
}
|
2008-09-16 15:27:42 +00:00
|
|
|
|
} #closing if count_child 2
|
2008-09-30 14:39:59 +00:00
|
|
|
|
|
|
|
|
|
|
2008-10-06 18:02:07 +00:00
|
|
|
|
my $table2=xCAT::Table->new("monitoring", -create =>1);
|
|
|
|
|
if (!$table2)
|
|
|
|
|
{
|
|
|
|
|
my $rsp={};
|
|
|
|
|
$rsp->{data}->[0]="Cannot open the monitoring table.\n";
|
|
|
|
|
$callback->($rsp);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-09-30 14:39:59 +00:00
|
|
|
|
|
2008-10-06 18:02:07 +00:00
|
|
|
|
my $ref = $table2->getAttribs({'name' => 'pcpmon'}, 'nodestatmon');
|
|
|
|
|
#print "array is $ref \n";
|
|
|
|
|
my $node_stat=$ref->{nodestatmon};
|
|
|
|
|
#print "nodestatmon is $node_stat \n";
|
|
|
|
|
if ($node_stat ='Y')
|
|
|
|
|
{ #opening ifnodestatusmon
|
|
|
|
|
#print "inside nodestatus mon $node_stat \n";
|
|
|
|
|
my %node_status=();
|
|
|
|
|
#print "2nd set is @inactive_children \n";
|
|
|
|
|
my $count_inactive=@inactive_children;
|
|
|
|
|
if ($count_inactive>0)
|
|
|
|
|
{
|
|
|
|
|
#print "more than 0 inactive children \n";
|
|
|
|
|
#print "3rd set is @inactive_children \n";
|
|
|
|
|
$node_status{$::STATUS_INACTIVE}=\@inactive_children;
|
|
|
|
|
my $changed1=$nodes_status{$::STATUS_INACTIVE};
|
|
|
|
|
#print "the changed1 is $changed1 \n";
|
|
|
|
|
my @final_inactive=@$changed1;
|
|
|
|
|
#print "final inactive is @final_inactive \n";
|
|
|
|
|
}
|
2008-09-30 14:39:59 +00:00
|
|
|
|
|
2008-10-06 18:02:07 +00:00
|
|
|
|
|
|
|
|
|
#only set the node status for the changed ones
|
|
|
|
|
if (keys(%node_status) > 0)
|
|
|
|
|
{
|
|
|
|
|
#print %node_status, "\n";
|
|
|
|
|
#print "updating nodelist table \n";
|
|
|
|
|
xCAT_monitoring::xcatmon::setNodeStatusAttributes(\%node_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} #closing if nodestatusmon
|
|
|
|
|
} #closing if count_child 1
|
2008-09-16 15:27:42 +00:00
|
|
|
|
|
2009-03-20 17:50:09 +00:00
|
|
|
|
} # closing subroutine
|