本文概述計算服務的已實證 FinOps 做法集合。 其提供優化成本、提高效率,以及深入瞭解 Azure 中計算資源的指引。 這些做法會根據計算服務的類型分類,例如虛擬機(VM)、Azure Kubernetes Service (AKS)和 Azure Functions。
Azure Kubernetes Service
Azure Kubernetes Service (AKS) 簡化了部署和管理容器化應用程式。 它提供無伺服器 Kubernetes、整合的 CI/CD 體驗,以及企業級的安全與治理。
相關資源:
查詢:AKS 叢集詳情
此 ARG 查詢會擷取 Azure 環境中 AKS 叢集的詳細資訊。
類別
資源管理
查詢
resources
| where type == "microsoft.containerservice/managedclusters"
| extend AgentPoolProfiles = properties.agentPoolProfiles
| mvexpand AgentPoolProfiles
| project
id,
ProfileName = tostring(AgentPoolProfiles.name),
Sku = tostring(sku.name),
Tier = tostring(sku.tier),
mode = AgentPoolProfiles.mode,
AutoScaleEnabled = AgentPoolProfiles.enableAutoScaling,
SpotVM = AgentPoolProfiles.scaleSetPriority,
VMSize = tostring(AgentPoolProfiles.vmSize),
nodeCount = tostring(AgentPoolProfiles.['count']),
minCount = tostring(AgentPoolProfiles.minCount),
maxCount = tostring(AgentPoolProfiles.maxCount),
location,
resourceGroup,
subscriptionId,
AKSname = name
使用 Spot VM 來管理 AKS 叢集
建議:使用 Spot VM 作為 AKS 代理池,以降低容錯且可中斷工作負載的計算成本。
關於 AKS 中的 Spot VM
Spot 虛擬機 利用未使用的Azure容量,且成本大幅降低。 當 Azure 需要回容量時,Azure 基礎架構會驅逐 Spot 虛擬機。 Spot VM 對於能處理中斷的工作負載非常有用,例如批次處理工作、開發/測試環境以及大型運算工作負載。
使用自動擴展但不善用 Spot VM 的 AKS 叢集,可能會支付比必要更多的費用。 透過啟用可中斷工作負載的即時虛擬機,你可以大幅降低運算成本。 此建議僅適用於能容忍中斷的工作負載叢集。 並非所有工作負載都適合 Spot 虛擬機。
查詢:沒有 Spot VM 的 AKS 叢集
請使用以下 ARG 查詢,找出啟用自動擴展且不使用 Spot 虛擬機的 AKS 叢集。
類別
Optimization
查詢
resources
| where type == 'microsoft.containerservice/managedclusters'
| mvexpand AgentPoolProfiles = properties.agentPoolProfiles
| where AgentPoolProfiles.enableAutoScaling == true
and isnull(AgentPoolProfiles.scaleSetPriority)
| project
ResourceId = id,
AKSName = name,
ProfileName = tostring(AgentPoolProfiles.name),
VMSize = tostring(AgentPoolProfiles.vmSize),
NodeCount = tostring(AgentPoolProfiles.['count']),
MinCount = tostring(AgentPoolProfiles.minCount),
MaxCount = tostring(AgentPoolProfiles.maxCount),
Region = location,
ResourceGroupName = resourceGroup,
SubscriptionId = subscriptionId
虛擬機器
Azure 虛擬機(VM)是 Azure 提供 的數種隨選、可調整運算資源之一。 一般而言,當您需要比其他選項提供更多的運算環境控制時,請選擇 VM。
Azure VM 讓您能夠有彈性地進行虛擬化,而不需購買並維護執行它的實體硬體。 不過,您仍然需要執行工作來維護 VM,例如設定、修補及安裝其上執行的軟體。
相關資源:
解除分配虛擬機
建議:解除分配 VM 以避免未使用的計算費用。 避免停止 VM 並且不進行資源解除分配。
關於閒置的虛擬機
VM 有兩個非使用中狀態:已停止和解除分配。
已關閉的 VM 是從作業系統內部進行關機(例如,使用 關機 命令)。 已停止的 VM 已關閉電源,但 Azure 仍會保留計算資源,例如 CPU 和記憶體。 由於計算資源已保留,且無法與其他 VM 搭配使用,因此這些 VM 會繼續產生計算費用。
解除分配的 VM 會透過 Azure 入口網站、CLI、PowerShell 或其他用戶端工具中的雲端管理 API 停止。 當 VM 解除分配時,Azure 會釋放對應的計算資源。 由於計算資源已發行,因此這些 VM 不會產生計算費用;不過,請務必注意,已停止和解除分配的 VM 都會繼續產生與計算無關的費用,例如磁碟的記憶體費用。
識別已停止的 VM
使用下列 Azure Resource Graph (ARG) 查詢來識別未解除分配的已停止 VM。 它會擷取其電源狀態、位置、資源群組和訂用帳戶標識碼的詳細數據。
resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend PowerState = tostring(properties.extended.instanceView.powerState.displayStatus)
| where PowerState !in =('VM deallocated', 'VM running')
| project
ResourceId = id,
PowerState,
Region = location,
ResourceGroupName = resourceGroup,
SubscriptionId = subscriptionId
使用承諾折扣
建議:相較於清單成本,使用承諾折扣可節省高達72%。
關於承諾用量折扣
承諾折扣是提供給承諾在指定期間或期限使用 Azure 服務的組織提供的財務獎勵,通常是一或三年。 同意在一定期限內設定固定的使用量或支出(成本),組織可以相較於清單價格享受大幅折扣(最多可達72%)。 折扣會套用至合格的資源,協助組織節省雲端成本,同時在預算中提供彈性和可預測性。
若要深入了解承諾折扣,請參閱 費率優化功能。
評估虛擬機承諾折扣的覆蓋率
使用下列 FinOps 中樞查詢來測量整體 VM 承諾用量折扣涵蓋範圍。
Costs
| where ResourceType =~ 'Virtual machine'
| where x_SkuMeterCategory startswith 'Virtual Machines'
//
// Join with prices to filter out ineligible SKUs
| extend tmp_MeterKey = strcat(substring(ChargePeriodStart, 0, 7), x_SkuMeterId)
| project tmp_MeterKey, EffectiveCost, PricingCategory, CommitmentDiscountCategory, ResourceName, x_ResourceGroupName, SubAccountName, BillingCurrency
| join kind=leftouter (
Prices
| where x_SkuMeterCategory startswith 'Virtual Machines'
| summarize sp = countif(x_SkuPriceType == 'SavingsPlan'), ri = countif(x_SkuPriceType == 'ReservedInstance')
by tmp_MeterKey = strcat(substring(x_EffectivePeriodStart, 0, 7), x_SkuMeterId)
| project tmp_MeterKey, x_CommitmentDiscountSpendEligibility = iff(sp == 0, 'Not Eligible', 'Eligible'), x_CommitmentDiscountUsageEligibility = iff(ri == 0, 'Not Eligible', 'Eligible')
) on tmp_MeterKey
| extend x_CommitmentDiscountUsageEligibility = iff(isempty(x_CommitmentDiscountUsageEligibility), '(missing prices)', x_CommitmentDiscountUsageEligibility)
| extend x_CommitmentDiscountSpendEligibility = iff(isempty(x_CommitmentDiscountSpendEligibility), '(missing prices)', x_CommitmentDiscountSpendEligibility)
//
// Sum costs
| summarize
TotalCost = sum(EffectiveCost),
OnDemandCost = sumif(EffectiveCost, PricingCategory == 'Standard'),
SpotCost = sumif(EffectiveCost, PricingCategory == 'Dynamic'),
CommittedCost = sumif(EffectiveCost, PricingCategory == 'Committed'),
CommittedSpendCost = sumif(EffectiveCost, CommitmentDiscountCategory == 'Spend'),
CommittedUsageCost = sumif(EffectiveCost, CommitmentDiscountCategory == 'Usage')
by x_CommitmentDiscountUsageEligibility, x_CommitmentDiscountSpendEligibility, BillingCurrency
| extend OnDemandPercent = round(OnDemandCost / TotalCost * 100, 2)
| extend CoveragePercent = round(CommittedCost / TotalCost * 100, 2)
| extend CoverageUsagePercent = round(CommittedUsageCost / TotalCost * 100, 2)
| extend CoverageSpendPercent = round(CommittedSpendCost / TotalCost * 100, 2)
| order by CoveragePercent desc
使用下列查詢來測量每個 VM 的成本明細,包括承諾折扣的涵蓋範圍。
Costs
| where ResourceType =~ 'Virtual machine'
| where x_SkuMeterCategory startswith 'Virtual Machines'
//
// Join with prices to filter out ineligible SKUs
| extend tmp_MeterKey = strcat(substring(ChargePeriodStart, 0, 7), x_SkuMeterId)
| project tmp_MeterKey, EffectiveCost, PricingCategory, CommitmentDiscountCategory, ResourceName, x_ResourceGroupName, SubAccountName, BillingCurrency
| join kind=leftouter (
Prices
| where x_SkuMeterCategory startswith 'Virtual Machines'
| summarize sp = countif(x_SkuPriceType == 'SavingsPlan'), ri = countif(x_SkuPriceType == 'ReservedInstance')
by tmp_MeterKey = strcat(substring(x_EffectivePeriodStart, 0, 7), x_SkuMeterId)
| project tmp_MeterKey, x_CommitmentDiscountSpendEligibility = iff(sp == 0, 'Not Eligible', 'Eligible'), x_CommitmentDiscountUsageEligibility = iff(ri == 0, 'Not Eligible', 'Eligible')
) on tmp_MeterKey
| extend x_CommitmentDiscountUsageEligibility = iff(isempty(x_CommitmentDiscountUsageEligibility), '(missing prices)', x_CommitmentDiscountUsageEligibility)
| extend x_CommitmentDiscountSpendEligibility = iff(isempty(x_CommitmentDiscountSpendEligibility), '(missing prices)', x_CommitmentDiscountSpendEligibility)
//
// Sum costs by resource
| summarize
TotalCost = sum(EffectiveCost),
OnDemandCost = sumif(EffectiveCost, PricingCategory == 'Standard'),
SpotCost = sumif(EffectiveCost, PricingCategory == 'Dynamic'),
CommittedCost = sumif(EffectiveCost, PricingCategory == 'Committed'),
CommittedSpendCost = sumif(EffectiveCost, CommitmentDiscountCategory == 'Spend'),
CommittedUsageCost = sumif(EffectiveCost, CommitmentDiscountCategory == 'Usage')
by ResourceName, x_ResourceGroupName, SubAccountName, x_CommitmentDiscountUsageEligibility, x_CommitmentDiscountSpendEligibility, BillingCurrency
| extend OnDemandPercent = round(OnDemandCost / TotalCost * 100, 2)
| extend CoveragePercent = round(CommittedCost / TotalCost * 100, 2)
| extend CoverageUsagePercent = round(CommittedUsageCost / TotalCost * 100, 2)
| extend CoverageSpendPercent = round(CommittedSpendCost / TotalCost * 100, 2)
| order by CoveragePercent desc
若要深入瞭解 FinOps 中樞,請參閱 FinOps 中樞。
查詢:虛擬機器擴展集詳細資料
此查詢會根據其 SKU、點狀 VM 優先順序和優先順序混合原則,分析 Azure 環境中的虛擬機器規模集。 其提供成本優化和資源管理策略的見解。
類別
資源管理
查詢
resources
| where type =~ 'microsoft.compute/virtualmachinescalesets'
| extend SpotVMs = tostring(properties.virtualMachineProfile.priority)
| extend SpotPriorityMix = tostring(properties.priorityMixPolicy)
| extend SKU = tostring(sku.name)
| extend resourceGroup = strcat('/subscriptions/', subscriptionId, '/resourceGroups/', resourceGroup)
| project id, SKU, SpotVMs, SpotPriorityMix, subscriptionId, resourceGroup, location
移轉到受控磁碟
建議:將使用非管理磁碟的虛擬機遷移到管理磁碟,以提升可靠性、簡化管理,並為非管理磁碟的退休做準備。
關於非管理磁碟
Unmanaged disks 會將 VHD 檔案以頁面塊形式儲存在Azure 儲存體帳號中,需要你自行管理儲存帳號容量、效能與安全性。 管理磁碟透過替你管理儲存帳號,簡化磁碟管理,提供更可靠的可用性設定、更細緻的存取控制,並支援磁碟加密與突發等新功能。 Microsoft 已宣布退休非管理型磁碟,因此遷移到管理型磁碟既是成本優化也是合規的步驟。
辨識擁有非管理磁碟的虛擬機
請使用以下 ARG 查詢來辨識仍在使用未管理磁碟的虛擬機。
resources
| where type =~ 'microsoft.compute/virtualmachines'
| where isnull(properties.storageProfile.osDisk.managedDisk)
| project
ResourceId = tolower(id),
ResourceName = name,
OsDiskVhd = tostring(properties.storageProfile.osDisk.vhd.uri),
Region = location,
ResourceGroupName = resourceGroup,
SubscriptionId = subscriptionId
查詢:虛擬機處理器類型分析
此查詢會識別 Azure 環境中 VM 所使用的處理器類型(ARM、AMD 或 Intel)。 它有助於瞭解不同處理器架構之間 VM 的分佈,這對於優化工作負載效能和成本效益很有用。
類別
資源管理
查詢
resources
| where type == 'microsoft.compute/virtualmachines'
| extend vmSize = properties.hardwareProfile.vmSize
| extend processorType = case(
// ARM Processors
vmSize has "Epsv5"
or vmSize has "Epdsv5"
or vmSize has "Dpsv5"
or vmSize has "Dpdsv", "ARM",
// AMD Processors
vmSize has "Standard_D2a"
or vmSize has "Standard_D4a"
or vmSize has "Standard_D8a"
or vmSize has "Standard_D16a"
or vmSize has "Standard_D32a"
or vmSize has "Standard_D48a"
or vmSize has "Standard_D64a"
or vmSize has "Standard_D96a"
or vmSize has "Standard_D2as"
or vmSize has "Standard_D4as"
or vmSize has "Standard_D8as"
or vmSize has "Standard_D16as"
or vmSize has "Standard_D32as"
or vmSize has "Standard_D48as"
or vmSize has "Standard_D64as"
or vmSize has "Standard_D96as", "AMD",
"Intel"
)
| project vmName = name, processorType, vmSize, resourceGroup
將 Azure Hybrid Benefit 用於 Windows VM
建議:啟用 Windows 虛擬機的 Azure Hybrid Benefit,透過使用現有的本地 Windows Server 授權來降低授權成本。
關於 Azure Hybrid Benefit for Windows
Azure Hybrid Benefit 讓你使用本地的 Windows Server 授權,並附有軟體保證或Windows Server訂閱,以較低成本在 Azure 中運行Windows虛擬機。 你可以帶著現有的授權,只需支付基本的運算成本,就不必為每台虛擬機支付完整的 Windows Server 授權。 此建議僅適用於貴組織擁有合格的本地 Windows Server 授權。
Note
FinOps hubs 可以自動識別未套用 Azure Hybrid Benefit 的 Windows VM,並將其作為可選擇啟用的建議提出。 了解更多。
查詢:未使用 Azure Hybrid Benefit 的 Windows 虛擬機器
請使用以下 ARG 查詢,找出未使用 Azure Hybrid Benefit 的 Windows 虛擬機與規模集。 查詢不包含開發/測試訂閱,因為這些訂閱已經有折扣授權。
類別
Optimization
查詢
resourcecontainers
| where type =~ 'Microsoft.Resources/subscriptions'
| where tostring(properties.subscriptionPolicies.quotaId) !has 'MSDNDevTest_2014-09-01'
| project SubscriptionName = name, subscriptionId
| join (
resources
| where type =~ 'microsoft.compute/virtualmachines'
or type =~ 'microsoft.compute/virtualMachineScaleSets'
| where tostring(properties.storageProfile.osDisk.osType) == 'Windows'
or tostring(properties.virtualMachineProfile.storageProfile.osDisk.osType) == 'Windows'
| where tostring(properties.['licenseType']) !has 'Windows'
and tostring(properties.virtualMachineProfile.['licenseType']) != 'Windows_Server'
| project
ResourceId = id,
ResourceName = name,
VMSize = tostring(properties.hardwareProfile.vmSize),
LicenseType = tostring(properties.['licenseType']),
Region = location,
ResourceGroupName = resourceGroup,
subscriptionId
) on subscriptionId
| project
ResourceId,
ResourceName,
VMSize,
LicenseType,
Region,
ResourceGroupName,
SubscriptionName,
SubscriptionId = subscriptionId
將 Azure Hybrid Benefit 用於 SQL 虛擬機器
建議:啟用 Azure Hybrid Benefit for SQL Server VM 以降低授權成本,透過使用現有的本地 SQL Server 授權。
關於 Azure Hybrid Benefit for SQL VMS
Azure Hybrid Benefit for SQL Server 讓你使用軟體保證的本地SQL Server授權,以較低成本在Azure中運行SQL Server虛擬機。 此優惠適用於標準版與企業版(Developer 和 Express 版本已免費,且不需要 Azure Hybrid Benefit)。 此建議僅適用於貴組織擁有具備軟體保證(Software Assurance)的合格本地 SQL Server 授權。
Note
FinOps hubs 可以自動識別未啟用 Azure Hybrid Benefit 的 SQL 虛擬機器,並將其列為可選建議。 了解更多。
查詢:沒有 Azure 混合權益的 SQL 虛擬機器
請使用以下 ARG 查詢來辨識未使用 Azure Hybrid Benefit 的 SQL Server 虛擬機。 查詢不包含開發/測試訂閱及開發者/Express 版本。
類別
Optimization
查詢
resourcecontainers
| where type =~ 'Microsoft.Resources/subscriptions'
| where tostring(properties.subscriptionPolicies.quotaId) !has 'MSDNDevTest_2014-09-01'
| project SubscriptionName = name, subscriptionId
| join (
resources
| where type =~ 'Microsoft.SqlVirtualMachine/SqlVirtualMachines'
and tostring(properties.['sqlServerLicenseType']) != 'AHUB'
| project
ResourceId = id,
ResourceName = name,
LicenseType = tostring(properties.['sqlServerLicenseType']),
SQLVersion = tostring(properties.['sqlImageOffer']),
SQLSKU = tostring(properties.['sqlImageSku']),
Region = location,
ResourceGroupName = resourceGroup,
subscriptionId
) on subscriptionId
| join (
resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project
ResourceName = tolower(name),
VMSize = tostring(properties.hardwareProfile.vmSize),
subscriptionId
) on ResourceName
| where SQLSKU != 'Developer' and SQLSKU != 'Express'
| project
ResourceId,
ResourceName,
VMSize,
LicenseType,
SQLVersion,
SQLSKU,
Region,
ResourceGroupName,
SubscriptionName,
SubscriptionId = subscriptionId
提供意見反應
請寫下您的快速評價,讓我們知道我們的表現如何。 我們會使用這些評論來改善及擴充 FinOps 工具和資源。
如果您要尋找特定專案,請投票給現有專案或建立新想法。 與其他人分享想法,以獲得更多的選票。 我們專注於擁有最多選票的想法。
相關內容
相關資源:
相關產品:
相關解決方案: