Azure Service Fabric应用程序日志记录与展现

Azure Service Fabric可以借助于EventStore进行平台的诊断,对于应用程序来说,用户可以自行选择方式记录应用程序日志。在使用模板创建ServiceFabric .net程序时,模板中会存在一个EventSource类,我们也可以使用这个官方提供的类来记录应用程序的日志,这篇文将就为大家介绍一下这个类以及部署在Azure上的集群如何使用这个类来记录以及展示日志。(关于其他记录日志的方法可以参考此文档 https://docs.azure.cn/zh-cn/service-fabric/service-fabric-how-to-diagnostics-log

EventSource类介绍

这个类是借助于ETW(Event Trace For Windows)的一种实现,关于这个类和ETW的详细介绍可以参考下面的博客:

https://www.cnblogs.com/artech/p/logging-via-etw.html 

https://github.com/jonwagner/EventSourceProxy/wiki/About-.NET-EventSource 

如何展示

在上面的的博客中有提到,如果想实时查看日志可以使用Perfview工具,但是如果使用ServiceFabric是不适合在实例上安装此工具并做到实时捕获该日志的,那么如何在ServiceFabric上查看这个日志呢?我们可以借助于Azure虚拟机实例的扩展,将该日志输出到存储账户指定的表中,以下为操作方式:

1.添加相应的扩展到实例中,可以在创建ServiceFabric在模板中添加,也可以创建完后,使用rest api或者powershell在虚拟机规模集中添加扩展。创建模板时添加可以参考:https://docs.azure.cn/zh-cn/service-fabric/service-fabric-diagnostics-event-aggregation-wad#collect-from-new-eventsource-channels,该步骤着重介绍rest api方式(标黄的部分都是需要自己填写的):

url:https://management.chinacloudapi.cn/subscriptions/订阅id/resourceGroups/resourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/virtualMachineScaleSetsName/extensions/DiagnosticExtensionName?api-version=2018-10-01

请求体内容:

{
     "name": "DiagnosticExtension",
     "properties": {
         "type": "IaaSDiagnostics",
         "autoUpgradeMinorVersion": true,
         "protectedSettings": {
             "storageAccountName": "StorageAccount",
             "storageAccountKey": "StorageAccountKey",
             "storageAccountEndPoint": "https://core.chinacloudapi.cn/"
         },
         "publisher": "Microsoft.Azure.Diagnostics",
         "settings": {
             "WadCfg": {
                 "DiagnosticMonitorConfiguration": {
                     "overallQuotaInMB": "50000",
                     "EtwProviders": {
                         "EtwEventSourceProviderConfiguration": [{
                                 "provider": "Microsoft-ServiceFabric-Actors",
                                 "scheduledTransferKeywordFilter": "1",
                                 "scheduledTransferPeriod": "PT5M",
                                 "DefaultEvents": {
                                     "eventDestination": "ServiceFabricReliableActorEventTable"
                                 }
                             },
                             {
                                 "provider": "Microsoft-ServiceFabric-Services",
                                 "scheduledTransferPeriod": "PT5M",
                                 "DefaultEvents": {
                                     "eventDestination": "ServiceFabricReliableServiceEventTable"
                                 }
                             },
                             {
                                 "provider": "EventSource名称",
                                 "scheduledTransferPeriod": "PT5M",
                                 "DefaultEvents": {
                                     "eventDestination": "表名称"
                                 }
                             }
                         ],
                         "EtwManifestProviderConfiguration": [{
                             "provider": "cbd93bc2-71e5-4566-b3a7-595d8eeca6e8",
                             "scheduledTransferLogLevelFilter": "Information",
                             "scheduledTransferKeywordFilter": "4611686018427387904",
                             "scheduledTransferPeriod": "PT5M",
                             "DefaultEvents": {
                                 "eventDestination": "ServiceFabricSystemEventTable"
                             }
                         }]
                     }
                 }
             },
             "StorageAccount": "StorageAccount"
         },
         "typeHandlerVersion": "1.5"
     }
}

Snipaste_2020-04-06_14-02-45

成功后会收到相应的201状态码返回,官方api文档可参考 https://docs.microsoft.com/zh-cn/rest/api/compute/virtualmachinescalesetvmextensions/createorupdate

2.即可刷新应用看相应的存储中是否有相应的表出现。

Snipaste_2020-04-06_14-07-06

猜你喜欢

转载自www.cnblogs.com/junshijie/p/12641901.html
今日推荐