@@ -34,14 +34,20 @@ The default value is 30.
34
34
35
35
Capture point-in-time CPU utilization value rather than a peak and average over a given time.
36
36
37
+ . PARAMETER Measurements
38
+
39
+ Specifies if the data should be output in a structure that matches the TMP /measurements endpoint.
40
+ This is intended to capture point-in-time CPU Utilization.
41
+
37
42
. INPUTS
38
43
39
44
None. You cannot pipe objects to runner.ps1
40
45
41
46
. OUTPUTS
42
47
43
- runner.ps1 generates a JSON output with all the gathered data suitable to be
44
- used with Tidal Tools or Tidal Migrations API.
48
+ Default behaviour will output JSON which is suitable to pipe to the Tidal Tools command "tidal sync servers".
49
+
50
+ Adding the -Measurements flag will output JSON which is suitable to pipe to the Tidal Migrations Platform /measurements API endpoint.
45
51
46
52
. EXAMPLE
47
53
@@ -51,6 +57,8 @@ used with Tidal Tools or Tidal Migrations API.
51
57
52
58
.\runner.ps1 -UserName myuser
53
59
60
+ .\runner.ps1 -UserName myuser -Measurements
61
+
54
62
#>
55
63
[CmdletBinding ()]
56
64
param (
@@ -84,9 +92,19 @@ param (
84
92
85
93
[Parameter ()]
86
94
[switch ]
87
- $CpuUtilizationOnlyValue
95
+ $CpuUtilizationOnlyValue ,
96
+
97
+ [Parameter ()]
98
+ [switch ]
99
+ $Measurements
88
100
)
89
101
102
+ # If the -Measurements flag is used, set -CPUUtilizationOnlyValue and -CPUUtilizationTimeout 1
103
+ if ($Measurements ) {
104
+ $CpuUtilizationOnlyValue = $true
105
+ $CpuUtilizationTimeout = 1
106
+ }
107
+
90
108
if (! [System.IO.File ]::Exists($SecurePwdFilePath )) {
91
109
Write-Error " $SecurePwdFilePath does not exist. Be sure to run save_password.ps1 before trying again."
92
110
exit 1
@@ -98,7 +116,7 @@ $secPwd = Get-Content $SecurePwdFilePath | ConvertTo-SecureString
98
116
$cred = New-Object System.Management.Automation.PSCredential - ArgumentList $UserName , $secPwd
99
117
100
118
try {
101
- $env_user = Invoke-Command - ComputerName ([Environment ]::MachineName) - Credential $cred - ScriptBlock { $env: USERNAME } - ErrorAction Stop
119
+ $env_user = Invoke-Command - ComputerName ([Environment ]::MachineName) - Credential $cred - ScriptBlock { $env: USERNAME } - ErrorAction Stop
102
120
Write-Host " Executing inventory gathering as user: $env_user ..."
103
121
} catch [System.Management.Automation.Remoting.PSRemotingTransportException ] {
104
122
Write-Host " Executing inventory gathering..."
@@ -122,15 +140,15 @@ $server_list | ForEach-Object {
122
140
if ($NoWinRM ) {
123
141
$startJobParams = @ {
124
142
ScriptBlock = $ServerStats
125
- ArgumentList = $_ , $cred , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM
143
+ ArgumentList = $_ , $cred , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM , $Measurements
126
144
}
127
145
$jobs += Start-Job @startJobParams
128
146
} else {
129
147
$invokeCommandParams = @ {
130
148
ComputerName = $_
131
149
Credential = $cred
132
150
ScriptBlock = $ServerStats
133
- ArgumentList = " localhost" , $null , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM
151
+ ArgumentList = " localhost" , $null , $ProcessStats , $CpuUtilizationTimeout , $CpuUtilizationOnlyValue , $NoWinRM , $Measurements
134
152
}
135
153
$jobs += Invoke-Command @invokeCommandParams - AsJob
136
154
}
@@ -155,14 +173,22 @@ Do {
155
173
} Until (($jobs | Get-Job | Where-Object { (($_.State -eq " Running" ) -or ($_.state -eq " NotStarted" )) }).count -eq 0 )
156
174
157
175
$jobs | Receive-Job | ForEach-Object {
158
- $server_stats += $_
176
+ $server_stats += $_ | Select - Property * - ExcludeProperty PSComputerName , RunSpaceID , PSShowComputerName
159
177
}
160
178
161
179
$num_results = $server_stats.Count
162
180
Write-Host " $num_results results received out of $num_servers servers."
163
181
164
- # Output results
165
- $results = @ { servers = $server_stats }
182
+ # # Build result
183
+
184
+ # Set root object key
185
+ $root_object_key = " servers"
186
+ if ($Measurements ) {
187
+ $root_object_key = " measurements"
188
+ }
189
+
190
+ # output result
191
+ $results = @ { $root_object_key = $server_stats }
166
192
$json = $results | ConvertTo-Json - Depth 99
167
193
Write-Output $json
168
194
0 commit comments