Skip to content

Commit 15146a1

Browse files
committed
Merge pull request #29 from CarlRabeler/elastic
bill
2 parents 002ecfe + 1c2520f commit 15146a1

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

Binary file not shown.

samples/manage/azure-sql-db-elastic-pools/PoolTelemetry.ps1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ----------------------------------------------------------------------------------
1+
# ----------------------------------------------------------------------------------
22
#
33
# Copyright Microsoft Corporation
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,12 +12,14 @@
1212
# limitations under the License.
1313
# ---------------------------------------------------------------------------------
1414
#
15-
# Sample script for loading SQL Database telemetry for pools and elastic databases on a single server
16-
# to a user-supplied Azure SQL database.
15+
# Sample script for loading SQL Database telemetry for pools and elastic databases
16+
# on a single server into a user-supplied Azure SQL database. Script will populate
17+
# the target schema if not present.
1718
#
1819
#
19-
# See additional comments in PoolTelemetryRunner.ps1, which includes script and instructions for running
20-
# this script as a PowerShell job, enabling data gathering for large numbers of servers in the background.
20+
# See additional comments in PoolTelemetryRunner.ps1, which includes instructions for
21+
# running this script as a PowerShell job, enabling data gathering for large numbers
22+
# of servers in the background.
2123
#
2224
#
2325
function Load-PoolTelemetryForServer {
@@ -32,6 +34,7 @@ function Load-PoolTelemetryForServer {
3234
[Parameter(Mandatory=$true)][PSCredential]$OutputServerCred,
3335
[Parameter(Mandatory=$true)][int]$IntervalMinutes, # interval for collection of telemetry
3436
[Parameter(Mandatory=$true)][int]$DurationMinutes, # total duration for collection of telemetry
37+
[Parameter(Mandatory=$true)][bool]$loadAllAvailablePoolTelemetry, # indicates if all available telemetry should be loaded on th first pass
3538
[Parameter(Mandatory=$true)][bool]$IncludeDatabases # indicates if telemetry should be gathered for databases as well as pools
3639
)
3740

@@ -119,7 +122,16 @@ function Load-PoolTelemetryForServer {
119122

120123
while($startTime -lt $finishTime)
121124
{
122-
$poolStartTime = $startTime.AddMinutes(-$poolLagMinutes) # sets the start of query window
125+
if ($loadAllAvailablePoolTelemetry)
126+
{
127+
$poolStartTime = $startTime.AddMinutes(-21600) # looks back 15 days to ensure gets all available older data
128+
$loadAllAvailablePoolTelemetry = $false # switches flag so this is done once only in the loop
129+
}
130+
else
131+
{
132+
$poolStartTime = $startTime.AddMinutes(-$poolLagMinutes) # sets the normal start of query window
133+
}
134+
123135
$poolEndTime = $endTime.AddMinutes(-$poolLagMinutes) # sets end of query window
124136

125137
Write-Host "Starting to collect elastic pool telemetry for period" $poolStartTime "to" $poolEndTime "(UTC)"

samples/manage/azure-sql-db-elastic-pools/PoolTelemetryJobRunner.ps1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# should be installed in the same directory.
1818
#
1919
# This script should be customized as required (see <<<) to select one or more source
20-
# servers, and will then spawn a telemetry gathering job for each server. Each job
21-
# will use Load-PoolTelemetryForServer in PoolTelemetry.ps1 to load telemetry for all
20+
# servers, and will then spawn a telemetry gathering job for each server based on
21+
# Load-PoolTelemetryForServer in PoolTelemetry.ps1, which loads telemetry for all
2222
# pools and elastic databases on the server. Each spawned job will run for an
2323
# extended period in the background, waking up periodically to load more telemetry.
2424
# The interval between telemetry gathering and the total duration can be controlled
@@ -58,7 +58,10 @@ $staticServerList = $false # set to $true if server list will not change during
5858
$intervalMinutes = 15 # interval between telemetry collections used by spawned server job (15-30 mins suggested)
5959
$durationMinutes = 60 # total duration for collection of telemetry and checking servers; 0 for one time execution, or a multiple of the interval.
6060

61-
# Set to $true to gather 15 sec telemetry for elastic databases. Caution: large volumes of data may be returned. <<< ***
61+
## Set to $true to include all available pool telemetry (up to 14 days). Be careful if rerunning on the same server as this may load duplicate data <<< ***
62+
$loadAllAvailablePoolTelemetry = $false
63+
64+
## Set to $true to gather 15 sec telemetry for elastic databases. Caution: large volumes of data may be returned. <<< ***
6265
[bool]$includeDatabases = $false # or $False
6366

6467
$now = [DateTime]::UtcNow
@@ -91,7 +94,7 @@ while ($startTime -le $finishTime)
9194
#$servers.Add($server.ServerName, $server)
9295

9396
## Get all servers in a specific resource group
94-
#$serverList = Get-AzureRmSqlServer -ResourceGroupName $resourceGroupName
97+
#$servers = Get-AzureRmSqlServer -ResourceGroupName $resourceGroupName
9598

9699
## Get all resources of type server in the subscription
97100
#$resourceList = Find-AzureRmResource -ResourceType microsoft.sql/servers
@@ -102,7 +105,7 @@ while ($startTime -le $finishTime)
102105
## Get all resources of type server with common name pattern
103106
#$resourceList = Find-AzureRmResource -ResourceType Microsoft.Sql/servers -ResourceNameContains '<common text>'
104107

105-
# If selecting resources via a $resourceList convert to an equivalent $serverList
108+
# If selecting resources by populating $resourceList populate an equivalent $servers list
106109
foreach ($resource in $resourceList)
107110
{
108111
$server = Get-AzureRmSqlServer -ResourceGroupName $resource.ResourceGroupName -ServerName $resource.Name
@@ -120,19 +123,19 @@ while ($startTime -le $finishTime)
120123
if ($jobs.Contains($server.ServerName) -eq $false)
121124
{
122125
$job = Start-Job -Name $server.ServerName -ScriptBlock {
123-
param ($sp, $inc, $sub, $rgn, $sn, $loc, $sc, $osn, $odn, $osc, $im, $dm)
126+
param ($sp, $all, $inc, $sub, $rgn, $sn, $loc, $sc, $osn, $odn, $osc, $im, $dm)
124127
. $sp
125-
Load-PoolTelemetryForServer -IncludeDatabases $inc `
128+
Load-PoolTelemetryForServer -loadAllAvailablePoolTelemetry $all -IncludeDatabases $inc `
126129
-SubscriptionId $sub -ResourceGroupName $rgn -ServerName $sn -Location $loc -ServerCred $sc -OutputServerName $osn -OutputDatabaseName $odn -OutputServerCred $osc -IntervalMinutes $im -DurationMinutes $dm} `
127-
-ArgumentList $scriptPath, $includeDatabases, $SubscriptionId, $server.ResourceGroupName, $server.ServerName, $server.Location, $sourceCred, $outputServerName, $outputDatabaseName, $outputServerCred, $intervalMinutes, $durationMinutes
130+
-ArgumentList $scriptPath, $loadAllAvailablePoolTelemetry, $includeDatabases, $SubscriptionId, $server.ResourceGroupName, $server.ServerName, $server.Location, $sourceCred, $outputServerName, $outputDatabaseName, $outputServerCred, $intervalMinutes, $durationMinutes
128131

129132
$jobs.Add($server.ServerName, $job)
130133

131134
Write-Host "Job started for server" $server.ServerName
132135

133136
# Following is useful for debugging changes to PoolTelemetry.ps1. Best used with a single server unless you set the duration to 0
134137
#. $scriptPath
135-
#Load-PoolTelemetryForServer -IncludeDatabases $IncludeDatabases -SubscriptionId $SubscriptionId -ResourceGroupName $server.ResourceGroupName `
138+
#Load-PoolTelemetryForServer -loadAllAvailablePoolTelemetry $loadAllAvailablePoolTelemetry -IncludeDatabases $IncludeDatabases -SubscriptionId $SubscriptionId -ResourceGroupName $server.ResourceGroupName `
136139
# -ServerName $server.ServerName -Location $server.Location -ServerCred $sourceCred -OutputServerName $outputServerName `
137140
# -OutputDatabaseName $outputDatabaseName -OutputServerCred $outputServerCred -IntervalMinutes $intervalMinutes -DurationMinutes $durationMinutes
138141
}

0 commit comments

Comments
 (0)