分析 Log Analytics 工作區中的使用量

Azure 監視器成本可能會根據在 Log Analytics 工作區中收集的資料量而大幅改變。 此數量會受到一組使用工作區的解決方案及每個解決方案所收集的資料量所影響。 本文提供有關如何分析收集的資料以協助控制資料擷取成本的指引。 可協助您判斷高於預期使用量的原因。 也可協助您預測當您監視更多資源並且設定不同 Azure 監視器功能時的成本。

提示

如需降低 Azure 監視器成本的策略,請參閱 成本最佳化和 Azure 監視器

高於預期使用量的原因

每項 Log Analytics 工作區都是個別計費的服務,並且會計入到您的 Azure 訂用帳戶帳單。 根據下列因素而定,資料擷取量可能會很可觀:

  • 一組已啟用的深入解析和服務以及其設定。
  • 受監視資源的數目和類型。
  • 從每個受監視資源收集的資料量。

上述任何因素的未預期增加都可能會導致資料保留費用增加。 本文的其餘部分提供方法來偵測這類情況,然後分析收集的資料以識別並減輕增加使用量的來源。

在資料收集量很高時傳送警示

為了避免非預期的帳單,您應該在遇到過多使用量時主動收到通知。 通知可讓您在計費週期結束時,解決任何潛在的異常。

下列範例是個記錄搜尋警示規則,如果過去 24 小時內所擷取的可計費資料量大於 50 GB,就會傳送警示。 修改 [警示邏輯] 設定,以根據您環境中的預期使用量使用不同的閾值。 您也可以增加每天多次檢查使用量的頻率,但此選項會導致警示規則產生較高的費用。

設定
範圍
目標範圍 選取 Log Analytics 工作區。
Condition
查詢 Usage | where IsBillable | summarize DataGB = sum(Quantity / 1000)
測量 量值:DataGB
彙總類型:總計
彙總細微性:1 天
警示邏輯 運算子:大於
閾值:50
評估頻率:1 天
動作 選取或新增動作群組,以在超過閾值時通知您。
詳細資料
嚴重性 警告
警示規則名稱 在 24 小時內大於 50 GB 的可計費資料量。

Azure 監視器中的使用量分析

使用 Azure 監視器中的現有工具開始分析。 這些工具不需要任何設定,而且通常只要最少的工作就能提供您所需的資訊。 如果您需要對收集的資料進行比現有 Azure 監視器功能更深入的分析,請使用 Log Analytics 中的下列任何記錄查詢

Log Analytics 工作區深入解析

Log Analytics 工作區深入解析可讓您快速了解工作區中的資料。 例如,您可以判斷:

  • 正在擷取主資料表中最多資料量的資料表。
  • 貢獻資料的熱門資源。
  • 資料擷取的趨勢。

如需依解決方案和資料表擷取的明細,請參閱 [使用量] 索引標籤。 此資訊可協助您快速識別貢獻大部分資料量的資料表。 索引標籤也會顯示一段時間的資料收集趨勢。 您可以判斷資料收集是在一段時間內穩定地增加,或是為了回應組態變更而驟然增加。

針對預先建置的查詢選取 [其他查詢],以協助您進一步了解資料模式。

使用量和估計成本

每個工作區之 [使用量和估計成本] 頁面上的 [每個解決方案的資料擷取] 圖表會顯示所傳送的總資料量,以及每個解決方案在過去 31 天所傳送的資料量。 此資訊可協助您判斷趨勢,例如是否有來自整體資料使用量或特定解決方案使用量的任何增加趨勢。

從使用量資料表查詢資料量

分析特定服務或解決方案所收集的可計費資料量。 這些查詢會使用 [使用量] 資料表來收集工作區中每個資料表的使用量資料。

注意

具有 TimeGenerated 的子句只是為了確保 Azure 入口網站中的查詢體驗回顧超過預設的 24 小時。 當您使用 [使用量] 資料類型時,StartTimeEndTime 代表所顯示結果所屬的時段。

過去一個月的可計費資料量 (依類型)

Usage 
| where TimeGenerated > ago(32d)
| where StartTime >= startofday(ago(31d)) and EndTime < startofday(now())
| where IsBillable == true
| summarize BillableDataGB = sum(Quantity) / 1000. by bin(StartTime, 1d), DataType 
| render columnchart

過去一個月的可計費資料量 (依解決方案和類型)

Usage 
| where TimeGenerated > ago(32d)
| where StartTime >= startofday(ago(31d)) and EndTime < startofday(now())
| where IsBillable == true
| summarize BillableDataGB = sum(Quantity) / 1000 by Solution, DataType
| sort by Solution asc, DataType asc

直接從事件查詢資料量

如果您需要對收集的資料進行更深入的分析,您可以使用 Log Analytics 中的記錄查詢。 Log Analytics 工作區中的每個資料表都有下列標準資料行,可協助您分析可計費的資料:

  • _IsBillable 會識別有擷取費用的記錄。 使用此資料行可篩選出不可計費的資料。
  • _BilledSize 會提供記錄的位元組大小。

特定事件的可計費資料量

如果您發現特定資料類型收集過多的資料,您可能會想要分析該資料表中的資料,以判斷增加的特定記錄。 此範例會篩選 Event 資料表中的特定事件識別碼,然後提供每個識別碼的計數。 您可以使用其他資料表中的資料行來修改此查詢。

Event
| where TimeGenerated > startofday(ago(31d)) and TimeGenerated < startofday(now()) 
| where EventID == 5145 or EventID == 5156
| where _IsBillable == true
| summarize count(), Bytes=sum(_BilledSize) by EventID, bin(TimeGenerated, 1d)

資料量 (依 Azure 資源、資源群組或訂用帳戶)

您可以分析從特定資源或一組資源收集的可計費資料量。 這些查詢會針對來自 Azure 中裝載資源的資料,使用 _ResourceId_SubscriptionId 資料行。

警告

請謹慎使用 find 查詢,因為執行跨資料類型掃描會耗用大量資源。 如果您不需要每個訂用帳戶、資源群組或資源名稱的結果,請使用 [使用量] 資料表,如上述查詢所示。

過去一整天可計費的資料量 (依資源識別碼)

find where TimeGenerated between(startofday(ago(1d))..startofday(now())) project _ResourceId, _BilledSize, _IsBillable
| where _IsBillable == true 
| summarize BillableDataBytes = sum(_BilledSize) by _ResourceId 
| sort by BillableDataBytes nulls last

過去一整天可計費的資料量 (依資源群組)

find where TimeGenerated between(startofday(ago(1d))..startofday(now())) project _ResourceId, _BilledSize, _IsBillable
| where _IsBillable == true 
| summarize BillableDataBytes = sum(_BilledSize) by _ResourceId
| extend resourceGroup = tostring(split(_ResourceId, "/")[4] )
| summarize BillableDataBytes = sum(BillableDataBytes) by resourceGroup 
| sort by BillableDataBytes nulls last

剖析 _ResourceId 可能會很有幫助:

| parse tolower(_ResourceId) with "/subscriptions/" subscriptionId "/resourcegroups/" 
    resourceGroup "/providers/" provider "/" resourceType "/" resourceName   

過去一整天可計費的資料量 (依訂閱)

find where TimeGenerated between(startofday(ago(1d))..startofday(now())) project _BilledSize, _IsBillable, _SubscriptionId
| where _IsBillable == true 
| summarize BillableDataBytes = sum(_BilledSize) by _SubscriptionId 
| sort by BillableDataBytes nulls last

提示

針對具有大量資料的工作區,執行如本節所示的查詢 (查詢大量未經處理資料) 可能需要限制為單日。 若要追蹤一段時間的趨勢,請考慮設定 Power BI 報表,並使用累加式重新整理一天收集一次每個資源的資料量。

資料量 (依電腦)

您可以分析從一部虛擬機器或一組虛擬機器收集的可計費資料量。 [使用量] 資料表沒有顯示特定虛擬機器資料量的細微性,因此這些查詢會使用 尋找運算子來搜尋包含電腦名稱的所有資料表。 省略了 [使用量] 類型,因為此查詢只是為了分析資料趨勢。

警告

請謹慎使用 find 查詢,因為執行跨資料類型掃描會耗用大量資源。 如果您不需要每個訂用帳戶、資源群組或資源名稱的結果,請使用 [使用量] 資料表,如上述查詢所示。

過去一整天可計費的資料量 (依電腦)

find where TimeGenerated between(startofday(ago(1d))..startofday(now())) project _BilledSize, _IsBillable, Computer, Type
| where _IsBillable == true and Type != "Usage"
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| summarize BillableDataBytes = sum(_BilledSize) by  computerName 
| sort by BillableDataBytes desc nulls last

過去一整天可計費的事件計數 (依電腦)

find where TimeGenerated between(startofday(ago(1d))..startofday(now())) project _IsBillable, Computer, Type
| where _IsBillable == true and Type != "Usage"
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| summarize eventCount = count() by computerName  
| sort by eventCount desc nulls last

查詢不包括已知免費資料類型的資料量

下列查詢會傳回以 GB 為單位的每月資料量,但不包括所有應該不收資料擷取費用的資料類型:

let freeTables = dynamic([
"AppAvailabilityResults","AppSystemEvents","ApplicationInsights","AzureActivity","AzureNetworkAnalyticsIPDetails_CL",
"AzureNetworkAnalytics_CL","AzureTrafficAnalyticsInsights_CL","ComputerGroup","DefenderIoTRawEvent","Heartbeat",
"MAApplication","MAApplicationHealth","MAApplicationHealthIssues","MAApplicationInstance","MAApplicationInstanceReadiness",
"MAApplicationReadiness","MADeploymentPlan","MADevice","MADeviceNotEnrolled","MADeviceReadiness","MADriverInstanceReadiness",
"MADriverReadiness","MAProposedPilotDevices","MAWindowsBuildInfo","MAWindowsCurrencyAssessment",
"MAWindowsCurrencyAssessmentDailyCounts","MAWindowsDeploymentStatus","NTAIPDetails_CL","NTANetAnalytics_CL",
"OfficeActivity","Operation","SecurityAlert","SecurityIncident","UCClient","UCClientReadinessStatus",
"UCClientUpdateStatus","UCDOAggregatedStatus","UCDOStatus","UCDeviceAlert","UCServiceUpdateStatus","UCUpdateAlert",
"Usage","WUDOAggregatedStatus","WUDOStatus","WaaSDeploymentStatus","WaaSInsiderStatus","WaaSUpdateStatus"]);
Usage 
| where DataType !in (freeTables) 
| where TimeGenerated > ago(30d) 
| summarize MonthlyGB=sum(Quantity)/1000

若要尋找可能未正確設定 IsBillable 的資料 (且可能會導致帳單不正確,或更具體來說計費不足),請在工作區上使用此查詢:

let freeTables = dynamic([
"AppAvailabilityResults","AppSystemEvents","ApplicationInsights","AzureActivity","AzureNetworkAnalyticsIPDetails_CL",
"AzureNetworkAnalytics_CL","AzureTrafficAnalyticsInsights_CL","ComputerGroup","DefenderIoTRawEvent","Heartbeat",
"MAApplication","MAApplicationHealth","MAApplicationHealthIssues","MAApplicationInstance","MAApplicationInstanceReadiness",
"MAApplicationReadiness","MADeploymentPlan","MADevice","MADeviceNotEnrolled","MADeviceReadiness","MADriverInstanceReadiness",
"MADriverReadiness","MAProposedPilotDevices","MAWindowsBuildInfo","MAWindowsCurrencyAssessment",
"MAWindowsCurrencyAssessmentDailyCounts","MAWindowsDeploymentStatus","NTAIPDetails_CL","NTANetAnalytics_CL",
"OfficeActivity","Operation","SecurityAlert","SecurityIncident","UCClient","UCClientReadinessStatus",
"UCClientUpdateStatus","UCDOAggregatedStatus","UCDOStatus","UCDeviceAlert","UCServiceUpdateStatus","UCUpdateAlert",
"Usage","WUDOAggregatedStatus","WUDOStatus","WaaSDeploymentStatus","WaaSInsiderStatus","WaaSUpdateStatus"]);
Usage 
| where DataType !in (freeTables) 
| where TimeGenerated > ago(30d) 
| where IsBillable == false 
| summarize MonthlyPotentialUnderbilledGB=sum(Quantity)/1000 by DataType

查詢常見的資料類型

如果您發現特定資料類型有過多的可計費資料,您可能需要執行查詢來分析該資料表中的資料。 下列查詢提供一些常見資料類型的範例:

安全性解決方案

SecurityEvent 
| summarize AggregatedValue = count() by EventID
| order by AggregatedValue desc nulls last

記錄管理解決方案

Usage 
| where Solution == "LogManagement" and iff(isnotnull(toint(IsBillable)), IsBillable == true, IsBillable == "true") == true 
| summarize AggregatedValue = count() by DataType
| order by AggregatedValue desc nulls last

Perf 資料類型

Perf 
| summarize AggregatedValue = count() by CounterPath
Perf 
| summarize AggregatedValue = count() by CounterName

Event 資料類型

Event 
| summarize AggregatedValue = count() by EventID
Event 
| summarize AggregatedValue = count() by EventLog, EventLevelName

Syslog 資料類型

Syslog 
| summarize AggregatedValue = count() by Facility, SeverityLevel
Syslog 
| summarize AggregatedValue = count() by ProcessName

AzureDiagnostics 資料類型

AzureDiagnostics 
| summarize AggregatedValue = count() by ResourceProvider, ResourceId

Application Insights 資料

您有兩種方法可調查針對 Application Insights 收集的資料量,視您擁有的是傳統或工作區型應用程式而定。 針對工作區型和傳統資源,請使用每個擷取事件上可用的 _BilledSize 屬性。 您也可以針對傳統資源,使用 systemEvents 資料表中的彙總資訊。

注意

除了 SystemEvents 之外,對 Application Insights 資料表的查詢也適用於工作區型和傳統 Application Insights 資源。 回溯相容性可讓您繼續使用舊版資料表名稱。 針對工作區型資源,請在 [Log Analytics 工作區] 功能表上開啟 [記錄]。 針對傳統資源,請在 [Application Insights] 功能表上開啟 [記錄]

相依性作業在過去 30 天內產生最多資料量 (工作區型或傳統)

dependencies
| where timestamp >= startofday(ago(30d))
| summarize sum(_BilledSize) by operation_Name
| render barchart  

此 Application Insights 資源過去 7 天內的每日資料量 (依類型) (僅限傳統)

systemEvents
| where timestamp >= startofday(ago(7d)) and timestamp < startofday(now())
| where type == "Billing"
| extend BillingTelemetryType = tostring(dimensions["BillingTelemetryType"])
| extend BillingTelemetrySizeInBytes = todouble(measurements["BillingTelemetrySize"])
| summarize sum(BillingTelemetrySizeInBytes) by BillingTelemetryType, bin(timestamp, 1d)  

若要查看工作區型 Application Insights 資源的資料量趨勢,請使用包含所有 Application Insights 資料表的查詢。 下列查詢會使用工作區型資源特定的資料表名稱

工作區中所有 Application Insights 資源在 7 天內的每日資料量 (依類型)

union AppAvailabilityResults,
      AppBrowserTimings,
      AppDependencies,
      AppExceptions,
      AppEvents,
      AppMetrics,
      AppPageViews,
      AppPerformanceCounters,
      AppRequests,
      AppSystemEvents,
      AppTraces
| where TimeGenerated >= startofday(ago(7d)) and TimeGenerated < startofday(now())
| summarize sum(_BilledSize) by _ResourceId, bin(TimeGenerated, 1d)

若要只查看單一 Application Insights 資源的資料量趨勢,請在上述查詢的 summarize 前面新增下列這一行:

| where _ResourceId contains "<myAppInsightsResourceName>"

提示

針對具有大量資料的工作區,執行類似上述查詢 (查詢大量未經處理資料) 可能需要限制為單日。 若要追蹤一段時間的趨勢,請考慮設定 Power BI 報表,並使用累加式重新整理一天收集一次每個資源的資料量。

了解傳送資料的節點

如果您沒有來自任何特定來源的過多資料,您可能會有過多的代理程式正在傳送資料。

過去一個月內每天傳送活動訊號的代理程式節點計數

Heartbeat 
| where TimeGenerated > startofday(ago(31d))
| summarize nodes = dcount(Computer) by bin(TimeGenerated, 1d)    
| render timechart

警告

請謹慎使用 find 查詢,因為執行跨資料類型掃描會耗用大量資源。 如果您不需要每個訂用帳戶、資源群組或資源名稱的結果,請使用 [使用量] 資料表,如上述查詢所示。

過去 24 小時內傳送任何資料的節點計數

find where TimeGenerated > ago(24h) project Computer
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| where computerName != ""
| summarize nodes = dcount(computerName)

過去 24 小時內每個節點所傳送的資料量

find where TimeGenerated > ago(24h) project _BilledSize, Computer
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| where computerName != ""
| summarize TotalVolumeBytes=sum(_BilledSize) by computerName

依舊版每個節點定價層計費的節點

舊版每個節點定價層會針對具有每小時資料細微性的節點計費。 也不會計算僅傳送一組安全性資料類型的節點。 若要在工作區位於舊版「每個節點」定價層時取得以節點形式計費的電腦清單,請尋找正在傳送計費資料類型的節點 (因為某些資料類型是免費的)。 在此案例中,請使用完整網域名稱的最左邊欄位。

下列查詢會傳回電腦計數以及每小時的計費資料。 帳單上的單位數是以節點月份單位表示,其在查詢中以 billableNodeMonthsPerDay 表示。 如果工作區已安裝更新管理解決方案,請將 UpdateUpdateSummary 資料類型新增至 where 子句中的清單。

find where TimeGenerated >= startofday(ago(7d)) and TimeGenerated < startofday(now()) project Computer, _IsBillable, Type, TimeGenerated
| where Type !in ("SecurityAlert", "SecurityBaseline", "SecurityBaselineSummary", "SecurityDetection", "SecurityEvent", "WindowsFirewall", "MaliciousIPCommunication", "LinuxAuditLog", "SysmonEvent", "ProtectionStatus", "WindowsEvent")
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| where computerName != ""
| where _IsBillable == true
| summarize billableNodesPerHour=dcount(computerName) by bin(TimeGenerated, 1h)
| summarize billableNodesPerDay = sum(billableNodesPerHour)/24., billableNodeMonthsPerDay = sum(billableNodesPerHour)/24./31.  by day=bin(TimeGenerated, 1d)
| sort by day asc

注意

使用上述查詢中未表示的解決方案目標時,實際計費演算法有一些額外的複雜度。

安全性和自動化節點計數

相異安全性節點的計數

union
(
    Heartbeat
    | where (Solutions has 'security' or Solutions has 'antimalware' or Solutions has 'securitycenter')
    | project Computer
),
(
    ProtectionStatus
    | where Computer !in (Heartbeat | project Computer)
    | project Computer
)
| distinct Computer
| project lowComputer = tolower(Computer)
| distinct lowComputer
| count

相異自動化節點的數目

 ConfigurationData 
 | where (ConfigDataType == "WindowsServices" or ConfigDataType == "Software" or ConfigDataType =="Daemons") 
 | extend lowComputer = tolower(Computer) | summarize by lowComputer 
 | join (
     Heartbeat 
       | where SCAgentChannel == "Direct"
       | extend lowComputer = tolower(Computer) | summarize by lowComputer, ComputerEnvironment
 ) on lowComputer
 | summarize count() by ComputerEnvironment | sort by ComputerEnvironment asc

延遲抵達的資料

如果您觀察到使用 Usage 記錄所報告的高資料擷取,但未觀察到直接在資料類型上加總 _BilledSize 的相同結果,您可能有延遲抵達的資料。 使用舊時間戳記擷取資料時會發生這種情況。

例如,代理程式可能有連線問題,並在重新連線後傳送累積的資料。 或者,主機可能有不正確的時間。 各種範例都會導致依 [使用量] 資料類型報告的擷取資料與加總 TimeGenerated (產生事件的時間戳記) 所指定特定一天之原始資料_BilledSize 的查詢之間,出現明顯不一致的情況。

若要診斷延遲抵達的資料問題,請使用 TimeGenerated 資料行和 _TimeReceived 資料行。 _TimeReceived 屬性是 Azure 雲端中 Azure 監視器擷取點收到記錄的時間。

下列範例是回應 2021 年 5 月 2 日 W3CIISLog 資料的高擷取資料量,以識別此擷取資料的時間戳記。 where TimeGenerated > datetime(1970-01-01) 陳述式是為了提供 Log Analytics 使用者介面的線索以查看所有資料所包含。

W3CIISLog
| where TimeGenerated > datetime(1970-01-01)
| where _TimeReceived >= datetime(2021-05-02) and _TimeReceived < datetime(2021-05-03) 
| where _IsBillable == true
| summarize BillableDataMB = sum(_BilledSize)/1.E6 by bin(TimeGenerated, 1d)
| sort by TimeGenerated asc 

下一步