mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	change monitor summary data to average of all resources and nodes
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@3605 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -77,6 +77,7 @@ sub update_metrix2rrd | ||||
| 	my $rrd = undef; | ||||
| 	my $process_time = xCAT::Utils->runcmd("date +%s", 0); | ||||
| 	$process_time = (int $process_time/$step)*$step; | ||||
| 	my $temp = undef; | ||||
|  | ||||
| 	while(($attr, $nnlist) = each %metrix){ | ||||
| 		while(($nnlist, $name) = each %{$metrix{$attr}}){ | ||||
| @@ -89,7 +90,8 @@ sub update_metrix2rrd | ||||
| 			} | ||||
| 			if($nnlist eq 'summary'){ | ||||
| 				$rrd = "$rrddir/"."$attr.rrd"; | ||||
| 				$ret = xCAT_monitoring::rrdutil::push_data_to_rrd($rrd, $metrix{$attr}{summary}, $metrix{$attr}{number}, $step, $process_time, 'GAUGE'); | ||||
| 				$temp = $metrix{$attr}{summary}/$metrix{$attr}{number}; | ||||
| 				$ret = xCAT_monitoring::rrdutil::push_data_to_rrd($rrd, $temp, $metrix{$attr}{number}, $step, $process_time, 'GAUGE'); | ||||
| 				if($ret != 0){ | ||||
| 					return ($ret, "Can't push data to $rrd\n"); | ||||
| 				} | ||||
| @@ -100,7 +102,8 @@ sub update_metrix2rrd | ||||
| 					} | ||||
| 					if($name eq 'summary'){ | ||||
| 						$rrd = "$rrddir/$attr.rrd"; | ||||
| 						$ret = xCAT_monitoring::rrdutil::push_data_to_rrd($rrd, $metrix{$attr}{$nnlist}{summary}, $metrix{$attr}{$nnlist}{number}, $step, $process_time, 'GAUGE'); | ||||
| 						$temp = $metrix{$attr}{$nnlist}{summary}/$metrix{$attr}{$nnlist}{number}; | ||||
| 						$ret = xCAT_monitoring::rrdutil::push_data_to_rrd($rrd, $temp, $metrix{$attr}{$nnlist}{number}, $step, $process_time, 'GAUGE'); | ||||
| 						if($ret != 0){ | ||||
| 							return($ret, "Can't push data to $rrd\n"); | ||||
| 						} | ||||
| @@ -215,28 +218,28 @@ sub getmetrix | ||||
| 	@attrs = split /,/, $attrlist; | ||||
| 	 | ||||
| 	$attr = join '::', @attrs; | ||||
| 	if(xCAT::Utils->isMN()){ | ||||
| 		if($rname eq "__ALL__"){ | ||||
| 			$cmd = "CT_MANAGEMENT_SCOPE=1 lsrsrc-api -i -s $rsrc"."::::Name::NodeNameList::$attr"; | ||||
| 			@output = xCAT::Utils->runcmd($cmd, 0); | ||||
| 			if($::RUNCMD_RC  != 0){ | ||||
| 				$line = join '', @output; | ||||
| 				return ($::RUNCMD_RC, $line); | ||||
| 			} | ||||
| 			&parse_lsrsrc_output($rsrc, \@attrs, \@output); | ||||
| 		} else { | ||||
| 			@names = split /,/, $rname; | ||||
| 			foreach $name (@names){ | ||||
| 				$cmd = "CT_MANAGEMENT_SCOPE=1 lsrsrc-api -i -s $rsrc"."::\'Name==\"$name\"\'::Name::NodeNameList::$attr"; | ||||
| 				@output = xCAT::Utils->runcmd($cmd, 0); | ||||
| 				if($::RUNCMD_RC != 0){ | ||||
| 					$line = join '', @output; | ||||
| 					return ($::RUNCMD_RC, $line); | ||||
| 				} | ||||
| 				&parse_lsrsrc_output($rsrc, \@attrs, \@output); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| #	if(xCAT::Utils->isMN()){ | ||||
| #		if($rname eq "__ALL__"){ | ||||
| #			$cmd = "CT_MANAGEMENT_SCOPE=1 lsrsrc-api -i -s $rsrc"."::::Name::NodeNameList::$attr"; | ||||
| #			@output = xCAT::Utils->runcmd($cmd, 0); | ||||
| #			if($::RUNCMD_RC  != 0){ | ||||
| #				$line = join '', @output; | ||||
| #				return ($::RUNCMD_RC, $line); | ||||
| #			} | ||||
| #			&parse_lsrsrc_output($rsrc, \@attrs, \@output); | ||||
| #		} else { | ||||
| #			@names = split /,/, $rname; | ||||
| #			foreach $name (@names){ | ||||
| #				$cmd = "CT_MANAGEMENT_SCOPE=1 lsrsrc-api -i -s $rsrc"."::\'Name==\"$name\"\'::Name::NodeNameList::$attr"; | ||||
| #				@output = xCAT::Utils->runcmd($cmd, 0); | ||||
| #				if($::RUNCMD_RC != 0){ | ||||
| #					$line = join '', @output; | ||||
| #					return ($::RUNCMD_RC, $line); | ||||
| #				} | ||||
| #				&parse_lsrsrc_output($rsrc, \@attrs, \@output); | ||||
| #			} | ||||
| #		} | ||||
| #	} | ||||
|  | ||||
| 	if($rname eq "__ALL__"){ | ||||
| 		$cmd = "CT_MANAGEMENT_SCOPE=3 lsrsrc-api -i -s $rsrc"."::::Name::NodeNameList::$attr"; | ||||
| @@ -263,7 +266,7 @@ sub getmetrix | ||||
| 		foreach $nnlist (keys %{$metrix{$attr}}){ | ||||
| 			if(($nnlist ne 'summary') && ($nnlist ne 'number')){ | ||||
| 				$metrix{$attr}{summary} += $metrix{$attr}{$nnlist}{summary}; | ||||
| 				$metrix{$attr}{number} += 1; | ||||
| 				$metrix{$attr}{number} += $metrix{$attr}{$nnlist}{number}; | ||||
| 			} | ||||
| 			 | ||||
| 		} | ||||
| @@ -339,6 +342,7 @@ sub get_sum_metrix | ||||
| 	my @rmc_nodes = (); | ||||
| 	my @svc_nodes = (); | ||||
| 	my $node = undef; | ||||
| 	my $temp = undef; | ||||
| #	my @threads = (); | ||||
| #	my $current_thread = 0; | ||||
| 	my $i = undef; | ||||
| @@ -436,10 +440,12 @@ sub get_sum_metrix | ||||
| 		foreach $nodename (keys %{$summary{$attribute}}){ | ||||
| 			foreach $time (keys %{$summary{$attribute}{$nodename}}){ | ||||
| 				print "$attribute.$nodename.$time $summary{$attribute}{$nodename}{$time}{sum} $summary{$attribute}{$nodename}{$time}{num}\n"; | ||||
| 				$summetrix{$attribute}{$time}{sum} += $summary{$attribute}{$nodename}{$time}{sum}; | ||||
| 				$temp = $summary{$attribute}{$nodename}{$time}{sum} * $summary{$attribute}{$nodename}{$time}{num}; | ||||
| 				$summetrix{$attribute}{$time}{sum} += $temp; | ||||
| 				$summetrix{$attribute}{$time}{num} += $summary{$attribute}{$nodename}{$time}{num}; | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
|  | ||||
| 	my $rrdcluster = "/var/rrd/cluster"; | ||||
| @@ -450,7 +456,8 @@ sub get_sum_metrix | ||||
| 		my @times = keys(%{$summetrix{$attribute}}); | ||||
| 		my @sorttimes = sort @times; | ||||
| 		foreach $time (@sorttimes){ | ||||
| 			$code = xCAT_monitoring::rrdutil::push_data_to_rrd("$rrdcluster/$attribute.rrd", $summetrix{$attribute}{$time}{sum}, $summetrix{$attribute}{$time}{num}, $step, $time, 'GAUGE'); | ||||
| 			$temp = $summetrix{$attribute}{$time}{sum}/$summetrix{$attribute}{$time}{num}; | ||||
| 			$code = xCAT_monitoring::rrdutil::push_data_to_rrd("$rrdcluster/$attribute.rrd", $temp, $summetrix{$attribute}{$time}{num}, $step, $time, 'GAUGE'); | ||||
| 			if($code != 0){ | ||||
| 				return($code, "Can't push data to $rrdcluster/$attribute.rrd"); | ||||
| 			} | ||||
|   | ||||
| @@ -1467,12 +1467,25 @@ sub showmetrix($rrddir, $attrs, $start_time, $end_time) | ||||
| 	my $timestamp = undef; | ||||
| 	my $sum = undef; | ||||
| 	my $num = undef; | ||||
| 	my $remote = undef; | ||||
|  | ||||
| 	if($rrddir =~ /:/){ | ||||
| 		($remote,$rrddir) = split /:/,$rrddir; | ||||
| 	} | ||||
| 	 | ||||
| 	foreach $attr (@attrlist) { | ||||
| 		@namelist = (); | ||||
| 		@timelist = (); | ||||
| 		%hash = {}; | ||||
| 		$output = `ls -A $rrddir/$attr*`; | ||||
| 		if($remote){ | ||||
| 			$output = xCAT::Utils->runcmd("xdsh $remote 'ls -A /var/rrd/$rrddir/$attr*'", 0); | ||||
| 			if($::RUNCMD_RC != 0){ | ||||
| 				return $result; | ||||
| 			} | ||||
| 			$output =~ s/$remote: \/var\/rrd\//''/; | ||||
| 		} else { | ||||
| 			$output = xCAT::Utils->runcmd("ls -A $rrddir/$attr*", 0); | ||||
| 		} | ||||
| 		@files = split /\n/, $output; | ||||
| 		foreach $file (@files) { | ||||
| 			if($file =~ /$attr\.rrd$/){ | ||||
| @@ -1481,7 +1494,11 @@ sub showmetrix($rrddir, $attrs, $start_time, $end_time) | ||||
| 				$name = $1; | ||||
| 			} | ||||
| 			push @namelist, $name; | ||||
| 			$output = xCAT_monitoring::rrdutil::RRD_fetch($file, $start_time, $end_time); | ||||
| 			if($remote){ | ||||
| 				$output = xCAT_monitoring::rrdutil::RRD_fetch($file, $start_time, $end_time, $remote); | ||||
| 			} else { | ||||
| 				$output = xCAT_monitoring::rrdutil::RRD_fetch($file, $start_time, $end_time); | ||||
| 			} | ||||
| 			$line = pop(@$output); | ||||
| 			if($line =~ /ERROR/){ | ||||
| 				push @$result, $line; | ||||
| @@ -1499,7 +1516,7 @@ sub showmetrix($rrddir, $attrs, $start_time, $end_time) | ||||
| 					if(! grep {/$timestamp/} @timelist){ | ||||
| 						push @timelist, $timestamp; | ||||
| 					} | ||||
| 					$hash{$name}{$timestamp} = sprintf "%.4f:%d", $sum, $num; | ||||
| 					$hash{$name}{$timestamp} = sprintf "%.4f", $sum/$num; | ||||
| 				} elsif ($line =~ /^(\d+): (\S+)/){ | ||||
| 					$timestamp = $1; | ||||
| 					$sum = $2; | ||||
| @@ -1578,23 +1595,21 @@ sub show { | ||||
|   if($sum){ | ||||
|     foreach $node (@$noderef){ | ||||
|       if($node eq $localhostname){ | ||||
| 	if($isSV){ | ||||
| 	  $rrddir = "/var/rrd/summary"; | ||||
|         } else { | ||||
| 	  $rrddir = "/var/rrd/cluster"; | ||||
| 	  my @metrixconf = xCAT_monitoring::rmcmetrix::get_metrix_conf(); | ||||
| 	  my $rmetrixcmd = undef; | ||||
|   	  while(@metrixconf){ | ||||
| 	    my ($rsrc, $rname, $attrlist, $minute); | ||||
| 	    $rsrc  = shift @metrixconf; | ||||
| 	    $rname = shift @metrixconf; | ||||
| 	    $attrlist = shift @metrixconf; | ||||
| 	    $minute = shift @metrixconf; | ||||
| 	    $rmetrixcmd = "/opt/xcat/sbin/rmcmon/rmcmetrixmon sum $rsrc $attrlist $minute"; | ||||
| 	    xCAT::Utils->runcmd($rmetrixcmd, 0); | ||||
|           } | ||||
| 	$rrddir = "/var/rrd/cluster"; | ||||
| 	my @metrixconf = xCAT_monitoring::rmcmetrix::get_metrix_conf(); | ||||
| 	my $rmetrixcmd = undef; | ||||
|   	while(@metrixconf){ | ||||
| 	  my ($rsrc, $rname, $attrlist, $minute); | ||||
| 	  $rsrc  = shift @metrixconf; | ||||
| 	  $rname = shift @metrixconf; | ||||
| 	  $attrlist = shift @metrixconf; | ||||
| 	  $minute = shift @metrixconf; | ||||
| 	  $rmetrixcmd = "/opt/xcat/sbin/rmcmon/rmcmetrixmon sum $rsrc $attrlist $minute"; | ||||
| 	  xCAT::Utils->runcmd($rmetrixcmd, 0); | ||||
|         } | ||||
|       }	else { | ||||
|       }	elsif(xCAT::Utils->isSN($node)){ | ||||
| 	$rrddir = "$node:summary"; | ||||
|       } else { | ||||
|         $rrddir = "/var/rrd/$node"; | ||||
|       } | ||||
|       $output = &showmetrix($rrddir, $attrs, $start_time, $end_time); | ||||
| @@ -1613,7 +1628,3 @@ sub show { | ||||
|   return (0, ""); | ||||
| } | ||||
|  | ||||
| #my $nref = ["hv8plus02", "hv8plus03"]; | ||||
| #my $cb = {}; | ||||
| #&show($nref, '0', '100', 'RecByteRate,XmitByteRate', 0, $cb); | ||||
|  | ||||
|   | ||||
| @@ -128,38 +128,6 @@ sub preprocess_request | ||||
|       foreach(@hostinfo) {$iphash{$_}=1;} | ||||
|       if (!$isSV) { $iphash{'noservicenode'}=1;} | ||||
|  | ||||
| #      if($command eq "monshow"){ | ||||
| #	my $keynosvcnode = undef; | ||||
|    #       foreach (@mon_servers){ | ||||
| #	   my @server_pair=split(':', $_); | ||||
| #	   my $sv=$server_pair[0]; | ||||
| #	   my $mon_nodes=$mon_hierachy->{$_}; | ||||
| #	   if ((!$mon_nodes) || (@$mon_nodes ==0)) { next; } | ||||
| #	   if(($sv eq 'noservicenode') && ($a_ret[2] & 0x1)){ | ||||
| #	     $keynosvcnode = $_; | ||||
| #	     my $i = 0; | ||||
| #	     foreach (@$mon_nodes){ | ||||
| #	       if(xCAT::Utils->isSN($_)){ | ||||
| #	         push @{$mon_hierachy->{$_}}, $_; | ||||
| #		 push @mon_servers, $_; | ||||
| #		 delete $mon_nodes->[$i]; | ||||
| #	       } | ||||
| #	       $i++; | ||||
| #	     } | ||||
| #	   } | ||||
| #	} | ||||
| #	if(($keynosvcnode) && ($a_ret[2] & 0x2)){ | ||||
| #	  if(@{$mon_hierachy->{$keynosvcnode}} == 0){ | ||||
| #           my $reqcopy = {%$req}; | ||||
| #	    push @{$reqcopy->{module}}, $a_ret[1]; | ||||
| #	    push @{$reqcopy->{priv}}, $a_ret[2]; | ||||
| #	    push @{$reqcopy->{priv}}, $a_ret[3]; | ||||
| #	    push @{$reqcopy->{priv}}, $a_ret[5]; | ||||
| #	    push @{$reqcopy->{priv}}, $a_ret[6]; | ||||
| #	    push @requests, $reqcopy; | ||||
| #	  } | ||||
| #	} | ||||
| #      } | ||||
|       foreach (@mon_servers) { | ||||
|         #service node come in pairs, the first one is the monserver adapter that facing the mn, | ||||
|         # the second one is facing the cn. we use the first one here | ||||
| @@ -1726,7 +1694,7 @@ sub preprocess_monshow | ||||
|   my $noderange=$ARGV[1]; | ||||
|   @nodes = noderange($noderange); | ||||
|   my @temp = nodesmissed; | ||||
|   if(@temp && xCAT::Utils->isMN()){ | ||||
|   if($sum && @temp && xCAT::Utils->isMN()){ | ||||
|     my $localhost = hostname(); | ||||
|     my $i = 0; | ||||
|     foreach (@temp) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user