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