Azure Monitor日志中的标准列

Azure Monitor 日志中的数据作为一组记录存储在Log Analytics工作区或 Application Insights 应用程序中。 每个数据类型都有一组唯一的列。 许多数据类型具有跨多个类型通用的标准列。 本文介绍这些列,并提供有关如何在查询中使用它们的示例。

Application Insights 中基于工作区的应用程序将其数据存储在Log Analytics工作区中,并使用与工作区中的其他表相同的标准列。 经典应用程序单独存储其数据,并具有本文所述的不同标准列。

下表汇总了标准列。 经典版 Application Insights 表在相关说明中注明时会使用不同的列名。

列 Description 适用对象
TenantId Log Analytics 工作区的 ID。 工作区
TimeGenerated 记录由数据源创建的日期和时间。 经典 Application Insights 表使用 Timestamp。 工作区和经典 Application Insights
_TimeReceived 记录由Azure Monitor引入点接收的日期和时间。 工作区
Type 从中检索记录的表的名称。 经典 Application Insights 表使用 itemType。 工作区和经典 Application Insights
_ItemId 记录的唯一标识符。 工作区
_ResourceId 与记录关联的资源的唯一标识符。 工作区
_SubscriptionId 与记录关联的资源的订阅 ID。 工作区
_IsBillable 引入的数据是否计费。 工作区
_BilledSize 计费数据的大小(以字节为单位)。 工作区

注释

某些标准列未显示在架构视图或 Log Analytics 中的 IntelliSense 中。 除非你在输出中显式指定列,否则它们不会显示在查询结果中。

TenantId 列

TenantId 列保留Log Analytics工作区的工作区 ID。

TimeGenerated 列

TimeGenerated 列包含数据源创建记录的日期和时间。 更多信息请参见 Azure Monitor 中的日志数据摄取时间。

TimeGenerated 提供用于按时间筛选或汇总的常用列。 在Azure门户中为视图或仪表板选择时间范围时,它使用 TimeGenerated 筛选结果。

支持经典 Application Insights 资源的表使用 时间戳 列而不是 TimeGenerated 列。 TimeGenerated 值不能早于接收时间之前的两天或将来的一天以上。 如果该值超出该范围,Azure Monitor将其替换为实际接收时间。

例子

以下查询返回过去一周内每天创建的错误事件数。

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 Monitor 引入点接收的日期和时间。 这对于查明数据源与云之间的延迟问题非常有用。 例如,网络问题会导致从代理发送数据时出现延迟。 有关详细信息,请参阅 Azure Monitor 中的日志数据引入时间。

注释

使用 _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 资源 ID URL。 此列仅限于 Azure 资源,包括 Azure Arc 资源,或是在引入时标明资源 ID 的自定义的日志。

注释

某些数据类型已经具有包含 Azure 资源 ID 或至少其中一部分(例如订阅 ID)的字段。 尽管这些字段保持向后兼容性,但建议使用_ResourceId执行交叉关联,因为它更加一致。

例子

以下查询联接每台计算机的性能和事件数据。 它显示 ID 为 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  

以下查询分析 _ResourceId,并聚合每个 Azure 的资源组的计费数据量。

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 列保留与该记录关联的资源的订阅 ID。 这为你提供了一个标准列,用于将查询范围限定为来自特定订阅的记录,或者用于比较不同的订阅。

对于Azure资源,_SubscriptionId的值是Azure资源 ID URL 的订阅部分。 此列仅限于 Azure 资源(包括 Azure Arc 资源),或者仅限于在引入时指明订阅 ID 的自定义日志。

注释

某些数据类型已有包含Azure订阅 ID 的字段。 尽管这些字段保持向后兼容性,但建议使用_SubscriptionId列执行交叉关联,因为它更加一致。

例子

下面的查询检查特定订阅的计算机的性能数据。

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

以下查询分析 _ResourceId并聚合每个Azure订阅的计费数据量。

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

如 _ResourceId列所述,请谨慎使用 union withsource = tt * 查询,因为跨数据类型的扫描执行成本高昂。

_IsBillable列

_IsBillable 列指定引入的数据是否被视为可计费。 _IsBillable等于false的数据不会产生数据引入、保留、工作区复制或存档费用。

例子

若要获取发送计费数据类型的计算机的列表,请使用以下查询。 如 _ResourceId列所述,请谨慎使用 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 列

_BilledSize 列指定在 _IsBillable 为 true 时向 Azure 帐户计费的数据的大小(以字节为单位)。 请参阅数据大小计算,了解如何计算计费大小的更多详细信息。

例子

若要查看每台计算机引入的可计费事件的大小,请使用 _BilledSize 列,该列提供大小(以字节为单位):

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

若要查看每个订阅引入的可计费事件大小,请使用以下查询:

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

若要查看每个资源组引入的可计费事件大小,请使用以下查询:

union withsource = tt * 
| 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 

后续步骤