/
Get-ConnectedCacheIISStats.ps1
149 lines (103 loc) · 3.66 KB
/
Get-ConnectedCacheIISStats.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
Outputs statistics form IIS log files relating to Microsoft Connected Cache
.DESCRIPTION
Outputs statistics form IIS log files relating to Microsoft Connected Cache
.OUTPUTS
Outputs to an PowerShell object containing information on AWS instances.
.PARAMETER NumberOfLogs
Number of ISS logs to process, most recent first.
.PARAMETER IISLogPath
Path to IIS Log Directory
.PARAMETER DOUserAgent
Delivery optimization User Agent
.EXAMPLE
&.\Get-ConnectedCacheIISStats.ps1
.NOTES
Author: Andy Cattle
Change Log:
03/03/2020: Initial Version
#>
Param (
[Parameter(Mandatory=$false)]
[int]$NumberOfLogs = 3,
[Parameter(Mandatory=$false)]
[string]$IISLogPath = "C:\inetpub\logs\LogFiles\W3SVC1",
[Parameter(Mandatory=$false)]
[string]$DOUserAgent = "Microsoft-Delivery-Optimization/10.0"
)
function Parse-IISLog {
Param (
[Parameter(Mandatory=$true, Position=0,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$true)]
[Alias('FullName')]
[string[]]$Path
) Process {
foreach ($P in $Path) {
Write-Verbose "Processing IIS Log File: $p"
$Fields = (Get-Content $P `
| Select-Object -First 10 `
| Where-Object {$_ -match "\#Fields\: "}
) -replace "\#Fields\: " -split " "
Get-Content $P `
| Where-Object {$_[0] -ne "#"} `
| ForEach-Object {
$Entry = @{}
$i = 0
$_ -split " " | ForEach-Object {
$Entry[$Fields[$i++]] = $_
}
[pscustomobject]$Entry
}
}
}
}
$LogsFiles = Get-ChildItem $IISLogPath
$DOData = $LogsFiles | Where-Object {$_.Name -like "u_ex*.log"} `
| Sort-Object Name -Descending | select -First $NumberOfLogs `
| Parse-IISLog -Verbose `
| Where-object {$DOUserAgent -contains $_."cs(User-Agent)"}
$DataByIP = $DOData | Group-Object c-ip | Select-Object @(
@{
Name = "IP Address"
Expression = {$_."Name"}
}
@{
Name = "Data GB"
Expression = {
$Bytes = $_.Group."sc-bytes" `
| Measure-Object -Sum `
| Select-Object -ExpandProperty Sum `
"{0:n2}" -f ($bytes / 1GB)
}
}
) | Sort-Object "IP Address"
$DataBySubnet = $DataByIP | ForEach-Object {
[pscustomobject] @{
"Subnet" = $_."IP Address" -replace "\d+\.\d+$","0.0"
"Data GB" = $_."Data GB"
}
} | Group-Object Subnet | Select-Object @(
@{
Name = "Subnet"
Expression = {$_."Name"}
}
@{
Name = "Data GB"
Expression = {
$GBytes = $_.Group."Data GB" `
| Measure-Object -Sum `
| Select-Object -ExpandProperty Sum `
"{0:n2}" -f $GBytes
}
}
)
$TotalData = "{0:n2}" -f (($DOData."sc-bytes" `
| Measure-Object -Sum `
| Select-Object -ExpandProperty Sum) / 1GB)
Write-Host "Total Connected Cache Data: $($TotalData)GB" -ForegroundColor Yellow
Write-Host "`nData by Subnet (2 octets):" -ForegroundColor Cyan
$DataBySubnet | Format-Table -AutoSize
Write-Host "Data by IP Address:" -ForegroundColor Cyan
$DataByIP | Format-Table -AutoSize