首页 文章

高性能事件日志

提问于
浏览
11

所以我一直在尝试各种方法来批量获取事件日志数据(1000条记录/秒) .

我需要能够过滤旧日志的东西,现在我存储最后记录的事件记录ID并检索事件ID大于那个的所有记录....

我已经尝试过EventLogQuery / EventLogReader,这个工作很快,除非我想拉消息数据,为了获得安全日志的格式化消息,我需要调用EventLogRecord.FormattedMessage(),这使我的日志速度达到约150 /秒具有易于格式化的日志,更复杂的日志更糟糕 .

我已经尝试过System.Diagnoistics.EventLog,这不允许我构建过滤器,所以每次运行它都必须加载所有事件日志,然后我可以解析任何重复项(从上次扫描) . 我有一个在过去两天内有200万个事件日志的服务器,由于这个内存使用情况变得很糟糕,所以这是不行的 .

我已经尝试过使用System.Management.ManagementObjectCollection的WMI,它有过滤功能,可以从安全事件日志中快速提取消息数据(接近~1000 /秒),但是它会达到大约50 / 60k并开始拖动它的脚,做到大约1-2 /秒,最终我会得到一个配额违规错误 . :(

所以要么:

有没有办法避免配额违规错误,或者我是否想使用其他方法以此速度提取事件日志?

编辑:

我写了一篇博文,详细介绍了我对此的了解:

http://www.roushtech.net/2013/10/30/high-performance-event-log-reading/

主要是:WINAPI是你最好的选择,要么写C / CLR,要么使用PInvoke .

2 回答

  • 3

    我发现托管代码太慢了,我最终使用win32 API来检索事件日志(本地和/或远程) . 它们很容易实现,并且有很多关于如何实现它的例子 . 它也会比你尝试和使用xml的任何事情都快得多 .

    新API:http://msdn.microsoft.com/en-us/library/aa385780(v=vs.85).aspx

    旧API:http://msdn.microsoft.com/en-us/library/aa363652(v=vs.85).aspx

    我还发现pre-vista API在我需要的时候运行良好,并且实际上比后vista机器上的新API更好 .

  • 2

    我可能会查看命令行实用程序:

    C:/> Wevtutil.exe qe Application / f:XML

    文件:http://technet.microsoft.com/en-us/library/cc732848(WS.10).aspx

    它将保存书签并从书签继续,并用于处理更复杂的查询 .

    例如,假设您希望所有事件的ID为1530,在一组1000中,来自您保存的最后一个书签,预先用英语呈现:

    Wevtutil qe Application / f:RenderedXml /bm:bookmark.pos /sbm:bookmark.pos / c:1000 / e:Log / l:en-us / q:Event [System / EventID ='1530']

    这个事件看起来像:

    <Log>
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
        <System>
          <Provider Name="Microsoft-Windows-User Profiles Service" Guid="{89B1E9F0-5AFF-44A6-9B44-0A07A7CE5845}"/>
          <EventID>1530</EventID>
          <Version>0</Version>
          <Level>3</Level>
          <Task>0</Task>
          <Opcode>0</Opcode>
          <Keywords>0x8000000000000000</Keywords>
          <TimeCreated SystemTime="2011-06-16T22:55:32.305140500Z"/>
          <EventRecordID>26196</EventRecordID>
          <Correlation/>
          <Execution ThreadID="4168" ProcessID="1660"/>
          <Channel>Application</Channel>
          <Computer>hostname.WORKGROUP</Computer>
          <Security UserID="S-1-5-18"/>
        </System>
        <EventData Name="EVENT_HIVE_LEAK">
          <Data Name="Detail">0 user registry handles leaked from \Registry\User\S-1-5-82: </Data>
        </EventData>
        <RenderingInfo Culture="en-US">
          <Message>Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards. DETAIL - 0 user registry handles leaked from \Registry\User\S-1-5-82: </Message>
          <Level>Warning</Level>
          <Task/>
          <Opcode>Info</Opcode>
          <Channel>Application</Channel>
          <Provider>Microsoft-Windows-User Profile Service</Provider>
          <Keywords/>
        </RenderingInfo>
      </Event>
    

    使用快速轻量级xml解析器,您应该能够在并行生成下一个结果页面时尖叫这些数据 . 如果直接捕获过程输出,甚至不需要将其写入磁盘 . 请确保您还捕获std :: error,因为此实用程序还会将错误写入该输出 .

相关问题