VMware Cloud Community
sureshasai
Enthusiast
Enthusiast

Need to be create a Virtual machine health check report for window\Linux in VMware environment.

HI,

I would like to monitor the few servers in VM infra like an exchange, Vcenter server and a connection server for both windows\linux OS.

CPU,RAM, and Disk free space need to add in monitoring report with the percentage.

For example, am having the script for datastore disk space monitoring

Get-Module -Name VMware* -ListAvailable | Import-Module

Connect-VIServer -Server '10.20.10.20'

$head = @"

<style>

TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}

TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;;background-color:thistle}

TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}

</style>

"@

$body = Get-Datastore |

    Select @{N='Datastore';E={$_.Name}},

         @{N='CapacityGB';E={[math]::Round($_.CapacityGB,1)}},

         @{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB,1)}},

         @{N='UsedPercent';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100,1)}},

         @{N='FreePercent';E={

             $p = [math]::Round((1 - ($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB)*100,1)

             if($p -lt 10){"#br#$($p)"}

             elseif($p -lt 30){"#by#$($p)"}

             else{"#bg#$($p)"}

         }} |

     Sort-Object -Property UsedPercent -Descending |

     ConvertTo-Html -Head $head

$body = $body.Replace('>#br#',' bgcolor="red">').Replace('>#by#',' bgcolor="yellow">').Replace('>#bg#',' bgcolor="green">')

$sMail = @{

     To = 'xxxx@xxx.com'

     From = 'xxxx@xxx.com'

     Subject = 'Datastore Report'

     BodyAsHtml = $true

     Body = $body | Out-String   

     SmtpServer = 'owa.XXX.com'

}

Send-MailMessage @sMail

Disconnect-VIServer -Server '10.20.10.20' -Confirm:$false

Tags (1)
0 Kudos
2 Replies
LucD
Leadership
Leadership

So what is the actual question?


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

0 Kudos
sureshasai
Enthusiast
Enthusiast

Hi Lucd,

I would like to set a script for Virtual machines health check like CPU, Disk free space....

0 Kudos