-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpollEstablishedConnections.ps1
More file actions
60 lines (50 loc) · 3.11 KB
/
pollEstablishedConnections.ps1
File metadata and controls
60 lines (50 loc) · 3.11 KB
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
# This script documents the number of established connections to an ArcGIS Server machine's internal Tomcat.
# This script has to be run on the machine of interest (it does not work remotely).
# Edit the "sleepSeconds" to establish how often the established connections will be counted (60 second default)
# The script will run in an infinite loop, writing the counts to the file you configure with the "establishedConnectionLogFile" variable
# If the count exceeds the "establishedConnectionThresholdForDetail" value, it will write a second file
# following the pattern established in the "localPort6443DetailPatternLogFile" variable to give you more detail.
# Run this PowerShell script via Windows Task Scheduler.
# Set the Trigger to begin the task at startup.
# Allow the task to be run on demand.
# Then, manually start the task. It will run until the machine restarts; at which point it will re-start when the machine comes up again.
# Stop the task when it is no longer needed.
# While the output does not use much space, you should not let this script run forever because it has no "clean-up" logic ...
# it will keep accumulating output until there is no more space on your system.
# So, use this for troubleshooting. And, when the trouble has been resolved, or this information is no longer useful, stop and disable or delete the task.
# Copyright 2025 Esri
#
# Licensed under the Apache License Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
$sleepSeconds = 60
$establishedConnectionLogFile = "c:\temp\established_connection_count_to_6443.log"
$establishedConnectionThresholdForDetail = 300
$localPort6443DetailPatternLogFile = "c:\temp\localPort6443Detail_[TIMESTAMP].log"
while ($true)
{
# Get a count of the established connections to 6443
$d = Get-Date -Format "u"
$cnt = [string]((Get-NetTCPConnection -State Established) | Where-Object { $_.LocalPort -eq "6443" }).Count
# If the count exceeds a threshold of interest, collect more detail and write it out to a separate file
if ($cnt -gt $establishedConnectionThresholdForDetail)
{
$localPort6443DetailContent = (Get-NetTCPConnection ) | Where-Object { $_.LocalPort -eq "6443" } | Out-String
$currentTimeString = Get-Date -Format "yyyy_MM_dd_hh_mm_ss"
$currentFileName = $localPort6443DetailPatternLogFile.Replace("[TIMESTAMP]",$currentTimeString)
Add-Content -Path $currentFileName -Value $localPort6443DetailContent
}
# Record the established connection count to an accumulating log file
$logEntry = $d + ", " + $cnt
Add-Content -Path $establishedConnectionLogFile -Value $logEntry
# Wait for a configured period of time
Start-Sleep -Seconds $sleepSeconds
}