VMware Cloud Community
mmmnnnbbb
Contributor
Contributor
Jump to solution

合併顯示問題Combined display issues

以下是我參考網路上寫出來的語法

但是有個問題我無法排除

一台虛擬機可能有scsi0:0 或ide0:0

我無法單獨選擇我要的類型合併顯示

不知道語法哪裡需要修改

麻煩 指導我一下 感激不盡

I  learn  from the Internet to write following script

But there is a problem I can not solve

A virtual machine may use scsi0: 0 or ide0: 0

Can not single type combinations to display

I do not know where the script need to be modified

Please tell me how to modify the script

Thank you very much

============================================

$entity  = Get-Vm | where {$_.NAME -eq "eBOOK"}
$APP = @()
$runday = ((get-date).day -1)
$day = (get-date).day
$runmonth = (get-date).month
$runyear = (get-date).year
$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation","cpu.capacity.entitlement.average","cpu.corecount.contention.average","mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average","mem.vmmemctl.average","mem.consumed.average","mem.overhead.average","mem.capacity.entitlement.average","mem.capacity.usage.average","disk.usage.average","net.usage.average","virtualDisk.throughput.usage.average"
$savepath = "c:\" + $entity + "-" + "$runyear" + "-" + "$runmonth" + "-" +"$runday" + ".csv"
$start = "$runmonth"+"/"+"$runday"+"/"+"$runyear"
$finish = "$runmonth"+"/"+"$day"+"/"+"$runyear"
$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish
$stats | where {"ide0:0","scsi0:0" -contains $_.Instance}| Group-Object -Property Instance | where {$_.Timestamp -ne "",$_.value -ne ""} | %{
     $_.Group | Group-Object -Property {$_.Timestamp} | %{
        $row = "" | Select "time","cpu_usage_average","cpu_usagemhz_average","cpu_ready_summation","cpu_capacity_entitlement_average","cpu_corecount_contention_average","mem_usage_average","mem_swapinRate_average","mem_swapoutRate_average","mem_vmmemctl_average","mem_consumed_average","mem_overhead_average","mem_capacity_entitlement_average","mem_capacity_usage_average","disk_usage_average","net_usage_average","virtualDisk_throughput_usage_average"
   $row."time" = $_.Group[0].Timestamp
        $row."cpu_usage_average" = $_.Group[0].value
$row."cpu_usagemhz_average" = $_.Group[1].value
$row."cpu_ready_summation" = $_.Group[2].value
$row."cpu_capacity_entitlement_average" = $_.Group[3].value
$row."cpu_corecount_contention_average" = $_.Group[4].value
$row."mem_usage_average" = $_.Group[5].value
$row."mem_swapinRate_average" = $_.Group[6].value
$row."mem_swapoutRate_average" = $_.Group[7].value
$row."mem_vmmemctl_average" = $_.Group[8].value
$row."mem_consumed_average" = $_.Group[9].value
$row."mem_overhead_average" = $_.Group[10].value
$row."mem_capacity_entitlement_average" = $_.Group[11].value
$row."mem_capacity_usage_average" = $_.Group[12].value
$row."disk_usage_average" = $_.Group[13].value
$row."net_usage_average" = $_.Group[14].value
$row."virtualDisk_throughput_usage_average" = $_.Group[15].value
   $APP += $row
}
}
$APP |sort time
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

So if I understand correctly you want something like this in the output

VMName              VM1     VM2

CPU Usage Avg        17      28

CPU Usage Avg MHz   732     453


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

Would love to help you, but I'm afraid something went wrong during the copy of the script.

I get a bunch of what I think are Chinese characters in there


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership
Jump to solution

If your question, I guess, is how you can include metrics for ide0:0 and scsi0:0 in the output, there are several ways of doing that.

The simplest is to replace this line

$stats | where {$_.Instance -eq "scsi0:0"}| Group-Object -Property Instance | %{

with something like this

$stats | where {"ide0:0","scsi0:0" -contains $_.Instance}| Group-Object -Property Instance | %{

If I completely misunderstood the question please let me know


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mmmnnnbbb
Contributor
Contributor
Jump to solution

1 , yes  u got me

2 , i am so sorry that i posted wrong script , i forgot to add to some parameters.andd i changed chinese to Eng ^^

3. the script you posted i tried before ,and it show  nothing.

4.i will upload script  with Successful execl file in rar .

5.thanks anyway

show nothing

=======================================

$entity  = Get-Vm | where {$_.NAME -eq "eBOOK"}
$APP = @()
$runday = ((get-date).day -1)
$day = (get-date).day
$runmonth = (get-date).month
$runyear = (get-date).year
$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation","cpu.capacity.entitlement.average","cpu.corecount.contention.average","mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average","mem.vmmemctl.average","mem.consumed.average","mem.overhead.average","mem.capacity.entitlement.average","mem.capacity.usage.average","disk.usage.average","net.usage.average","virtualDisk.throughput.usage.average"
$savepath = "c:\" + $entity + "-" + "$runyear" + "-" + "$runmonth" + "-" +"$runday" + ".csv"
$start = "$runmonth"+"/"+"$runday"+"/"+"$runyear"
$finish = "$runmonth"+"/"+"$day"+"/"+"$runyear"
$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish
$stats | where {"ide0:0","scsi0:0" -contains $_.Instance}| Group-Object -Property Instance | where {$_.Timestamp -ne "",$_.value -ne ""} | %{
     $_.Group | Group-Object -Property {$_.Timestamp} | %{
        $row = "" | Select "time","cpu_usage_average","cpu_usagemhz_average","cpu_ready_summation","cpu_capacity_entitlement_average","cpu_corecount_contention_average","mem_usage_average","mem_swapinRate_average","mem_swapoutRate_average","mem_vmmemctl_average","mem_consumed_average","mem_overhead_average","mem_capacity_entitlement_average","mem_capacity_usage_average","disk_usage_average","net_usage_average","virtualDisk_throughput_usage_average"
   $row."time" = $_.Group[0].Timestamp
        $row."cpu_usage_average" = $_.Group[0].value
$row."cpu_usagemhz_average" = $_.Group[1].value
$row."cpu_ready_summation" = $_.Group[2].value
$row."cpu_capacity_entitlement_average" = $_.Group[3].value
$row."cpu_corecount_contention_average" = $_.Group[4].value
$row."mem_usage_average" = $_.Group[5].value
$row."mem_swapinRate_average" = $_.Group[6].value
$row."mem_swapoutRate_average" = $_.Group[7].value
$row."mem_vmmemctl_average" = $_.Group[8].value
$row."mem_consumed_average" = $_.Group[9].value
$row."mem_overhead_average" = $_.Group[10].value
$row."mem_capacity_entitlement_average" = $_.Group[11].value
$row."mem_capacity_usage_average" = $_.Group[12].value
$row."disk_usage_average" = $_.Group[13].value
$row."net_usage_average" = $_.Group[14].value
$row."virtualDisk_throughput_usage_average" = $_.Group[15].value
   $APP += $row
}
}
$APP |sort time

if i move red line it run well

===============================================

$entity  = Get-Vm | where {$_.NAME -eq "eBOOK"}

$APP = @()

$runday = ((get-date).day -1)

$day = (get-date).day

$runmonth = (get-date).month

$runyear = (get-date).year

$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation","cpu.capacity.entitlement.average","cpu.corecount.contention.average","mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average","mem.vmmemctl.average","mem.consumed.average","mem.overhead.average","mem.capacity.entitlement.average","mem.capacity.usage.average","disk.usage.average","net.usage.average"

$savepath = "c:\" + $entity + "-" + "$runyear" + "-" + "$runmonth" + "-" +"$runday" + ".csv"

$start = "$runmonth"+"/"+"$runday"+"/"+"$runyear"

$finish = "$runmonth"+"/"+"$day"+"/"+"$runyear"

$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish

$stats | Group-Object -Property Instance | where {$_.Timestamp -ne "",$_.value -ne ""} | %{

     $_.Group | Group-Object -Property {$_.Timestamp} | %{

        $row = "" | Select "time","cpu_usage_average","cpu_usagemhz_average","cpu_ready_summation","cpu_capacity_entitlement_average","cpu_corecount_contention_average","mem_usage_average","mem_swapinRate_average","mem_swapoutRate_average","mem_vmmemctl_average","mem_consumed_average","mem_overhead_average","mem_capacity_entitlement_average","mem_capacity_usage_average","disk_usage_average","net_usage_average"

    $row."time" = $_.Group[0].Timestamp

        $row."cpu_usage_average" = $_.Group[0].value

$row."cpu_usagemhz_average" = $_.Group[1].value

$row."cpu_ready_summation" = $_.Group[2].value

$row."cpu_capacity_entitlement_average" = $_.Group[3].value

$row."cpu_corecount_contention_average" = $_.Group[4].value

$row."mem_usage_average" = $_.Group[5].value

$row."mem_swapinRate_average" = $_.Group[6].value

$row."mem_swapoutRate_average" = $_.Group[7].value

$row."mem_vmmemctl_average" = $_.Group[8].value

$row."mem_consumed_average" = $_.Group[9].value

$row."mem_overhead_average" = $_.Group[10].value

$row."mem_capacity_entitlement_average" = $_.Group[11].value

$row."mem_capacity_usage_average" = $_.Group[12].value

$row."disk_usage_average" = $_.Group[13].value

$row."net_usage_average" = $_.Group[14].value

    $APP += $row

}

}

$APP |sort time

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The filtering on the instances is happening too soon. At that time you have metrics for all the counetr types you specified.

Meaning that this where-clause will throw away all the metrics that do have a ide0:0 or scsi0:0 instance.

The grouping should be organised in the order that you want your results: so first group on Timestamp and then on Entity (the VM name).

In the resulting group you will now have metrics for all the counters your specified on the Get-Stat cmdlet.

For the disk.usage.average counter, what do you want to include in the report ?

Only the values for IDE0:0 or SCSI0:0 ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mmmnnnbbb
Contributor
Contributor
Jump to solution

i want  the values for  SCSI0:0 in that file ^^

another question how can i change the file form like below ....

A , B , C
1 , 2 , 3
4 , 5 , 6

i want to transpose rows into columns like

A , 1 , 4
B , 2 , 5
C, 3 , 6

plz help me   thank ^^

0 Kudos
LucD
Leadership
Leadership
Jump to solution

So if I understand correctly you want something like this in the output

VMName              VM1     VM2

CPU Usage Avg        17      28

CPU Usage Avg MHz   732     453


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mmmnnnbbb
Contributor
Contributor
Jump to solution

yes , i want your output , but i dont know how to do ~
please help me thank you ^^
and i still have an issue
in the output only can create one CSV named ebook-day.csv

,how can i use follow output replace and create different CSV file

please help me

$entity = Get-Vm | where {$_.PowerState -eq "PoweredOn"}

replace ↓


$entity = Get-Vm | where {$_.NAME -eq "eBOOK"}
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The attached script will produce the results you are looking for.

But for the transpose part I would still need some further clarification.

The resulting CSV, 1 CSV per powered on VM, from this script looks something like this

Is this the table you want to transpose ?

In other words the result would look like this

Time
20/04/13 00:30
20/04/13 01:0020/04/13 01:30
cpu_usage_average15.917.312.3
cpu_usagemhz_average
872889855
cpu_ready_summation
753081427211

Is that what you want ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mmmnnnbbb
Contributor
Contributor
Jump to solution

DEAR LucD

Something happens at home , I'm so sorry.to keep you waiting so many days,

at before ,my boss want that transpose form ,but he changed his mind again and again,
I really do not want to meet the needs for him.Damn it
your script work very nice ,You were great, I deeply admire you
the output very helpful.thank you, my one issue got solve. ^^
$_.Group | where {($_.MetricId -ne "virtualDisk.throughput.usage.average" -and $_.Instance -eq "") -or
($_.MetricId -eq "virtualDisk.throughput.usage.average" -and $_.Instance -eq "SCSI0:0")} | %{
Add-Member -InputObject $row -Name ($_.MetricId).Replace('.','_') -Value $_.Value -MemberType NoteProperty
could i ask for another question ???
i try modify from your script to run in the output ,it run well ,but be created  second file in second folder always include first file value. .
if i want 1 VMguest when do Cmdlet (get-stat) it could creat itself  folder and use VMguest name to replace folder name ,
and then do Cmdlet (export-csv)  , it could  establish file into that folder without other value , i still can't find out how to Separate that
thank for your kindness
===========================================
$args = Get-Vm | where {$_.PowerState -eq "PoweredOn"}|sort name
$APP = @()
For($i=0;$i -lt $args.Count; $i++)
{
$entity = $($args[$i])
New-Item -Path "C:\1\$entity" -ItemType "directory" 
$finish = Get-Date -Hour 0 -Minute 0 -Second 0
$start = $finish.AddDays(-1)
$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation",
"cpu.capacity.entitlement.average","cpu.corecount.contention.average",
"mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average",
"mem.vmmemctl.average","mem.consumed.average","mem.overhead.average",
"mem.capacity.entitlement.average","mem.capacity.usage.average",
"disk.usage.average","net.usage.average","virtualDisk.throughput.usage.average"
$stats = Get-Stat -Entity $entity -Stat $metrics -Start $start -Finish $finish
$stats|sort Timestamp|Group-Object -Property {$_.Entity.Name} | %{
$_.Group | Group-Object -Property Timestamp | %{
$row = "" | Select Name, Time
$row."Name" = $entity
$row."time" = $_.Group[0].Timestamp
$_.Group | where {($_.MetricId -ne "virtualDisk.throughput.usage.average" -and $_.Instance -eq "") -or
($_.MetricId -eq "virtualDisk.throughput.usage.average" -and $_.Instance -eq "SCSI0:0")} | %{
Add-Member -InputObject $row -Name ($_.MetricId).Replace('.','_') -Value $_.Value -MemberType NoteProperty
}
$APP += $row
}
$savepath = "c:\1\" + $entity +"\" + $entity + "-" + $start.ToString("yyyy-MM-dd") + ".csv"
$APP | Export-Csv -Path $savepath -encoding utf8 -NoTypeInformation
[System.IO.File]::ReadAllText($savepath) | out-file $savepath  -encoding OEM
}
}
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, but I'm not sure I understand what you are trying to do.

My script creates 1 CSV file per VM.

Are you trying to store the results from all VMs in 1 file ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mmmnnnbbb
Contributor
Contributor
Jump to solution

Dear LucD

Sorry,I did not explain well , my english not well ^^

I am using a Chinese system,so i used your script and modify some place. like red  line  and than it could make i want 1 CSV file per VM.

thanks a lot  ^^

but still have one issue with  blue line ,when folder exist  it show the folder already exist  ,  if  the folder already exist ,i want to it will skip to create folder action  , but still creat CSV file ,please tell me where Should modify it

====================================================

$args = Get-Vm | where {$_.PowerState -eq "PoweredOn"}|sort name
For($i=0;$i -lt $args.Count; $i++)
{
$APP = @()
$entity = $args[$i]
New-Item -Path "C:\1\$entity" -ItemType "directory" 
$finish = Get-Date -Hour 0 -Minute 0 -Second 0
$start = $finish.AddDays(-1)
$metrics = "cpu.usage.average","cpu.usagemhz.average","cpu.ready.summation",
"cpu.capacity.entitlement.average","cpu.corecount.contention.average",
"mem.usage.average","mem.swapinRate.average","mem.swapoutRate.average",
"mem.vmmemctl.average","mem.consumed.average","mem.overhead.average",
"mem.capacity.entitlement.average","mem.capacity.usage.average",
"disk.usage.average","net.usage.average","virtualDisk.throughput.usage.average"
$stats = Get-Stat -Entity $args[$i] -Stat $metrics -Start $start -Finish $finish
$stats|sort Timestamp|Group-Object -Property {$_.Entity.Name} | %{
$_.Group | Group-Object -Property Timestamp | %{
$row = "" | Select Name, Time
$row."Name" = $entity
$row."time" = $_.Group[0].Timestamp
$_.Group | where {($_.MetricId -ne "virtualDisk.throughput.usage.average" -and $_.Instance -eq "") -or
($_.MetricId -eq "virtualDisk.throughput.usage.average" -and $_.Instance -eq "SCSI0:0")} | %{
Add-Member -InputObject $row -Name ($_.MetricId).Replace('.','_') -Value $_.Value -MemberType NoteProperty
}
$APP += $row
}
$savepath = "c:\1\" + $entity +"\" + $entity + "-" + $start.ToString("yyyy-MM-dd") + ".csv"
$APP | Export-Csv -Path $savepath -encoding utf8 -NoTypeInformation
[System.IO.File]::ReadAllText($savepath) | out-file $savepath  -encoding OEM
}
}
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try it like this

New-Item -Path "C:\1\$($entity)" -ItemType "directory"



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos