Skip to content
Merged

bill #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
24 changes: 18 additions & 6 deletions samples/manage/azure-sql-db-elastic-pools/PoolTelemetry.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ----------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,12 +12,14 @@
# limitations under the License.
# ---------------------------------------------------------------------------------
#
# Sample script for loading SQL Database telemetry for pools and elastic databases on a single server
# to a user-supplied Azure SQL database.
# Sample script for loading SQL Database telemetry for pools and elastic databases
# on a single server into a user-supplied Azure SQL database. Script will populate
# the target schema if not present.
#
#
# See additional comments in PoolTelemetryRunner.ps1, which includes script and instructions for running
# this script as a PowerShell job, enabling data gathering for large numbers of servers in the background.
# See additional comments in PoolTelemetryRunner.ps1, which includes instructions for
# running this script as a PowerShell job, enabling data gathering for large numbers
# of servers in the background.
#
#
function Load-PoolTelemetryForServer {
Expand All @@ -32,6 +34,7 @@ function Load-PoolTelemetryForServer {
[Parameter(Mandatory=$true)][PSCredential]$OutputServerCred,
[Parameter(Mandatory=$true)][int]$IntervalMinutes, # interval for collection of telemetry
[Parameter(Mandatory=$true)][int]$DurationMinutes, # total duration for collection of telemetry
[Parameter(Mandatory=$true)][bool]$loadAllAvailablePoolTelemetry, # indicates if all available telemetry should be loaded on th first pass
[Parameter(Mandatory=$true)][bool]$IncludeDatabases # indicates if telemetry should be gathered for databases as well as pools
)

Expand Down Expand Up @@ -119,7 +122,16 @@ function Load-PoolTelemetryForServer {

while($startTime -lt $finishTime)
{
$poolStartTime = $startTime.AddMinutes(-$poolLagMinutes) # sets the start of query window
if ($loadAllAvailablePoolTelemetry)
{
$poolStartTime = $startTime.AddMinutes(-21600) # looks back 15 days to ensure gets all available older data
$loadAllAvailablePoolTelemetry = $false # switches flag so this is done once only in the loop
}
else
{
$poolStartTime = $startTime.AddMinutes(-$poolLagMinutes) # sets the normal start of query window
}

$poolEndTime = $endTime.AddMinutes(-$poolLagMinutes) # sets end of query window

Write-Host "Starting to collect elastic pool telemetry for period" $poolStartTime "to" $poolEndTime "(UTC)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# should be installed in the same directory.
#
# This script should be customized as required (see <<<) to select one or more source
# servers, and will then spawn a telemetry gathering job for each server. Each job
# will use Load-PoolTelemetryForServer in PoolTelemetry.ps1 to load telemetry for all
# servers, and will then spawn a telemetry gathering job for each server based on
# Load-PoolTelemetryForServer in PoolTelemetry.ps1, which loads telemetry for all
# pools and elastic databases on the server. Each spawned job will run for an
# extended period in the background, waking up periodically to load more telemetry.
# The interval between telemetry gathering and the total duration can be controlled
Expand Down Expand Up @@ -58,7 +58,10 @@ $staticServerList = $false # set to $true if server list will not change during
$intervalMinutes = 15 # interval between telemetry collections used by spawned server job (15-30 mins suggested)
$durationMinutes = 60 # total duration for collection of telemetry and checking servers; 0 for one time execution, or a multiple of the interval.

# Set to $true to gather 15 sec telemetry for elastic databases. Caution: large volumes of data may be returned. <<< ***
## 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 <<< ***
$loadAllAvailablePoolTelemetry = $false

## Set to $true to gather 15 sec telemetry for elastic databases. Caution: large volumes of data may be returned. <<< ***
[bool]$includeDatabases = $false # or $False

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

## Get all servers in a specific resource group
#$serverList = Get-AzureRmSqlServer -ResourceGroupName $resourceGroupName
#$servers = Get-AzureRmSqlServer -ResourceGroupName $resourceGroupName

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

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

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

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

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