Azure 監視器記錄中的標準資料行

Azure 監視器記錄中的資料會儲存為 Log Analytics 工作區或 Application Insights 應用程式中的一組記錄,而每筆記錄都具有包含一組唯一資料行的特定資料類型。 有許多資料類型將會具有多種類型通用的標準資料行。 本文將說明這些資料行,並提供在查詢中加以使用的範例。

Application Insights 中的工作區型應用程式會將其資料儲存至 Log Analytics 工作區,並使用與工作區中其他資料表相同的標準資料行。 傳統應用程式會個別儲存其資料,並具有本文中所指定的不同標準資料行。

注意

有些標準資料行將不會顯示在 Log Analytics 的結構描述檢視或 Intellisense 中,除非您在輸出中明確指定資料行,否則資料行不會顯示在查詢結果中。

TenantId

TenantId 資料行會保存 Log Analytics 工作區的工作區識別碼。

TimeGenerated

TimeGenerated 資料行包含資料來源建立記錄的日期和時間。 如需詳細資料,請參閱 Azure 監視器中的記錄資料內嵌時間

TimeGenerated 提供用於依時間進行篩選或總結的通用資料行。 當您在 Azure 入口網站中針對檢視或儀表板選取時間範圍時,就是使用 TimeGenerated 來篩選結果。

注意

支援傳統 Application Insights 資源的資料表會使用 timestamp 資料行,而不是 TimeGenerated 資料行。

注意

TimeGenerated 值不可比接收時間早 2 天以上,或晚於目前時間一天以上。 在某些情況下,如果值早 2 天以上或晚於目前時間一天以上,則其會取代為實際的接收時間。

範例

下列查詢會傳回前一週中每天建立的錯誤事件數目。

Event
| where EventLevelName == "Error" 
| where TimeGenerated between(startofweek(ago(7days))..endofweek(ago(7days))) 
| summarize count() by bin(TimeGenerated, 1day) 
| sort by TimeGenerated asc 

_TimeReceived

_TimeReceived 資料行包含 Azure 監視器內嵌點在 Azure 雲端中接收到記錄的日期和時間。 這很適合用來識別資料來源與雲端之間的延遲問題。 例如,網路問題會導致從代理程式傳送資料延遲。 如需詳細資料,請參閱 Azure 監視器中的記錄資料內嵌時間

注意

_TimeReceived 資料行在每次使用時都會進行計算。 此程序會耗用大量資源。 請避免使用此程序來篩選大量記錄。 週期性使用此函數可能會導致查詢執行持續時間增加。

下列查詢會為來自代理程式的事件記錄提供每小時的平均延遲。 這包括從代理程式到雲端的時間,以及記錄可供記錄查詢使用的總時間。

Event
| where TimeGenerated > ago(1d) 
| project TimeGenerated, TimeReceived = _TimeReceived, IngestionTime = ingestion_time() 
| extend AgentLatency = toreal(datetime_diff('Millisecond',TimeReceived,TimeGenerated)) / 1000
| extend TotalLatency = toreal(datetime_diff('Millisecond',IngestionTime,TimeGenerated)) / 1000
| summarize avg(AgentLatency), avg(TotalLatency) by bin(TimeGenerated,1hr)

類型

Type 資料行會保留資料表名稱,而從中擷取的記錄也可視為記錄類型。 此資料行適用於合併多份資料表中記錄的查詢 (例如使用 search 運算子的查詢),可區分不同類型的記錄。 $table 可以用來取代某些查詢中的 Type

注意

支援傳統 Application Insights 資源的資料表會使用 itemType 資料行,而不是 Type 資料行。

範例

下列查詢會依據類型傳回過去一小時所收集的記錄計數。

search * 
| where TimeGenerated > ago(1h)
| summarize count() by Type

_ItemId

_ItemId 資料行會保存記錄的唯一識別碼。

_ResourceId

_ResourceId 資料行會保存記錄相關聯資源的唯一識別碼。 這會提供給您一個標準資料行以用來只將查詢範圍限定於來自特定資源的記錄,或聯結跨多個資料表的相關資料。

就 Azure 資源而言,_ResourceId 的值為 Azure 資源識別碼 URL。 此資料行僅限於 Azure 資源 (包括 Azure Arc 資源) 或已指出內嵌期間資源識別碼的自訂記錄。

注意

某些資料類型的欄位已包含 Azure 資源識別碼,或是至少屬於其一部份的訂用帳戶識別碼等。 雖然這些欄位會保留回溯相容性,但還是建議您使用 _ResourceId 執行交叉相互關聯,這樣將會更一致。

範例

下列是將每一部電腦的效能和事件資料相聯結的查詢。 其中顯示識別碼為 101 且處理器使用率超過 50% 的所有事件。

Perf 
| where CounterName == "% User Time" and CounterValue  > 50 and _ResourceId != "" 
| join kind=inner (     
    Event 
    | where EventID == 101 
) on _ResourceId

下列是將 AzureActivity 記錄與 SecurityEvent 記錄相聯結的查詢。 其中顯示已登入這些機器的使用者所產生的所有活動作業。

AzureActivity 
| where  
    OperationName in ("Restart Virtual Machine", "Create or Update Virtual Machine", "Delete Virtual Machine")  
    and ActivityStatus == "Succeeded"  
| join kind= leftouter (    
   SecurityEvent 
   | where EventID == 4624  
   | summarize LoggedOnAccounts = makeset(Account) by _ResourceId 
) on _ResourceId  

下列查詢會剖析每個 Azure 資源群組的 _ResourceId,以及彙總已計費的資料量。

union withsource = tt * 
| where _IsBillable == true 
| parse tolower(_ResourceId) with "/subscriptions/" subscriptionId "/resourcegroups/" 
    resourceGroup "/providers/" provider "/" resourceType "/" resourceName   
| summarize Bytes=sum(_BilledSize) by resourceGroup | sort by Bytes nulls last 

請謹慎使用這些 union withsource = tt * 查詢,因為執行跨資料類型掃描的費用相當高昂。

使用 _SubscriptionId 資料行,一律會比剖析 _ResourceId 資料行來進行擷取更有效率。

_SubscriptionId

_SubscriptionId 資料行會保存記錄相關聯資源的訂用帳戶識別碼。 這會提供給您一個標準資料行以用來只將查詢範圍限定於來自特定訂用帳戶的記錄,或比較不同的訂用帳戶。

針對 Azure 資源,__SubscriptionId 的值為 Azure 資源識別碼 URL 的訂用帳戶部分。 此資料行僅限於 Azure 資源 (包括 Azure Arc 資源) 或已指出擷取期間訂用帳戶識別碼的自訂記錄。

注意

某些資料類型的欄位已包含 Azure 訂用帳戶識別碼。 雖然這些欄位會基於回溯相容性而予以保留,但還是建議您使用 _SubscriptionId 資料行來執行交叉相互關聯,這樣將會更為一致。

範例

下列查詢會檢查特定訂用帳戶電腦的效能資料。

Perf 
| where TimeGenerated > ago(24h) and CounterName == "memoryAllocatableBytes"
| where _SubscriptionId == "ebb79bc0-aa86-44a7-8111-cabbe0c43993"
| summarize avgMemoryAllocatableBytes = avg(CounterValue) by Computer

下列查詢會剖析每個 Azure 訂用帳戶的 _ResourceId,以及彙總已計費的資料量。

union withsource = tt * 
| where _IsBillable == true 
| summarize Bytes=sum(_BilledSize) by _SubscriptionId | sort by Bytes nulls last 

請謹慎使用這些 union withsource = tt * 查詢,因為執行跨資料類型掃描的費用相當高昂。

_IsBillable

_IsBillable 資料行會指定所擷取的資料是否視為可計費。 _IsBillable 等於 false 的資料不會產生資料擷取、保留或封存費用。

範例

若要取得傳送計費資料類型的電腦清單,請使用下列查詢:

注意

請謹慎使用這些查詢搭配 union withsource = tt *,因為執行跨資料類型掃描相當昂貴。

union withsource = tt * 
| where _IsBillable == true 
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| where computerName != ""
| summarize TotalVolumeBytes=sum(_BilledSize) by computerName

加以延伸,即可傳回每小時傳送計費資料類型的電腦計數:

union withsource = tt * 
| where _IsBillable == true 
| extend computerName = tolower(tostring(split(Computer, '.')[0]))
| where computerName != ""
| summarize dcount(computerName) by bin(TimeGenerated, 1h) | sort by TimeGenerated asc

_BilledSize

如果 _IsBillable 為 true,則 _BilledSize 資料行會指定將計入 Azure 帳戶的資料大小 (位元組)。 若要深入了解如何計算大小計費的詳細資料,請參閱資料大小計算

範例

若要查看每部電腦所內嵌的可計費事件大小,請使用可提供大小 (位元組) 的 _BilledSize 資料行:

union withsource = tt * 
| where _IsBillable == true 
| summarize Bytes=sum(_BilledSize) by  Computer | sort by Bytes nulls last 

若要查看每個訂用帳戶所內嵌的可計費事件大小,請使用下列查詢:

union withsource=table * 
| where _IsBillable == true 
| summarize Bytes=sum(_BilledSize) by  _SubscriptionId | sort by Bytes nulls last 

若要查看每個訂用帳戶所內嵌的可計費事件大小,請使用下列查詢:

union withsource=table * 
| where _IsBillable == true 
| parse _ResourceId with "/subscriptions/" SubscriptionId "/resourcegroups/" ResourceGroupName "/" *
| summarize Bytes=sum(_BilledSize) by  _SubscriptionId, ResourceGroupName | sort by Bytes nulls last 

若要查看每部電腦所擷取的事件計數,請使用下列查詢:

union withsource = tt *
| summarize count() by Computer | sort by count_ nulls last

若要查看每部電腦所擷取的可計費事件計數,請使用下列查詢:

union withsource = tt * 
| where _IsBillable == true 
| summarize count() by Computer  | sort by count_ nulls last

若要查看特定電腦的可計費資料類型計數,請使用下列查詢:

union withsource = tt *
| where Computer == "computer name"
| where _IsBillable == true 
| summarize count() by tt | sort by count_ nulls last 

下一步