设为首页 收藏本站
查看: 1142|回复: 0

[经验分享] vsphere监控代码备份

[复制链接]

尚未签到

发表于 2015-10-9 14:15:11 | 显示全部楼层 |阅读模式
#!/usr/bin/perl -w
use lib "/opt/limserver/lib/perllib";
use strict;
use warnings;
use VMware::VIRuntime;
use DBI;
use Config::Tiny;
use Log::Minimal;
use File::Stamped;
use Net::Ping;
#use Thread;
use threads;
use threads::shared;
use Sys::CPU;
use Net::Telnet;
use POSIX ":sys_wait_h";
#$SIG{CHLD} = 'IGNORE';
#$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
my %hashCounters=();
my @cpuArr=("usage.average:*");#cpu
my @diskArr=("read.average:*","write.average:*");#disk
my @netArr=("received.average:*","transmitted.average:*","packetsRx.summation:*","packetsTx.summation:*");#net
$hashCounters{"cpu"}=\@cpuArr;
$hashCounters{"disk"}=\@diskArr;
$hashCounters{"net"}=\@netArr;


sub check_health_state{
  my ($state) = shift(@_);
  my $res = "UNKNOWN";
  if (uc($state) eq "GREEN") {
     $res = "OK";
  } elsif (uc($state) eq "YELLOW") {
    $res = "WARNING";
  } elsif (uc($state) eq "RED") {
    $res = "CRITICAL";
  }
  return $res;
}


sub simplify_number{
  my ($number, $cnt) = @_;
  $cnt = 2 if (!defined($cnt));
  return sprintf("%.${cnt}f", "$number");
}
sub convert_number{
  my @vals = split(/,/, shift(@_));
  return shift(@vals) if ($vals[-1] < 0);
  return pop(@vals);
}




sub return_host_performance_values {
  my $values;
  #my $host_name = shift(@_);
  my $host_view=shift(@_);  
  #my $host_view = Vim::find_entity_views(view_type => 'HostSystem', filter => $host_name, properties => [ 'name', 'runtime.inMaintenanceMode' ]); # Added properties named argument.
  #die &quot;Runtime error\n&quot; if (!defined($host_view));
  #die &quot;Host \&quot;&quot; . $$host_name{&quot;name&quot;} . &quot;\&quot; does not exist\n&quot; if (!@$host_view);
  #die {msg => (&quot;NOTICE: \&quot;&quot; . $$host_view[0]->name . &quot;\&quot; is in maintenance mode, check skipped\n&quot;), code => OK} if (uc($$host_view[0]->get_property('runtime.inMaintenanceMode')) eq &quot;TRUE&quot;);
  $values = generic_performance_values($host_view,@_);
  return undef if ($@);
  return ($host_view, $values);
}


sub generic_performance_values {
  my ($views,$hostname,$fileT) = @_;
  my $counter = 0;
  my @values = ();
  my @viewArr=($views);
  #my $amount = @list;
  my $perfMgr = Vim::get_view(mo_ref => Vim::get_service_content()->perfManager, properties => [ 'perfCounter' ]);
  my $retList=get_key_metrices($perfMgr);
  my $hashCounterIdKey= pop(@$retList);
  my $metrices=pop(@$retList);
  my @perf_query_spec = ();
  push(@perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $metrices, format => 'csv', intervalId => 20, maxSample => 1))foreach (@viewArr);
  my $perf_data = $perfMgr->QueryPerf(querySpec => \@perf_query_spec);
  #$amount *= @$perf_data;
  while (@$perf_data){
    my $unsorted = shift(@$perf_data)->value;
    my @host_values = ();
    foreach my $id (@$unsorted){
      foreach my $index (0..@$metrices-1){
        if ($id->id->counterId == $$metrices[$index]->counterId){
   $counter&#43;&#43; if (!defined($host_values[$index]));
          $host_values[$index] = $id;
           my $instance=$id->id->instance;
           my $keyName=$$hashCounterIdKey{$id->id->counterId};
           if($instance eq &quot;&quot; ){
             if($keyName=~/^disk/i){
               print $fileT  $hostname.&quot; &quot;.$keyName.&quot; &quot;.(($id->value)*1024).&quot;\n&quot;;
               #print &quot;---------------********XXXXXX*********-----------------&quot;.$instance.&quot;\n&quot;;
               #print &quot;---------------#######################-----------------&quot;.$$hashCounterIdKey{$id->id->counterId}.&quot;\n&quot;;
               #print &quot;---------------********@@@@@@@*********-----------------&quot;.$id->value.&quot;\n&quot;;
             }
          }
          if($instance ne &quot;&quot; ){
             #my $keyName=$$hashCounterIdKey{$id->id->counterId};
             if($keyName=~/^disk/i){
             #      print $fileT  $hostname.&quot; &quot;.$keyName.&quot; &quot;.$id->value.&quot;\n&quot;;
                   #print &quot;---------------*****************-----------------&quot;.$keyName.&quot;\n&quot;;
                   #print &quot;---------------xxxxxxxxxxxxxx1-----------------&quot;.$instance.&quot;\n&quot;;
             }elsif($keyName=~/^cpu/i){
                   print  $fileT $hostname.&quot; &quot;.$keyName.$instance.&quot; &quot;.($id->value)*0.01.&quot;\n&quot;;
             }else{
                if(($keyName=~/received/i)||($keyName=~/transmitted/i)){
                   print  $fileT $hostname.&quot; &quot;.$instance.&quot;_&quot;.$keyName.&quot; &quot;.(($id->value)*1024).&quot;\n&quot;;
                }else{
                   print  $fileT $hostname.&quot; &quot;.$instance.&quot;_&quot;.$keyName.&quot; &quot;.$id->value.&quot;\n&quot;;
                }
             }
            
          }
        }
      }
    }
    push(@values, \@host_values);
  }
  #return undef if ($counter != $amount || $counter == 0);
  return \@values;
}


sub get_key_metrices {
  my ($perfmgr_view) = @_;
  my $perfCounterInfo = $perfmgr_view->perfCounter;
  my @counters;
  my $k=0;
  my %hashKeyName=();
  my @retArrt=();
  die &quot;Insufficient rights to access perfcounters\n&quot; if (!defined($perfCounterInfo));
  foreach (@$perfCounterInfo) {
    # cpu cpuArr
    if ($_->groupInfo->key eq &quot;cpu&quot;) {
      my $cur_name = $_->nameInfo->key . &quot;.&quot; . $_->rollupType->val;
      foreach my $index (0..@cpuArr-1){
        if ($cpuArr[$index] =~ /$cur_name/){
          $cpuArr[$index] =~ /(\w&#43;).(\w&#43;):*(.*)/;
          $counters[$k] = PerfMetricId->new(counterId => $_->key, instance => $3);
          $hashKeyName{$_->key}=&quot;cpu&quot;;
          $k&#43;&#43;;
        }
      }
    }
    # disk diskArr
    if ($_->groupInfo->key eq &quot;disk&quot;) {
      my $cur_name = $_->nameInfo->key . &quot;.&quot; . $_->rollupType->val;
      foreach my $index (0..@diskArr-1){
        if ($diskArr[$index] =~ /$cur_name/){
          $diskArr[$index] =~ /(\w&#43;).(\w&#43;):*(.*)/;
          $counters[$k] = PerfMetricId->new(counterId => $_->key, instance => $3);
          $hashKeyName{$_->key}=&quot;disk&quot;.$_->nameInfo->key;
          $k&#43;&#43;;
        }
      }
    }
    #net netArr
    if ($_->groupInfo->key eq &quot;net&quot;) {
      my $cur_name = $_->nameInfo->key . &quot;.&quot; . $_->rollupType->val;
      foreach my $index (0..@netArr-1){
        if ($netArr[$index] =~ /$cur_name/){
          $netArr[$index] =~ /(\w&#43;).(\w&#43;):*(.*)/;
          $counters[$k] = PerfMetricId->new(counterId => $_->key, instance => $3);
          $hashKeyName{$_->key}=$_->nameInfo->key;
          $k&#43;&#43;;
        }
      }
    }
  }


  push(@retArrt,\@counters);
  push(@retArrt,\%hashKeyName);
  return \@retArrt;
}
sub getValueBykey{
  my($key,$value,$mem)=@_;
  my $times=1800;
  my $val=$mem->get($key);
  if($val){
     $mem->replace($key,$value,$times);
  }else{
     $mem->add($key,$value,$times);
  }


}

my %opts = (
  entity => {
  type => &quot;=s&quot;,
  variable => &quot;VI_ENTITY&quot;,
  help => &quot;ManagedEntity type: HostSystem, etc&quot;,
  required => 1,
  },
  testType=>{
  type=>&quot;=s&quot;,
  required=>0
  }
  
);


     my $Config = Config::Tiny->new;
     $Config = Config::Tiny->read('/opt/limserver/etc/limserver.conf');
     my $dbname = $Config->{_}->{DBName};
     if(!defined($dbname)){
        $dbname=&quot;&quot;;
     }
     my $location =$Config->{_}->{DBHost};
     if(!defined($location)){
        $location=&quot;127.0.0.1&quot;;
     }
     my $port=$Config->{_}->{DBPort};
     if(!defined($port)){
        $port=&quot;3306&quot;;
     }
     my $db_user=$Config->{_}->{DBUser};
     if(!defined($db_user)){
        $db_user=&quot;root&quot;;
     }
     my $db_pass = $Config->{_}->{DBPassword};
     my $serverIp=$Config->{_}->{SourceIP};
     if(!defined($serverIp)){
        $serverIp=&quot;127.0.0.1&quot;;
     }
     my $serverPort=$Config->{_}->{ListenPort};
     if(!defined($serverPort)){
        $serverPort=&quot;8211&quot;;
     }
     my $mysqlSock=$Config->{_}->{DBSocket};
     my $logPath =$Config->{_}->{LogFile};
     my $logLevel=&quot;INFO&quot;;
     my $debugLevel=$Config->{_}->{DebugLevel};
       if(defined($debugLevel)){
        if($debugLevel==0){
          $logLevel=&quot;MUTE&quot;;
        }elsif($debugLevel==1){
          $logLevel=&quot;CRITICAL&quot;;
        }elsif($debugLevel==2){
          $logLevel=&quot;ERROR&quot;;
        }elsif($debugLevel==3){
          $logLevel=&quot;WARN&quot;;
        }elsif($debugLevel==4){
          $logLevel=&quot;INFO&quot;;
        }
       }else{
          $logLevel=&quot;WARN&quot;;
       }
        
       $logLevel=&quot;INFO&quot;;
     my $ConfigT = Config::Tiny->new;
     $ConfigT = Config::Tiny->read('/opt/limserver/etc/limvsphere.conf');
     my $dirPath=$ConfigT->{_}->{dataDir};
     if(!defined($dirPath)){
        $dirPath=&quot;/vsphereValues&quot;;
     }
     my $senderPath=$ConfigT->{_}->{senderPath};
     my $fh = File::Stamped->new(pattern => $logPath);
     $ENV{LM_DEBUG}  = 1;
     #LM_DEFAULT_COLOR='debug=red:info=;cyan:critical=yellow;red'
     local $Log::Minimal::LOG_LEVEL = $logLevel;
     local $Log::Minimal::PRINT = sub {
       my ( $time, $type, $message, $trace) = @_;
       print  {$fh} &quot; $time [$type] $message at $trace\n&quot;;
     };
#print $dbname.$location.$port.$db_user.$db_pass.&quot;\n&quot;;
my $database = &quot;DBI:mysql:database=$dbname;host=$location;mysql_socket=$mysqlSock&quot;;
#my $database = &quot;DBI:mysql:$dbname:$location:$port&quot;;
my %hashKeyValue=();
    share(%hashKeyValue);
   if(-e $dirPath){
     infof(&quot;------dirPath---exits-----&quot;);
     print &quot;---------exits-----&quot;.&quot;\n&quot;;
   }else{
     mkdir( $dirPath, 0755 );
   }
#my $semaphore;
my $num_proc=0;
my $num_collect=0;
my $collect;
my $hostSleep=0;
#$SIG{CHLD} = sub { $num_proc-- };
#while(1){
my $cpuCores=Sys::CPU::cpu_count();#system(&quot;cat /proc/cpuinfo | grep processor | wc -l&quot;);
if($cpuCores>10){
  $cpuCores=8;
}else{
  $cpuCores=2;
}
infof(&quot;------cpuCores------$cpuCores&quot;);
print &quot;--------cpuCores----------&quot;.$cpuCores.&quot;\n&quot;;
sub REAPER { waitpid(-1 , WNOHANG);$num_proc--;};
$SIG{CHLD} = \&REAPER;
sub mainStart{
  infof(&quot;mianstart sleep &quot;.$hostSleep.&quot; sec&quot;);
  system(&quot;sleep $hostSleep&quot;);
  $num_proc=0;
  $num_collect=0;
  my $zcount=0;
#create a database connect
  print &quot;----db_pass----&quot;.$db_pass.&quot;\n&quot;;
my $dbh;
eval{
  $dbh = DBI->connect($database,$db_user,$db_pass,{RaiseError=>1,AutoCommit=>0,PrintError=>0});
};
if($@){
    my $errNumber=$DBI::err;
    SWITCH:{
    if ($errNumber==1044) {
      infof(&quot;DatabaseName is $database&quot;);
      warnf(&quot;DatabaseName error!&quot;);
      print &quot;DatabaseName error!&quot;;last SWITCH;
    }
    if ($errNumber==1045) {
      warnf(&quot;DB UserName or Password error!&quot;);
      print &quot;DB UserName or Password error!&quot;;
      last SWITCH;
    }
    if ($errNumber==2003) {
      warnf(&quot;Can't connect to MySQL server! Please check out the value of DBhost,DBport and the physical connection that is from cli
ent to MySQL server.&quot;);
      print &quot;Can't connect to MySQL server! Please check out the value of DBhost,DBport and the physical connection that is from client to MySQL server.&quot;;
      last SWITCH;
    }
   if ($errNumber==2013) {
      warnf(&quot;Lost connection to MySQL server!&quot;);
      print &quot;Lost connection to MySQL server!&quot;;
      last SWITCH;
   }
  }
  #exit 0;
}
my $sql=&quot;select hostid,lim_v_address,host,username,password from lim_vsphere_host inner join hosts on status=0 and hostid=zhostid&quot;;
infof(&quot;get host list -> &quot;.$sql);
my $sql2=&quot;select vsphere_refresh_period from config;&quot;;
infof(&quot;get host frequest -> &quot;. $sql2);
my $sthf = $dbh->prepare($sql2);
    $sthf->execute() or die &quot;error:$dbh->errstr&quot;;

my $sth = $dbh->prepare($sql);
    $sth->execute() or die &quot;error:$dbh->errstr&quot;;
my $numRows=$sth->rows;
my @rowf;
while(@rowf=$sthf->fetchrow_array){
   $hostSleep=$rowf[0];
   print &quot;-------rowf-----------&quot;.$rowf[0].&quot;\n&quot;;
}
my @row;
infof(&quot;---------hostSize-----$numRows&quot;);
print $numRows.&quot;----\n&quot;;
#$semaphore = new Thread::Semaphore($numRows);
my @hostArr=();
while(@row=$sth->fetchrow_array){
    my @hostInfoArr=();
    $hostInfoArr[0]=$row[1];
    $hostInfoArr[1]=$row[2];
    $hostInfoArr[2]=$row[3];
    $hostInfoArr[3]=$row[4];
    push(@hostArr,\@hostInfoArr);
}
$dbh->disconnect();
  foreach my $host (@hostArr){
   infof(&quot;-----num_proc-------------$num_proc&quot;);
   infof(&quot;-----zcount------------$zcount&quot;);
   print &quot;-----num_proc-------------&quot;.$num_proc.&quot;\n&quot;;
   print &quot;-----zcount------------&quot;.$zcount.&quot;\n&quot;;
   #print $$host[0];
   #threads->new(\&subThread,$$host[0],$$host[1],$$host[2],$$host[3]);
   #&subThread($$host[0],$$host[1],$$host[2],$$host[3]);
   do {
        sleep(1);
    } until ($num_proc < $cpuCores);
   my $pid = fork();
    if (!defined($pid)) {
        warnf(&quot;Error in fork: $!&quot;);
        print &quot;Error in fork: $!&quot;;
        exit 0;
    }
    if ($pid == 0) {
        ## == child proc ==
        &subThread($$host[0],$$host[1],$$host[2],$$host[3]);
        exit 0;
    }
    $num_proc &#43;&#43;;
    if (($zcount-$num_proc-$num_collect) > 0) {
        while (($collect = waitpid(-1, WNOHANG)) > 0) {
            $num_collect &#43;&#43;;
        }
    }
    #$numRows--;
    $zcount&#43;&#43;;
    #do {
    #    sleep(1);
    #} until ($num_proc < $cpuCores);
  }
&mainStart();
}
&mainStart();


sub subThread{


   my ($ip,$hostname,$username,$password)=@_;#$row_[1];
   my $addr=&quot;https://&quot;.$ip.&quot;/sdk/webService&quot;;
   infof(&quot;-----vspherehostAddr------------$addr&quot;);
   #my $pingobject = Net::Ping->new(&quot;icmp&quot;);
   #if ($pingobject->ping($ip)) {
   #   infof(&quot;vsphere host ip is &quot;.$ip.&quot; -> could reach...&quot;);
   #   $pingobject->close();
   #}else{
   #   warnf(&quot;vsphere host ip is &quot;.$ip.&quot; -> could not reach...&quot;);
   #   $pingobject->close();
   #   exit 0;
   #}
   my $telnet=Net::Telnet->new(Host=>$ip,Port=>'443',Timeout=>'3',Errmode=>'return');
   my $host_status=1;
   unless($telnet){
     warnf(&quot;webService is not connect&quot;);
     system(&quot;$senderPath  -z $serverIp -p $serverPort -s $hostname  -k hostStatus -o 0&quot;);
     exit 0;
   }else{
     infof(&quot;webService  connect ok &quot;);
     #system(&quot;$senderPath  -z $serverIp -p $serverPort -s $hostname  -k hostStatus -o 1&quot;);
   }
   eval {
    infof(&quot;$ip username: $username ; password: $password&quot;);
    Opts::set_option(&quot;url&quot;, $addr);
    Opts::set_option(&quot;username&quot;, $username);
    Opts::set_option(&quot;password&quot;, $password);
    Opts::parse();
    Opts::validate();
    Util::connect();
    #Util::connect($addr, $username, $password);
   };
   if ($@) {
      warnf(&quot;ip=$ip -> &quot;.&quot;$@&quot;);
      exit 0;
   }
   
   print &quot;---ggg----&quot;.&quot;\n&quot;;
   my $entity_type =&quot;HostSystem&quot;;# Opts::get_option('entity');
   #my $esx = {name => $host};
   my $host_view=Vim::find_entity_view(view_type=>$entity_type,properties => ['name','runtime','vm','summary','configManager.datastoreSystem','configManager.dateTimeSystem']);
   unless ($host_view){
    print &quot;host is not found&quot;.&quot;\n&quot;;
  }
   #my $host_view=Vim::find_entity_view(view_type=>$entity_type);
   if(!defined($host_view)){
     warnf(&quot;vsphereHost ip is $ip is wrong&quot;);
     exit 0;
   }
   my $values = $host_view->get_property('summary.quickStats');
   my $hardinfo = $host_view->get_property('summary.hardware');
   #print $hardinfo->model.&quot;\n&quot;;
   
   my $memorySize=$hardinfo->memorySize;
   #print &quot;--------zong------------&quot;.$memorySize.&quot;\n&quot;;
   my $cpuUsageValue = simplify_number($values->overallCpuUsage / ($hardinfo->numCpuCores * $hardinfo->cpuMhz) * 100) if exists($values->{overallCpuUsage}) && defined($hardinfo);
   my $memUsageValue = simplify_number($values->overallMemoryUsage / ($hardinfo->memorySize / 1024 / 1024) * 100) if exists($values->{overallMemoryUsage}) && defined($hardinfo);
   my $memUsageSize = simplify_number($values->overallMemoryUsage*1024*1024) if exists($values->{overallMemoryUsage});
   #print &quot;---------12121------------&quot;.$values->overallMemoryUsage.&quot;\n&quot;;
   #my $diskReadValues = return_host_performance_values($host_view);
   #my $diskRead = simplify_number(convert_number($$diskReadValues[0][0]->value), 0);
   #my $diskWriteValues = return_host_performance_values($esx, 'disk', ('write.average:*'));
   #my $diskWrite = simplify_number(convert_number($$diskWriteValues[0][0]->value), 0);
   #my $host_status=$host_view->runtime->powerState->val;
   my $cpuNum =$hardinfo->numCpuPkgs;
   my $cpuLogicNum=$hardinfo->numCpuThreads;
   my $datetime_system = Vim::get_view(mo_ref => $host_view->get_property('configManager.dateTimeSystem') , properties => ['dateTimeInfo']);
   my $localtime=$datetime_system->QueryDateTime();
   my $config= $host_view->get_property('summary.config');
   my $systemVersion=$config->product->name.&quot;,&quot;.$config->product->version.&quot;,&quot;.$config->product->build;
   my $uptime=$values->uptime;
   my $vmArr = $host_view->vm;
   my $vmCount=0;
   my $vmPowerOnCount=0;
   my $nicNum=$host_view->summary->hardware->numNics;
   foreach my $vm_sub (@$vmArr){
     my $vmObj = Vim::get_view(mo_ref => $vm_sub, properties => ['runtime']);
     if($vmObj->runtime->powerState->val eq &quot;poweredOn&quot;){
        $vmPowerOnCount&#43;&#43;;
     }
     $vmCount&#43;&#43;;
   }
   
   my $sensors= $host_view->runtime->healthSystemRuntime->hardwareStatusInfo->storageStatusInfo;
   my $driveCount=0;
   my $out_file=&quot;$dirPath&quot;.&quot;/&quot;.&quot;$hostname&quot;;
   open(FILE,&quot;>$out_file&quot;);
   my $datastore_system = Vim::get_view(mo_ref => $host_view->get_property('configManager.datastoreSystem'));
   my $ret=$datastore_system->get_property('datastore');
   foreach my $ref_store (@$ret){
     my $store = Vim::get_view(mo_ref => $ref_store, properties => ['summary', 'info']);
     my $value1 = simplify_number(convert_number($store->summary->freeSpace));
     my $value2 = convert_number($store->summary->capacity);
     my $value3 = simplify_number(convert_number($store->info->freeSpace) / $value2 * 100) if ($value2 > 0);
     my $storeName=$store->summary->name;
        print FILE $hostname.&quot; &quot;.&quot;$storeName&quot;.&quot;_freeSpace&quot;.&quot; &quot;.$value1.&quot;\n&quot;;
        print FILE $hostname.&quot; &quot;.&quot;$storeName&quot;.&quot;_capacity&quot;.&quot; &quot;.&quot;$value2&quot;.&quot;\n&quot;;
        print FILE $hostname.&quot; &quot;.&quot;$storeName&quot;.&quot;_freeSpaceUsage&quot;.&quot; &quot;.&quot;$value3&quot;.&quot;\n&quot;;
        
   }
   foreach my $sensor (@$sensors){
      my $value =$sensor->name;
      my $status=$sensor->status->key;
           if ($value=~/^controller/i){
             my $start=index ($value,&quot;(&quot;,0);
             my $length=index($value,&quot;)&quot;,0)-$start;
             my $subStr=substr($value,$start&#43;1,$length-1).&quot;\n&quot;;
             $subStr=~ s/\s//g;
             print FILE $hostname.&quot; &quot;.&quot;raidController&quot;.&quot; &quot;.&quot;$subStr&quot;.&quot;\n&quot;;
           }
           if($value=~/^Battery/i){
             my $length=index ($value,&quot;on&quot;,0);
             my $subStr=substr($value,0,$length-1);
             $subStr=~ s/\s//g;
             print FILE $hostname.&quot; &quot;.&quot;raid_battery&quot;.&quot; &quot;.&quot;$status&quot;.&quot;\n&quot;;
           }
           if($value=~/^Drive/i){
             $driveCount&#43;&#43;;
             my $length=index ($value,&quot;on&quot;,0);
             my $subStr=substr($value,0,$length-1);
             $subStr=~ s/\s//g;
             print FILE $hostname.&quot; &quot;.&quot;$subStr&quot;.&quot; &quot;.$status.&quot;\n&quot;;
          }
          if($value=~/^Port/i){
             my $length=index ($value,&quot;on&quot;,0);
             my $subStr=substr($value,0,$length-1);
             $subStr=~ s/\s//g;
             print FILE $hostname.&quot; &quot;.&quot;$subStr&quot;.&quot; &quot;.check_health_state($status).&quot;\n&quot;;
          }
         if($value=~/^Raid/i){
             my $length=index ($value,&quot;on&quot;,0);
             my $subStr=substr($value,0,$length-1);
             $subStr=~ s/\s//g;
             print FILE $hostname.&quot; &quot;.&quot;$subStr&quot;.&quot; &quot;.$status.&quot;\n&quot;;
          }
     }


    my $memoryIdleSize=$memorySize-$memUsageSize;
     return_host_performance_values($host_view,$hostname,\*FILE);
     print FILE $hostname.&quot; &quot;.&quot;memorySize&quot;.&quot; &quot;.$memorySize.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;memUsage&quot;.&quot; &quot;.$memUsageValue.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;memUsageSize&quot;.&quot; &quot;.$memUsageSize.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;memoryIdleSize&quot;.&quot; &quot;.$memoryIdleSize.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;hostStatus&quot;.&quot; &quot;.$host_status.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;cpuUsage&quot;.&quot; &quot;.$cpuUsageValue.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;cpuLogicNum&quot;.&quot; &quot;.$cpuLogicNum.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;cpuNum&quot;.&quot; &quot;.$cpuNum.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;localtime&quot;.&quot; &quot;.$localtime.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;systemVersion&quot;.&quot; &quot;.$systemVersion.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;uptime&quot;.&quot; &quot;.$uptime.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;vmCount&quot;.&quot; &quot;.$vmCount.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;vmPowerOnCount&quot;.&quot; &quot;.$vmPowerOnCount.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;driveCount&quot;.&quot; &quot;.$driveCount.&quot;\n&quot;;
     print FILE $hostname.&quot; &quot;.&quot;nicNum&quot;.&quot; &quot;.$nicNum.&quot;\n&quot;;
   close(FILE);
   system(&quot;$senderPath  -z $serverIp -p $serverPort -s $hostname  -i $out_file&quot;);
   #$memd->disconnect_all();
   #$semaphore->up();
   #}
   exit 0;
   Util::disconnect();
}
#$dbh->disconnect();# destory a database connect
#Util::disconnect();         版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-124799-1-1.html 上篇帖子: VMware vSphere服务器虚拟化实验二 准备SQL数据库环境 下篇帖子: VMware虚拟化之vSphere4.1-VMotion
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表