分析 Log Analytics 工作区中的使用情况
Azure Monitor 成本可能会因 Log Analytics 工作区中收集的数据量而有很大差异。 此容量受使用工作区的解决方案集以及每个解决方案收集的数据量的影响。 本文提供有关分析收集的数据的指导,以帮助控制数据引入成本。 这有助于确定使用率高于预期的原因。 还有助于在监视更多资源和配置不同的 Azure Monitor 功能时预测成本。
提示
有关降低 Azure Monitor 成本的策略,请参阅成本优化和 Azure Monitor。
每个 Log Analytics 工作区作为独立服务计费,并在 Azure 订阅的账单中产生相应费用。 根据以下因素,数据引入量有时会很大:
- 已启用见解和服务集及其配置。
- 受监视资源的数量和类型。
- 从每个受监视资源收集的数据量。
任何这些因素的意外增加都可能导致数据保留费用增加。 本文的其余部分提供了方法,用于检测此类情况,然后分析收集的数据,以识别和缓解使用量增加的来源。
为了避免出现意外账单,应让系统在遇到过度使用时主动通知你。 通知使你可以在计费期结束之前解决任何潜在的异常情况。
以下示例是一个日志搜索警报规则,如果在过去 24 小时内引入的可计费数据量大于 50 GB,它会发送警报。 根据环境中的预期使用情况修改“警报逻辑”设置以使用不同的阈值。 还可以增加频率以每天多次检查使用情况,但此选项会导致警报规则的费用更高。
设置 | 值 |
---|---|
范围 | |
目标作用域 | 选择 Log Analytics 工作区。 |
条件 | |
查询 | Usage | where IsBillable | summarize DataGB = sum(Quantity / 1000) |
度量 | 度量值:DataGB 聚合类型:Total 聚合粒度:1 天 |
警报逻辑 | 运算符:大于 阈值:50 评估频率:1 天 |
操作 | 选择或添加一个操作组,以便在超过阈值时通知你。 |
详细信息 | |
严重性 | 警告 |
预警规则名称 | 24 小时内的可计费数据量大于 50 GB。 |
使用 Azure Monitor 中的现有工具开始分析。 这些工具不需要配置,并且通常只需极少的工作量即可提供所需的信息。 如果需要对收集的数据进行比现有 Azure Monitor 功能更深入的分析,可以在 Log Analytics 中使用以下任何日志查询。
Log Analytics 工作区见解可让你快速了解工作区中的数据。 例如,可以确定:
- 在主表中引入的数据量最大的数据表。
- 贡献数据最多的资源。
- 数据引入趋势。
请参阅“使用情况”选项卡,了解按解决方案和表划分的引入明细。 此信息有助于快速识别导致大量数据量的表。 该选项卡还显示一段时间内数据收集的趋势。 可以确定数据收集是随着时间的推移稳步增加,还是因配置更改而突然增加。
选择“其他查询”,使用可帮助你进一步了解数据模式的预生成查询。
在每个工作区的“使用情况和预估成本”页的“单个解决方案的数据引入”图表中,显示了过去 31 天内发送的数据总量以及每个解决方案发送的数据量。 此信息有助于确定趋势,例如任何增长是来自于整体的数据使用,还是来自于某个特定的解决方案的使用。
分析特定服务或解决方案收集的可计费数据量。 这些查询使用 Usage 表,该表收集工作区中每个表的使用情况数据。
备注
带有 TimeGenerated
的子句仅用于确保 Azure 门户中的查询体验在超出默认的 24 小时后会回看。 使用“使用情况”数据类型时,StartTime
和 EndTime
表示显示结果的时间存储桶。
过去一个月内按类型划分的可计费数据量
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
表中的特定事件 ID,然后为每个 ID 提供计数。 可以使用其他表中的列修改此查询。
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)
可以分析从特定资源或资源集收集的可计费数据量。 这些查询使用 _ResourceId 和 _SubscriptionId 列来获取 Azure 中托管的资源的数据。
过去一整天按资源 ID 统计的可计费数据量
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 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
如果发现特定数据类型的可计费数据过多,则可能需要执行查询以分析该表中的数据。 以下查询提供了一些常见数据类型的示例:
“安全”解决方案
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
| summarize AggregatedValue = count() by CounterPath
Perf
| summarize AggregatedValue = count() by CounterName
“事件”数据类型
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 收集的数据量,具体取决于你拥有的是经典应用程序还是基于工作区的应用程序。 对于基于工作区的资源和经典资源,使用可用于每个引入事件的 _BilledSize
属性。 还可以将 systemEvents 表中的聚合信息用于经典资源。
备注
对 Application Insights 表的查询(SystemEvents
除外)将适用于基于工作空间的资源和经典 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 表的查询。 以下查询使用特定于基于工作区的资源的表名称。
7 天内工作区中所有 Application Insights 资源的每日数据量(按类型统计)
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
最近 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
表示。 如果工作区安装了更新管理解决方案,请将 Update 和 UpdateSummary 数据类型添加到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
备注
当使用解决方案目标设定时,实际的计费算法中会有些复杂性,而上述查询中并未体现这种复杂性。
如果你观察到使用 Usage
记录报告的数据引入量过高,但发现直接对该数据类型执行 _BilledSize
求和的结果却并不相同,则数据有可能延迟抵达。 使用旧时间戳引入数据时便会发生这种情况。
例如,代理可能存在连接问题,并在重新连接后发送累积的数据。 或者主机的时间可能不正确。 任一示例可能会导致,按“使用情况”数据类型报告的引入数据与某个查询针对 TimeGenerated(生成事件时的时间戳)指定的特定日期的原始数据的 _BilledSize 求和后报告的引入数据之间存在明显的偏差。
若要诊断数据延迟到达的问题,请使用 _TimeReceived 列和 TimeGenerated 列。 _TimeReceived
属性是 Azure 云中的 Azure Monitor 引入点收到记录的时间。
以下示例响应 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
- 请参阅 Azure Monitor 日志定价详细信息,了解计算 Log Analytics 工作区中的数据费用的方式,以及用于降低费用的不同配置选项。
- 请参阅 Azure Monitor 成本和使用情况,了解不同类型的 Azure Monitor 费用,以及针对 Azure 帐单分析这些费用的方式。
- 请参阅 Azure Monitor 最佳做法 - 成本管理,了解有关配置和管理 Azure Monitor 以最大程度地减少费用的最佳做法。
- 有关使用转换通过筛选不需要的记录和列来减少在 Log Analytics 工作区中收集的数据量的信息,请参阅 Azure Monitor 中的数据收集转换(预览)。