使用 PowerShell 對 Azure Cosmos DB - Gremlin API 的資料庫或圖表執行輸送量 (RU/秒) 作業
適用於: Gremlin
注意
建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 若要開始使用,請參閱安裝 Azure PowerShell (部分機器翻譯)。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az。
此範例需要 Azure PowerShell Az 5.4.0 或更新版本。 執行 Get-Module -ListAvailable Az
可查看已安裝的版本。
如果您需要安裝,請參閱安裝 Azure PowerShell 模組。
執行 Connect-AzAccount 來登入 Azure。
取得輸送量
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get database or graph throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$graphName = "myGraph"
# --------------------------------------------------
Write-Host "Get database shared throughput"
Get-AzCosmosDBGremlinDatabaseThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName
Write-Host "Get graph dedicated throughput"
Get-AzCosmosDBGremlinGraphThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $graphName
更新輸送量
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update graph throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$graphName = "myGraph"
$newRUs = 500
# --------------------------------------------------
$throughput = Get-AzCosmosDBGremlinGraphThroughput `
-ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $graphName
$currentRUs = $throughput.Throughput
$minimumRUs = $throughput.MinimumThroughput
Write-Host "Current throughput is $currentRUs. Minimum allowed throughput is $minimumRUs."
if ([int]$newRUs -lt [int]$minimumRUs) {
Write-Host "Requested new throughput of $newRUs is less than minimum allowed throughput of $minimumRUs."
Write-Host "Using minimum allowed throughput of $minimumRUs instead."
$newRUs = $minimumRUs
}
if ([int]$newRUs -eq [int]$currentRUs) {
Write-Host "New throughput is the same as current throughput. No change needed."
}
else {
Write-Host "Updating throughput to $newRUs."
Update-AzCosmosDBGremlinGraphThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName `
-Name $graphName -Throughput $newRUs
}
遷移輸送量
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a database or graph to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$databaseName = "myDatabase"
$graphName = "myGraph"
# --------------------------------------------------
Write-Host "Migrate database with standard throughput to autoscale throughput."
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Autoscale
Write-Host "Migrate database with autoscale throughput to standard throughput."
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $databaseName -ThroughputType Manual
Write-Host "Migrate graph with standard throughput to autoscale throughput."
Invoke-AzCosmosDBGremlinGraphThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $graphName -ThroughputType Autoscale
Write-Host "Migrate graph with autoscale throughput to standard throughput."
Invoke-AzCosmosDBGremlinGraphThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -DatabaseName $databaseName -Name $graphName -ThroughputType Manual
清除部署
在執行過指令碼範例之後,您可以使用下列命令來移除資源群組和所有與其相關聯的資源。
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
指令碼說明
此指令碼會使用下列命令。 下表中的每個命令都會連結至命令特定的文件。
Command | 注意 |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBGremlinDatabaseThroughput | 取得 Gremlin API 資料庫的輸送量值。 |
Get-AzCosmosDBGremlinGraphThroughput | 取得 Gremlin API 圖表的輸送量值。 |
Update-AzCosmosDBGremlinDatabaseThroughput | 更新 Gremlin API 資料庫的輸送量值。 |
Update-AzCosmosDBGremlinGraphThroughput | 更新 Gremlin API 圖表的輸送量值。 |
Invoke-AzCosmosDBGremlinDatabaseThroughputMigration | 遷移 Gremlin API 資料庫的輸送量。 |
Invoke-AzCosmosDBGremlinGraphThroughputMigration | 遷移 Gremlin API 圖表的輸送量。 |
Azure 資源群組 | |
Remove-AzResourceGroup | 刪除資源群組,包括所有的巢狀資源。 |
下一步
如需有關 Azure PowerShell 的詳細資訊,請參閱 Azure PowerShell 文件。