Azure 诊断扩展是 Azure Monitor 中的一个代理,可从 Azure 虚拟机的来宾操作系统和工作负荷及其他计算资源收集监视数据。 本文介绍如何将数据从 Microsoft Azure 诊断(WAD)扩展发送到 Azure 事件中心 ,以便可以转发到 Azure 外部的位置。
支持的数据
从来宾操作系统收集的可发送到事件中心的数据包括以下内容。 WAD 收集的其他数据源(包括 Internet Information Services (IIS) 日志和故障转储)无法发送到事件中心。
- Windows 事件跟踪 (ETW) 事件
- 性能计数器
- Windows 事件日志(包括 Windows 事件日志中的应用程序日志)
- Azure 诊断基础结构日志
先决条件
- Windows 诊断扩展 1.6 或更高版本。 请参阅 Azure 诊断扩展配置架构版本和历史记录以获取版本历史记录,参阅 Azure 诊断扩展概述以获取支持的资源。
- 必须始终预配事件中心命名空间。 请参阅事件中心入门以获取详细信息。
- 事件中心必须至少为标准层。 不支持基本层。
配置架构
有关启用 和配置诊断扩展的不同选项,请参阅安装和配置 Microsoft Azure 诊断扩展(WAD )。 有关配置架构的参考,请参阅 Azure 诊断配置 架构。 本文的其余部分介绍如何使用此配置将数据发送到事件中心。
Azure 诊断始终将日志和指标发送到 Azure 存储帐户。 可以配置一个或多个将数据发送到其他位置 的数据接收器 。 每个接收器都在公共配置的 SinksConfig 元素中定义,而敏感信息则包含在专用配置中。 事件中心的此配置使用下表中的值。
| 属性 | 说明 |
|---|---|
| 名称 | 接收器的说明性名称。 在配置中用于指定要发送到接收器的数据源。 |
| 网址 | 事件中心的 URL 格式为 <event-hubs-namespace>.servicebus.chinacloudapi.cn/<event-hub-name>。 |
| 共享访问密钥名称 | 事件中心的至少具有“发送”权限的共享访问策略的名称。 |
| 共享访问密钥 | 事件中心的共享访问策略中的主密钥或辅助密钥。 |
以下示例显示了公共配置和专用配置。 它是使用单个性能计数器和事件日志进行的最低配置,演示如何配置和使用事件中心数据接收器。 如需更复杂的示例,请参阅 Azure 诊断配置架构。
公共配置
{
"WadCfg": {
"DiagnosticMonitorConfiguration": {
"overallQuotaInMB": 5120,
"PerformanceCounters": {
"scheduledTransferPeriod": "PT1M",
"sinks": "myEventHub",
"PerformanceCounterConfiguration": [
{
"counterSpecifier": "\\Processor(_Total)\\% Processor Time",
"sampleRate": "PT3M"
}
]
},
"WindowsEventLog": {
"scheduledTransferPeriod": "PT1M",
"sinks": "myEventHub",
"DataSource": [
{
"name": "Application!*[System[(Level=1 or Level=2 or Level=3)]]"
}
]
}
},
"SinksConfig": {
"Sink": [
{
"name": "myEventHub",
"EventHub": {
"Url": "https://diags-mycompany-ns.servicebus.chinacloudapi.cn/diageventhub",
"SharedAccessKeyName": "SendRule"
}
}
]
}
},
"StorageAccount": "mystorageaccount",
}
专用配置
{
"storageAccountName": "mystorageaccount",
"storageAccountKey": "{base64 encoded key}",
"storageAccountEndPoint": "https://core.chinacloudapi.cn",
"EventHub": {
"Url": "https://diags-mycompany-ns.servicebus.chinacloudapi.cn/diageventhub",
"SharedAccessKeyName": "SendRule",
"SharedAccessKey": "{base64 encoded key}"
}
}
配置选项
若要将数据发送到数据接收器,请在数据源的节点上指定 sinks 特性。 在何处放置 sinks 特性决定了分配的范围。 在以下示例中,sinks 属性被定义为 PerformanceCounters 节点。 这会导致所有子性能计数器发送到事件中心。
"PerformanceCounters": {
"scheduledTransferPeriod": "PT1M",
"sinks": "MyEventHub",
"PerformanceCounterConfiguration": [
{
"counterSpecifier": "\\Processor(_Total)\\% Processor Time",
"sampleRate": "PT3M"
},
{
"counterSpecifier": "\\Memory\\Available MBytes",
"sampleRate": "PT3M"
},
{
"counterSpecifier": "\\Web Service(_Total)\\ISAPI Extension Requests/sec",
"sampleRate": "PT3M"
}
]
}
在以下示例中,sink属性直接应用于三个计数器。 它只会导致将这些性能计数器发送到事件中心。
"PerformanceCounters": {
"scheduledTransferPeriod": "PT1M",
"PerformanceCounterConfiguration": [
{
"counterSpecifier": "\\Processor(_Total)\\% Processor Time",
"sampleRate": "PT3M",
"sinks": "MyEventHub"
},
{
"counterSpecifier": "\\Memory\\Available MBytes",
"sampleRate": "PT3M"
},
{
"counterSpecifier": "\\Web Service(_Total)\\ISAPI Extension Requests/sec",
"sampleRate": "PT3M"
},
{
"counterSpecifier": "\\ASP.NET\\Requests Rejected",
"sampleRate": "PT3M",
"sinks": "MyEventHub"
},
{
"counterSpecifier": "\\ASP.NET\\Requests Queued",
"sampleRate": "PT3M",
"sinks": "MyEventHub"
}
]
}
验证配置
可以使用各种方法验证数据是否发送到事件中心。 一种直接的方法是使用事件中心捕获,如通过 Azure Blob 存储或 Azure Data Lake Storage 中的 Azure 事件中心来捕获事件中所述。
排查事件中心接收器问题
查看 Azure 存储表 WADDiagnosticInfrastructureLogsTable,其中包含 Azure 诊断本身的日志和错误。 可使用 Azure 存储资源管理器 等工具连接到此存储帐户,查看此表,并添加过去 24 小时的时间戳查询。 可以使用此工具导出 .csv 文件,并在 Microsoft Excel 之类的应用程序中打开它。 Excel 可轻松搜索电话卡字符串(如 EventHubs),查看系统报告了哪些错误。
检查是否已成功预配事件中心。 配置的 PrivateConfig 节的所有连接信息必须与门户中显示的资源值匹配。 请确保已在门户中定义 SAS 策略(本示例中为 SendRule),并为其授予“发送”权限。