-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathStats using Google charts.ps1
71 lines (56 loc) · 2.17 KB
/
Stats using Google charts.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Variable declaration
$vCenterIPorFQDN="192.168.243.40"
$vCenterUsername="Administrator@vsphere.local"
$vCenterPassword="vmware"
$ESXiHost="192.168.243.62"
$outputFile="C:\Users\Paolo\Desktop\mycharts.html"
$stat = "mem.usage.average" #Stat to measure
#Available stats
#cpu.usage.average
#cpu.usagemhz.average
#mem.usage.average
#disk.usage.average
#net.usage.average
#sys.uptime.latest
Connect-VIServer -Server $vCenterIPorFQDN -User $vCenterUsername -Password $vCenterPassword
$htmlheader = @"
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Virtual Machine', 'Average Usage'], //What we are measuring
"@
$vms = Get-VMHost -Name $ESXiHost | Get-VM | Where-Object PowerState -match "PoweredOn" #Retrieves all powered on VMs from a specific host
#$vms = Get-VM -Server $vCenterIPorFQDN | Where-Object PowerState -match "PoweredOn" #Retrieves all powered on VMs from a vCenter, depending on the number of hosts/VMs this could take a while
foreach ($vm in $vms) {
$value = Get-Stat -Entity $vm.Name -Stat $stat -Start (Get-Date).AddHours(-24) -MaxSamples (10) -IntervalMins 10 | Measure-Object Value -Average
$data += "['$vm', $($value.Average)],"
}
$htmlfooter=@"
]);
var options = {
title: 'Average Network Usage', //Chart Title
pieHole: 0.4, //Option regarding this specific kind of chart
};
var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id='title'>PowerCLI Google Charts</div>$br<div id='subtitle'>Report generated: $(Get-Date)</div>
<div id="box1">
<div id='boxheader'>Average Memory Usage</div>
<div id='boxcontent'>
<div id="donutchart" style="width: 900px; height: 500px;"></div>
</div>
</div>
</body>
</html>
"@
#Generating the output by concatenating strings
$htmlheader + $data + $htmlfooter | Out-File $outputFile