From 230bfd5f190175da18fd0bc221d3278eaa905edc Mon Sep 17 00:00:00 2001 From: linggao Date: Sat, 16 Feb 2008 04:51:42 +0000 Subject: [PATCH] hierarchical management support for xcatmon which does node liveness monitoring for xCAT git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@495 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- .../lib/xcat/monitoring/xcatmon.pm | 80 ++++++++++++++++--- xCAT-server-2.0/sbin/xcatnodemon | 6 +- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm index 270b874a8..347f649a3 100644 --- a/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm +++ b/xCAT-server-2.0/lib/xcat/monitoring/xcatmon.pm @@ -6,11 +6,10 @@ BEGIN $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat'; } use lib "$::XCATROOT/lib/perl"; -#use xCAT::NodeRange; -#use Socket; -#use xCAT::Utils; -#use xCAT::GlobalDef; use xCAT::Utils; +use xCAT::GlobalDef; +use xCAT_monitoring::monitorctrl; +use Sys::Hostname; 1; @@ -29,9 +28,9 @@ use xCAT::Utils; when xcatd starts. Arguments: monservers --A hash reference keyed by the monitoring server nodes - and each value is a ref to an array of [nodes, nodetype] arrays + and each value is a ref to an array of [nodes, nodetype, status] arrays monitored by the server. So the format is: - {monserver1=>[['node1', 'osi'], ['node2', 'switch']...], ...} + {monserver1=>[['node1', 'osi', 'active'], ['node2', 'switch', 'booting']...], ...} Returns: (return code, message) =cut @@ -87,9 +86,9 @@ sub supportNodeStatusMon { to xCAT. Arguments: monservers --A hash reference keyed by the monitoring server nodes - and each value is a ref to an array of [nodes, nodetype] arrays + and each value is a ref to an array of [nodes, nodetype, status] arrays monitored by the server. So the format is: - {monserver1=>[['node1', 'osi'], ['node2', 'switch']...], ...} + {monserver1=>[['node1', 'osi', 'active'], ['node2', 'switch', 'booting']...], ...} Returns: (return code, message) @@ -132,9 +131,9 @@ sub stopNodeStatusMon { to the xCAT cluster. It should add the nodes into the product for monitoring. Arguments: nodes --nodes to be added. It is a hash reference keyed by the monitoring server - nodes and each value is a ref to an array of [nodes, nodetype] arrays monitored + nodes and each value is a ref to an array of [nodes, nodetype, status] arrays monitored by the server. So the format is: - {monserver1=>[['node1', 'osi'], ['node2', 'switch']...], ...} + {monserver1=>[['node1', 'osi', 'active'], ['node2', 'switch', 'booting']...], ...} Returns: none =cut @@ -143,7 +142,6 @@ sub addNodes { #print "xcatmon:addNodes called\n"; - #TODO: include the nodes into the product for monitoring. return; } @@ -164,8 +162,66 @@ sub removeNodes { #print "xcatmon:removeNodes called\n"; - #TODO: remove the nodes from the product for monitoring. return; } +#-------------------------------------------------------------------------------- +=head3 getMonNodesStatus + This function goes to the xCAT nodelist table to retrieve the saved node status + for all the node that are managed by local nodes. + Arguments: + none. + Returns: + a hash that has the node status. The format is: + {active=>[node1, node3,...], unreachable=>[node4, node2...], unknown=>[node8, node101...]} +=cut +#-------------------------------------------------------------------------------- +sub getMonNodesStatus { + %status=(); + my @inactive_nodes=(); + my @active_nodes=(); + my @unknown_nodes=(); + + my $monservers=xCAT_monitoring::monitorctrl->getMonHierarchy(); + + my $host=hostname(); + my $monnodes=$monservers->{$host}; + if (($monnodes) && (@$monnodes >0)) { + foreach(@$monnodes) { + my $node=$_->[0]; + my $status=$_->[2]; + if ($status eq $::STATUS_ACTIVE) { push(@active_nodes, $node);} + elsif ($status eq $::STATUS_INACTIVE) { push(@inactive_nodes, $node);} + else { push(@unknown_nodes, $node);} + } + } + + $status{$::STATUS_ACTIVE}=\@active_nodes; + $status{$::STATUS_INACTIVE}=\@inactive_nodes; + $status{unknown}=\@unknown_nodes; + + return %status; +} + + +#-------------------------------------------------------------------------------- +=head3 processNodeStatusChanges + This function will update the status column of the + nodelist table with the new node status. + Arguments: + status -- a hash pointer of the node status. A key is a status string. The value is + an array pointer of nodes that have the same status. + for example: {active=>["node1", "node1"], inactive=>["node5","node100"]} + Returns: + 0 for successful. + non-0 for not successful. +=cut +#-------------------------------------------------------------------------------- +sub processNodeStatusChanges { + my $temp=shift; + if ($temp =~ /xCAT_plugin::xcatmon/) { + $temp=shift; + } + return xCAT_monitoring::monitorctrl->processNodeStatusChanges($temp); +} diff --git a/xCAT-server-2.0/sbin/xcatnodemon b/xCAT-server-2.0/sbin/xcatnodemon index 38172501d..2569a3fd6 100755 --- a/xCAT-server-2.0/sbin/xcatnodemon +++ b/xCAT-server-2.0/sbin/xcatnodemon @@ -7,7 +7,7 @@ BEGIN use lib "$::XCATROOT/lib/perl"; use xCAT::GlobalDef; use xCAT::Table; -use xCAT_monitoring::monitorctrl; +use xCAT_monitoring::xcatmon; ################################################################# # This script is used as a cron job by the xCAT monitoring plug-in # to monitor the node status. To activate it, simply do @@ -18,7 +18,7 @@ use xCAT_monitoring::monitorctrl; #printf "%2d-%02d-%04d %02d:%02d:%02d: xcatnodemon started.\n", $mon+1,$mday,$year+1900,$hour,$min,$sec; #get saved node status from the nodelist table -my %nodes_status_old=xCAT_monitoring::monitorctrl::getNodeStatus(); +my %nodes_status_old=xCAT_monitoring::xcatmon::getMonNodesStatus(); #get a list of nodes my $tmp_node_active=$nodes_status_old{$::STATUS_ACTIVE}; @@ -56,7 +56,7 @@ if (@changed_inactive>0) { #only set the node status for the changed ones if (keys(%node_status) > 0) { - xCAT_monitoring::monitorctrl::processNodeStatusChanges(\%node_status); + xCAT_monitoring::xcatmon::processNodeStatusChanges(\%node_status); } #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);