本文概述計算服務的已實證 FinOps 做法集合。 其提供優化成本、提高效率,以及深入瞭解 Azure 中計算資源的指引。 這些做法會根據計算服務的類型分類,例如虛擬機(VM)、Azure Kubernetes Service (AKS)和 Azure Functions。
Azure Kubernetes Service
下一節提供 AKS 叢集的 Azure Resource Graph (ARG) 查詢。 此查詢可協助您深入瞭解 VM。
查詢 - 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
虛擬機器
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
查詢 - 虛擬機處理器類型分析
此查詢會識別 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
提供意見反應
請寫下您的快速評價,讓我們知道我們的表現如何。 我們會使用這些評論來改善及擴充 FinOps 工具和資源。
如果您要尋找特定專案,請投票給現有專案或建立新想法。 與其他人分享想法,以獲得更多的選票。 我們專注於擁有最多選票的想法。
相關內容
相關資源:
相關產品:
相關解決方案: