Migracja na szczyt innowacji:
Dowiedz się, jak migrowanie i modernizacja na platformę Azure może zwiększyć wydajność, odporność i bezpieczeństwo firmy, umożliwiając pełne wykorzystanie sztucznej inteligencji.Zarejestruj się teraz
Ta przeglądarka nie jest już obsługiwana.
Przejdź na przeglądarkę Microsoft Edge, aby korzystać z najnowszych funkcji, aktualizacji zabezpieczeń i pomocy technicznej.
Ten przykładowy skrypt programu PowerShell monitoruje metryki wydajności pojedynczej bazy danych, skaluje ją do wyższego rozmiaru obliczeniowego i tworzy regułę alertu dla jednej z metryk wydajności.
Na platforma Azure hostowane jest Azure Cloud Shell, interaktywne środowisko powłoki, z którego można korzystać w przeglądarce. Do pracy z usługami platformy Azure można używać programu Bash lub PowerShell w środowisku Cloud Shell. Aby uruchomić kod w tym artykule, możesz użyć wstępnie zainstalowanych poleceń usługi Cloud Shell bez konieczności instalowania niczego w środowisku lokalnym.
Aby uruchomić środowisko Azure Cloud Shell:
Opcja
Przykład/link
Wybierz pozycję Wypróbuj w prawym górnym rogu bloku kodu. Wybranie pozycji Wypróbuj nie spowoduje automatycznego skopiowania kodu do środowiska Cloud Shell.
Przejdź do witryny https://shell.azure.com lub wybierz przycisk Uruchom Cloud Shell, aby otworzyć środowisko Cloud Shell w przeglądarce.
Wybierz przycisk Cloud Shell na pasku menu w prawym górnym rogu witryny Azure Portal.
Aby uruchomić kod z tego artykułu w środowisku Azure Cloud Shell:
Uruchom usługę Cloud Shell.
Wybierz przycisk Kopiuj w bloku kodu, aby skopiować kod.
Wklej kod do sesji usługi Cloud Shell, wybierając Ctrl+Shift+V w systemach Windows i Linux lub wybierając pozycję Cmd+Shift+V w systemie macOS.
Naciśnij klawisz Enter, aby uruchomić kod.
Jeśli zdecydujesz się zainstalować program PowerShell i używać go lokalnie, ten samouczek wymaga modułu Az PowerShell 1.4.0 lub nowszego. Jeśli konieczne będzie uaktualnienie, zobacz Instalowanie modułu Azure PowerShell. Jeśli używasz programu PowerShell lokalnie, musisz też uruchomić polecenie Connect-AzAccount, aby utworzyć połączenie z platformą Azure.
Przykładowy skrypt
PowerShell
# This script requires the following# - Az.Resources# - Az.Accounts# - Az.Monitor# - Az.Sql# First, run Connect-AzAccount# Set the subscription in which to create these objects. This is displayed on objects in the Azure portal.$SubscriptionId = ''# Set the resource group name and location for your server$resourceGroupName = "myResourceGroup-$(Get-Random)"$location = "westus2"# Set an admin login and password for your server$adminSqlLogin = "SqlAdmin"$password = (New-Guid).Guid # Generates a randomized GUID password. # Set server name - the logical server name has to be unique in the system$serverName = "server-$(Get-Random)"# The sample database name$databaseName = "mySampleDatabase"# The ip address range that you want to allow to access your server via the firewall rule$startIp = "0.0.0.0"$endIp = "0.0.0.0"# Set subscription Set-AzContext -SubscriptionId$subscriptionId# Create a new resource group$resourceGroup = New-AzResourceGroup -Name$resourceGroupName -Location$location# Create a new server with a system wide unique server name$server = New-AzSqlServer -ResourceGroupName$resourceGroupName `
-ServerName$serverName `
-Location$location `
-SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList$adminSqlLogin, $(ConvertTo-SecureString -String$password -AsPlainText -Force))
# Create a server firewall rule that allows access from the specified IP range$serverFirewallRule = New-AzSqlServerFirewallRule -ResourceGroupName$resourceGroupName `
-ServerName$serverName `
-FirewallRuleName"AllowedIPs" -StartIpAddress$startIp -EndIpAddress$endIp# Create a blank database with an S0 performance level$database = New-AzSqlDatabase -ResourceGroupName$resourceGroupName `
-ServerName$serverName `
-DatabaseName$databaseName `
-RequestedServiceObjectiveName"S0" `
-SampleName"AdventureWorksLT"# Monitor the DTU consumption on the database in 5 minute intervals$MonitorParameters = @{
ResourceId = "/subscriptions/$($(Get-AzContext).Subscription.Id)/resourceGroups/$resourceGroupName/providers/Microsoft.Sql/servers/$serverName/databases/$databaseName"
TimeGrain = [TimeSpan]::Parse("00:05:00")
MetricNames = "dtu_consumption_percent"
}
$metric = Get-AzMetric @monitorparameters
$metric.Data
# Scale the database performance to Standard S1$database = Set-AzSqlDatabase -ResourceGroupName$resourceGroupName `
-ServerName$servername `
-DatabaseName$databasename `
-Edition"Standard" `
-RequestedServiceObjectiveName"S1"# Set up an Alert rule using Azure Monitor for the database# Add an Alert that fires when the pool utilization reaches 90%# Objects needed: An Action Group Receiver (in this case, an email group), an Action Group, Alert Criteria, and finally an Alert Rule.# Creates an new action group receiver object with a target email address.$receiver = New-AzActionGroupReceiver `
-Name"my Sample Azure Admins" `
-EmailAddress"azure-admins-group@contoso.com"# Creates a new or updates an existing action group.$actionGroup = Set-AzActionGroup `
-Name"mysample-email-the-azure-admins" `
-ShortName"AzAdminsGrp" `
-ResourceGroupName$resourceGroupName `
-Receiver$receiver# Fetch the created AzActionGroup into an object of type Microsoft.Azure.Management.Monitor.Models.ActivityLogAlertActionGroup$actionGroupObject = New-AzActionGroup -ActionGroupId$actionGroup.Id
# Create a criteria for the Alert to monitor.$criteria = New-AzMetricAlertRuleV2Criteria `
-MetricName"dtu_consumption_percent" `
-TimeAggregation Average `
-Operator GreaterThan `
-Threshold90# Create the Alert rule.# Add-AzMetricAlertRuleV2 adds or updates a V2 (non-classic) metric-based alert rule.Add-AzMetricAlertRuleV2 -Name"mySample_Alert_DTU_consumption_pct" `
-ResourceGroupName$resourceGroupName `
-WindowSize (New-TimeSpan -Minutes1) `
-Frequency (New-TimeSpan -Minutes1) `
-TargetResourceId"/subscriptions/$($(Get-AzContext).Subscription.Id)/resourceGroups/$resourceGroupName/providers/Microsoft.Sql/servers/$serverName/databases/$databaseName" `
-Condition$criteria `
-ActionGroup$actionGroupObject `
-Severity3#Informational<#
# Set up an alert rule using Azure Monitor for the database
# Note that Add-AzMetricAlertRule is deprecated. Use Add-AzMetricAlertRuleV2 instead.
Add-AzMetricAlertRule -ResourceGroup $resourceGroupName `
-Name "MySampleAlertRule" `
-Location $location `
-TargetResourceId "/subscriptions/$($(Get-AzContext).Subscription.Id)/resourceGroups/$resourceGroupName/providers/Microsoft.Sql/servers/$serverName/databases/$databaseName" `
-MetricName "dtu_consumption_percent" `
-Operator "GreaterThan" `
-Threshold 90 `
-WindowSize $([TimeSpan]::Parse("00:05:00")) `
-TimeAggregationOperator "Average" `
-Action $(New-AzAlertRuleEmail -SendToServiceOwner)
#># Clean up deployment # Remove-AzResourceGroup -ResourceGroupName $resourceGroupName
Uwaga
Aby uzyskać pełną listę metryk, zobacz obsługiwane metryki.
(Przestarzałe) Dodaje lub aktualizuje regułę alertu, aby automatycznie monitorować metryki w przyszłości. Dotyczy tylko klasycznych reguł alertów opartych na metryce.
Dodaje lub aktualizuje regułę alertu, aby automatycznie monitorować metryki w przyszłości. Dotyczy tylko nie klasycznych reguł alertów opartych na metryce.
Administrowanie infrastrukturą bazy danych programu SQL Server dla chmurowych, lokalnych i hybrydowych relacyjnych baz danych przy użyciu ofert relacyjnych baz danych PaaS firmy Microsoft.
Widok dynamicznego zarządzania sys.dm_operation_status zawiera informacje o operacjach wykonywanych na bazach danych na serwerze logicznym usługi Azure SQL Database.
W tym artykule wyjaśniono, jak skalować bazę danych w usługach Azure SQL Database i Azure SQL Managed Instance, dodając lub usuwając przydzielone zasoby.
Tworzenie elastycznych pul usługi Azure SQL Database i zarządzanie nimi przy użyciu witryny Azure Portal, programu PowerShell, interfejsu wiersza polecenia platformy Azure, języka Transact-SQL (T-SQL) i interfejsu API REST.