• 通过powershell读取性能计数器


    读取指定文件夹里性能计数器文件的信息,取出各个counter的平均值,存储在csv

    param($folderPath="")

    function funhelp()
    {
    $helpText=@"
    NAME: PerformanceCounterCalculation)_multipleFile.ps1
    This script will loop all the counters and calcualte the average value
    PARAMETERS:
    -$folderPath Specifies the folder of the .BLG you want to get
    SYNTAX:
    PerformanceCounterCalculation)_multipleFile.ps1 -folderPath 
    "c:\disk\*"
    "@
    Write
    -Host $helpText -ForegroundColor Green
    exit
    }

    #define PerformanceCounter CLASS
     $source = @"
        public class PerformanceCounter
        {
            private string computerName;
      private string counterPath;
            private double value;
         private  string date;
            public PerformanceCounter(string computerName,string counterPath, double value,string date)
            {
      
      this.computerName = computerName;
                this.counterPath = counterPath;
                this.value = value;
       this.date=date;
               
            }
            public double Value
            {
                get { return this.value; }
            }
      
       public string CounterPath
            {
                get { return this.counterPath; }
            }
      public string ComputerName
            {
                get { return this.computerName; }
            }
      
       public string Date
            {
                get { return this.date; }
            }
         
        }
    "@
     
    #------------------------------------------------------This script will loop all the counters and calcualte the average value
    function Cal([string]$filename)
    {
        
    $PathCount=0;
        
    $CounterArray=import-counter $filename
        
    $PathCount=$CounterArray[0].CounterSamples.Count
        
    for($i=0;$i -lt $PathCount;$i++)
        {
            
    $total=0
            
    foreach ($singleCounterArray in $CounterArray)
            {
            
    $total=$total+$singleCounterArray.CounterSamples[$i].CookedValue
            }
            
    $averageValue= $total/$CounterArray.count
            
    $countPath=$CounterArray[0].CounterSamples[$i].Path;
            
    $countPath=$countPath.Substring(2,$countPath.Length-2);#elminiate the first \\
            $computerName=$countPath.Substring(0,$countPath.IndexOf("\"));#get the computername 
            $countPath=$countPath.Substring($countPath.IndexOf("\"),$countPath.Length-$countPath.IndexOf("\"));#remove the computername 
            $date=[string]$CounterArray[0].Timestamp.ToString("yyyyMMdd");
            
    $counter=New-Object PerformanceCounter($computerName,$countPath,$averageValue,$date); 

            
    $c=$a.add($counter# $.add operation will output the number of PerformanceCounter,  add $c to elimiate the behavior
        }
    }

    if ($folderPath -eq "")#$folderPath can't be empty
     {
        funhelp
        exit
     }
     
    $a=New-Object System.Collections.ArrayList
    Add
    -Type -TypeDefinition $source
    $blgList=Get-Item $folderPath -include *.blg
    $processedNumber=0
    foreach($blg in $blgList)
    {
     
    $processedNumber=$processedNumber+1
     Cal([string]
    $blg.FullName)
     Write
    -Host   $processedNumber "files of " $blgList.count "have been processed"
    }
    Write
    -Host "Process done, Please wait..." -ForegroundColor Green
    $filename="result"+[system.datetime]::now.ToString("yyyyMMddhhmmss")+".csv"
    $a |Export-Csv $filename
    Write
    -Host "Please check" $filename "for detail" -ForegroundColor Green

    下面是csv文件的效果图

    1

    2

    3

  • 相关阅读:
    GAMIT中遇到的错误
    bash: ./install_software: Permission denied
    xmanager无法加载远程桌面
    GMT的安装
    小总结:Gamit中常见常用命令
    动态分配指针数组(以解决)
    Gamit使用gftp软件下载数据
    Python基础(1)
    JAVA中关于多线程的理解
    JAVA 基本绘图——利用JFrame JPanel 绘制扇形
  • 原文地址:https://www.cnblogs.com/stswordman/p/1868887.html
Copyright © 2020-2023  润新知