Windows系統(tǒng)日志收集

方案

采用nxlog+fluentd+elasticsearch組件酱虎。nxlog 是用 C 語言寫的一個跨平臺日志收集處理軟件双藕,其內(nèi)部支持使用 Perl 正則和語法來進行數(shù)據(jù)結(jié)構(gòu)化和邏輯判斷操作坏怪。nxlog負責收集Windows系統(tǒng)日志郎哭,并將日志傳給fluentd款侵,fluentd將這些日志信息拋給elasticsearch割疾。fluentd官方文檔Collecting Log Data from Windows中也是推薦使用該方案的。

預(yù)先準備

  1. Windows服務(wù)器(本次使用的是Win10)栅干。
  2. Linux服務(wù)器(本次使用的CentOS7)迈套。
  3. 下載elasticsearch并安裝在Linux服務(wù)器上。

環(huán)境搭建步驟

Windows上安裝nxlog

  1. 下載Windows版本的nxlog碱鳞。
  2. 直接點擊next安裝即可桑李。

補充:nxlog默認是安裝在C:\Program Files (x86)\nxlog目錄中。

Linux上安裝fluentd

  1. 若從rpm庫安裝窿给,執(zhí)行如下命令:
$ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-  agent2.sh | sh
  1. 常用命令:
$ /etc/init.d/td-agent start
$ /etc/init.d/td-agent stop
$ /etc/init.d/td-agent restart
$ /etc/init.d/td-agent status

測試

修改配置文件

  1. 修改td-agent配置文件/etc/td-agent/td-agent.conf

    $ vim /etc/td-agent/td-agent.conf
    

    增添如下配置并保存:

    <source>
       @type tcp
       format json
       port 5140
       tag windowslog
     </source>
     <match windowslog>
       type elasticsearch
     </match>
    
  2. 修改nxlog配置文件C:\Program Files (x86)\nxlog\conf
    改后的文件如下所示:

    define ROOT C:\Program Files (x86)\nxlog
    
    Moduledir %ROOT%\modules
    CacheDir %ROOT%\data
    Pidfile %ROOT%\data\nxlog.pid
    SpoolDir %ROOT%\data
    LogFile %ROOT%\data\nxlog.log
    
    <Extension _syslog>
        Module      xm_syslog
    </Extension>
    
    <Extension json>
        Module xm_json
    </Extension>
    #日志輸入端
    <Input in>
        Module im_msvistalog 
        #For windows 2003 and earlier use the following:
        #Module im_mseventlog
        Exec to_json(); 
    </Input>
    #日志輸出端
    <Output out>
        Module om_tcp
        Host 192.168.159.133    #安裝有td-agent的服務(wù)器地址
        Port 5140               #此端口要與td-agent監(jiān)聽端口一致
    </Output> 
    <Output outfile>
        Module om_file
        File   "D:\logs\log"    #為了便于觀察贵白,將收集到的系統(tǒng)日志存放在該位置下
    </Output>
    #綁定某輸入到具體某輸出
    <Route r1>
        Path in => out
    </Route>
    <Route r2>
        Path in => outfile
    </Route>
    

啟動服務(wù)

  1. 啟動td-agent:

    $ /etc/init.d/td-agent start
    
  2. 啟動nxlog,使用powershell進入到C:\Program Files (x86)\nxlog目錄下崩泡,執(zhí)行命令:

    C:\Program Files (x86)\nxlog> .\\nxlog.exe -f -c ./conf/nxlog.conf
    

    部分輸出如下:

    2017-07-13 14:43:30 INFO connecting to 192.168.159.133:5140
    2017-07-13 14:43:30 INFO nxlog-ce-2.9.1716 started
    

結(jié)果

在Linux控制臺查看elasticsearch中的索引:

[root@localhost ~]# curl 'localhost:9200/_cat/indices?v'
health status index               uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   fluentd             c05Ykvp_RPebnOppfsa1_w   5   1          2            0     67.7kb         67.7kb
yellow open   .kibana             Zldk9n-BSweLtaeVNMsNtg   1   1          8            0       54kb           54kb

查看fluentd索引中的數(shù)據(jù)禁荒,部分輸出如下:

[root@localhost ~]# curl -XGET 'localhost:9200/fluentd/_search?pretty'
{
  "took" : 363,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 68,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "fluentd",
        "_type" : "fluentd",
        "_id" : "AV06sthgdjHN6maqugXM",
        "_score" : 1.0,
        "_source" : {
          "EventTime" : "2017-07-13 14:45:59",
          "Hostname" : "LAPTOP-AQ1VQEMH",
          "Keywords" : 576460752303423488,
          "EventType" : "INFO",
          "SeverityValue" : 2,
          "Severity" : "INFO",
          "EventID" : 20,
          "SourceName" : "Microsoft-Windows-Audio",
          "ProviderGuid" : "{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}",
          "Version" : 0,
          "Task" : 116,
          "OpcodeValue" : 0,
          "RecordNumber" : 113490,
          "ProcessID" : 6804,
          "ThreadID" : 13988,
          "Channel" : "Microsoft-Windows-Audio/PlaybackManager",
          "Domain" : "LAPTOP-AQ1VQEMH",
          "AccountName" : "WHL",
          "UserID" : "S-1-5-21-2442955922-1256182451-2774828708-1001",
          "AccountType" : "User",
          "Message" : "格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false",
          "Opcode" : "信息",
          "Format" : "1",
          "SamplingRate" : "22050",
          "bAudioSrvStreamResourceType" : "false",
          "EventReceivedTime" : "2017-07-13 14:46:00",
          "SourceModuleName" : "in",
          "SourceModuleType" : "im_msvistalog"
        }
      },
      {
        "_index" : "fluentd",
        "_type" : "fluentd",
        "_id" : "AV06uizFdjHN6maqugXh",
        "_score" : 1.0,
        "_source" : {
          "EventTime" : "2017-07-13 14:53:26",
          "Hostname" : "LAPTOP-AQ1VQEMH",
          "Keywords" : 576460752303423488,
          "EventType" : "INFO",
          "SeverityValue" : 2,
          "Severity" : "INFO",
          "EventID" : 505,
          "SourceName" : "Microsoft-Windows-Application-Experience",
          "ProviderGuid" : "{EEF54E71-0661-422D-9A98-82FD4940B820}",
          "Version" : 0,
          "Task" : 0,
          "OpcodeValue" : 0,
          "RecordNumber" : 31916,
          "ProcessID" : 14276,
          "ThreadID" : 13872,
          "Channel" : "Microsoft-Windows-Application-Experience/Program-Telemetry",
          "Domain" : "LAPTOP-AQ1VQEMH",
          "AccountName" : "WHL",
          "UserID" : "S-1-5-21-2442955922-1256182451-2774828708-1001",
          "AccountType" : "User",
          "Message" : "兼容性修復(fù)程序已應(yīng)用于 C:\\Users\\WHL\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe蛆橡。\r\n修補程序信息: Google Chrome淘菩,{18A8B5B2-9D2F-4DB2-8307-196B5CC0CE6B},0x80010101季春。",
          "Opcode" : "信息",
          "EventReceivedTime" : "2017-07-13 14:53:28",
          "SourceModuleName" : "in",
          "SourceModuleType" : "im_msvistalog"
        }
      },

打開D:\logs下的log文件靴寂,部分輸出如下:

{"EventTime":"2017-07-13 14:43:51","Hostname":"LAPTOP-AQ1VQEMH","Keywords":4611686018429485056,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":146,"SourceName":"Microsoft-Windows-Ntfs","ProviderGuid":"{3FF37A1C-A68D-4D6E-8C9B-F79E8B16C482}","Version":1,"Task":0,"OpcodeValue":0,"RecordNumber":11792,"ProcessID":4,"ThreadID":8584,"Channel":"Microsoft-Windows-Ntfs/Operational","Domain":"NT AUTHORITY","AccountName":"SYSTEM","UserID":"S-1-5-18","AccountType":"Well Known Group","Message":"IO latency summary:\r\n\r\n           Volume Id: {4E0E6863-60CA-4F3A-ADC1-EA02A7E953E3}\r\n           Volume name: C:\r\n           Is boot volume: true\r\n\r\n           Interval duration: 3627921184 us\r\n\r\n           Non-cached reads:\r\n                     IO count: 7387\r\n                     Total bytes: 466456052\r\n                     Avg latency: 8210412 ns\r\n\r\n           Non-cached writes: \r\n                     IO count: 24179\r\n                     Total bytes: 412844919\r\n                     Avg latency: 3188872 ns\r\n\r\n           File flushes: \r\n                     IO count: 1622\r\n                     Avg latency: 17203859 ns\r\n\r\n           Volume flushes: \r\n                     IO count: 0\r\n                     Avg latency: 0 ns\r\n\r\n           File level trims: \r\n                     IO count: 1\r\n                     Total bytes: 147374080\r\n                     Extents count: 1\r\n                     Avg latency: 1947000 ns\r\n\r\n           Volume trims: \r\n                     IO count: 324\r\n                     Total bytes: 1420537856\r\n                     Extents count: 1548\r\n                     Avg latency: 1463830 ns\r\n\r\n For more details see the details tab.\r\n","Opcode":"信息","VolumeCorrelationId":"{4E0E6863-60CA-4F3A-ADC1-EA02A7E953E3}","VolumeNameLength":"2","VolumeName":"C:","IsBootVolume":"true","HighIoLatencyCount":"0","IntervalDurationUs":"3627921184","NCReadIOCount":"7387","NCReadTotalBytes":"466456052","NCReadAvgLatencyNs":"8210412","NCWriteIOCount":"24179","NCWriteTotalBytes":"412844919","NCWriteAvgLatencyNs":"3188872","FileFlushCount":"1622","FileFlushAvgLatencyNs":"17203859","VolumeFlushCount":"0","VolumeFlushAvgLatencyNs":"0","FileLevelTrimCount":"1","FileLevelTrimTotalBytes":"147374080","FileLevelTrimExtentsCount":"1","FileLevelTrimAvgLatencyNs":"1947000","VolumeTrimCount":"324","VolumeTrimTotalBytes":"1420537856","VolumeTrimExtentsCount":"1548","VolumeTrimAvgLatencyNs":"1463830","IoBucketsCount":"48","TotalBytesBucketsCount":"44","ExtentsBucketsCount":"4","IoCount":"35","TotalLatencyUs":"51080","TotalBytes":"1208320","TrimExtentsCount":"1537","IoTypeIndex":"0","EventReceivedTime":"2017-07-13 14:43:52","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:43:51","Hostname":"LAPTOP-AQ1VQEMH","Keywords":4611686018429485056,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":146,"SourceName":"Microsoft-Windows-Ntfs","ProviderGuid":"{3FF37A1C-A68D-4D6E-8C9B-F79E8B16C482}","Version":1,"Task":0,"OpcodeValue":0,"RecordNumber":11793,"ProcessID":4,"ThreadID":8584,"Channel":"Microsoft-Windows-Ntfs/Operational","Domain":"NT AUTHORITY","AccountName":"SYSTEM","UserID":"S-1-5-18","AccountType":"Well Known Group","Message":"IO latency summary:\r\n\r\n           Volume Id: {EFA1B98E-1BD3-45F1-A956-882127C35622}\r\n           Volume name: D:\r\n           Is boot volume: false\r\n\r\n           Interval duration: 3627921030 us\r\n\r\n           Non-cached reads:\r\n                     IO count: 11248\r\n                     Total bytes: 820325912\r\n                     Avg latency: 4644197 ns\r\n\r\n           Non-cached writes: \r\n                     IO count: 7992\r\n                     Total bytes: 242775864\r\n                     Avg latency: 15979689 ns\r\n\r\n           File flushes: \r\n                     IO count: 49\r\n                     Avg latency: 10135571 ns\r\n\r\n           Volume flushes: \r\n                     IO count: 0\r\n                     Avg latency: 0 ns\r\n\r\n           File level trims: \r\n                     IO count: 0\r\n                     Total bytes: 0\r\n                     Extents count: 0\r\n                     Avg latency: 0 ns\r\n\r\n           Volume trims: \r\n                     IO count: 2\r\n                     Total bytes: 16384\r\n                     Extents count: 4\r\n                     Avg latency: 893000 ns\r\n\r\n For more details see the details tab.\r\n","Opcode":"信息","VolumeCorrelationId":"{EFA1B98E-1BD3-45F1-A956-882127C35622}","VolumeNameLength":"2","VolumeName":"D:","IsBootVolume":"false","HighIoLatencyCount":"0","IntervalDurationUs":"3627921030","NCReadIOCount":"11248","NCReadTotalBytes":"820325912","NCReadAvgLatencyNs":"4644197","NCWriteIOCount":"7992","NCWriteTotalBytes":"242775864","NCWriteAvgLatencyNs":"15979689","FileFlushCount":"49","FileFlushAvgLatencyNs":"10135571","VolumeFlushCount":"0","VolumeFlushAvgLatencyNs":"0","FileLevelTrimCount":"0","FileLevelTrimTotalBytes":"0","FileLevelTrimExtentsCount":"0","FileLevelTrimAvgLatencyNs":"0","VolumeTrimCount":"2","VolumeTrimTotalBytes":"16384","VolumeTrimExtentsCount":"4","VolumeTrimAvgLatencyNs":"893000","IoBucketsCount":"35","TotalBytesBucketsCount":"32","ExtentsBucketsCount":"1","IoCount":"2902","TotalLatencyUs":"1952578","TotalBytes":"41503232","TrimExtentsCount":"4","IoTypeIndex":"0","EventReceivedTime":"2017-07-13 14:43:52","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:45:52","Hostname":"LAPTOP-AQ1VQEMH","Keywords":576460752303423488,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":20,"SourceName":"Microsoft-Windows-Audio","ProviderGuid":"{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}","Version":0,"Task":116,"OpcodeValue":0,"RecordNumber":113487,"ProcessID":6804,"ThreadID":13716,"Channel":"Microsoft-Windows-Audio/PlaybackManager","Domain":"LAPTOP-AQ1VQEMH","AccountName":"WHL","UserID":"S-1-5-21-2442955922-1256182451-2774828708-1001","AccountType":"User","Message":"格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false","Opcode":"信息","Format":"1","SamplingRate":"22050","bAudioSrvStreamResourceType":"false","EventReceivedTime":"2017-07-13 14:45:54","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:45:59","Hostname":"LAPTOP-AQ1VQEMH","Keywords":576460752303423488,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":20,"SourceName":"Microsoft-Windows-Audio","ProviderGuid":"{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}","Version":0,"Task":116,"OpcodeValue":0,"RecordNumber":113488,"ProcessID":6804,"ThreadID":12172,"Channel":"Microsoft-Windows-Audio/PlaybackManager","Domain":"LAPTOP-AQ1VQEMH","AccountName":"WHL","UserID":"S-1-5-21-2442955922-1256182451-2774828708-1001","AccountType":"User","Message":"格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false","Opcode":"信息","Format":"1","SamplingRate":"22050","bAudioSrvStreamResourceType":"false","EventReceivedTime":"2017-07-13 14:46:00","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:45:59","Hostname":"LAPTOP-AQ1VQEMH","Keywords":576460752303423488,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":20,"SourceName":"Microsoft-Windows-Audio","ProviderGuid":"{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}","Version":0,"Task":116,"OpcodeValue":0,"RecordNumber":113489,"ProcessID":6804,"ThreadID":9620,"Channel":"Microsoft-Windows-Audio/PlaybackManager","Domain":"LAPTOP-AQ1VQEMH","AccountName":"WHL","UserID":"S-1-5-21-2442955922-1256182451-2774828708-1001","AccountType":"User","Message":"格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false","Opcode":"信息","Format":"1","SamplingRate":"22050","bAudioSrvStreamResourceType":"false","EventReceivedTime":"2017-07-13 14:46:00","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:45:59","Hostname":"LAPTOP-AQ1VQEMH","Keywords":576460752303423488,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":20,"SourceName":"Microsoft-Windows-Audio","ProviderGuid":"{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}","Version":0,"Task":116,"OpcodeValue":0,"RecordNumber":113490,"ProcessID":6804,"ThreadID":13988,"Channel":"Microsoft-Windows-Audio/PlaybackManager","Domain":"LAPTOP-AQ1VQEMH","AccountName":"WHL","UserID":"S-1-5-21-2442955922-1256182451-2774828708-1001","AccountType":"User","Message":"格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false","Opcode":"信息","Format":"1","SamplingRate":"22050","bAudioSrvStreamResourceType":"false","EventReceivedTime":"2017-07-13 14:46:00","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
{"EventTime":"2017-07-13 14:45:59","Hostname":"LAPTOP-AQ1VQEMH","Keywords":576460752303423488,"EventType":"INFO","SeverityValue":2,"Severity":"INFO","EventID":20,"SourceName":"Microsoft-Windows-Audio","ProviderGuid":"{AE4BD3BE-F36F-45B6-8D21-BDD6FB832853}","Version":0,"Task":116,"OpcodeValue":0,"RecordNumber":113491,"ProcessID":6804,"ThreadID":11340,"Channel":"Microsoft-Windows-Audio/PlaybackManager","Domain":"LAPTOP-AQ1VQEMH","AccountName":"WHL","UserID":"S-1-5-21-2442955922-1256182451-2774828708-1001","AccountType":"User","Message":"格式: 1\r\n采樣率 : 22050Hz\r\n已卸載: false","Opcode":"信息","Format":"1","SamplingRate":"22050","bAudioSrvStreamResourceType":"false","EventReceivedTime":"2017-07-13 14:46:00","SourceModuleName":"in","SourceModuleType":"im_msvistalog"}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末磷蜀,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子百炬,更是在濱河造成了極大的恐慌褐隆,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件剖踊,死亡現(xiàn)場離奇詭異庶弃,居然都是意外死亡,警方通過查閱死者的電腦和手機德澈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門歇攻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人梆造,你說我怎么就攤上這事缴守。” “怎么了镇辉?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵屡穗,是天一觀的道長。 經(jīng)常有香客問我忽肛,道長村砂,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任屹逛,我火速辦了婚禮础废,結(jié)果婚禮上汛骂,老公的妹妹穿的比我還像新娘。我一直安慰自己评腺,他們只是感情好帘瞭,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蒿讥,像睡著了一般图张。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上诈悍,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機與錄音兽埃,去河邊找鬼侥钳。 笑死,一個胖子當著我的面吹牛柄错,可吹牛的內(nèi)容都是我干的舷夺。 我是一名探鬼主播,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼售貌,長吁一口氣:“原來是場噩夢啊……” “哼给猾!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起颂跨,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤敢伸,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后恒削,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體池颈,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年钓丰,在試婚紗的時候發(fā)現(xiàn)自己被綠了躯砰。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡携丁,死狀恐怖琢歇,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情梦鉴,我是刑警寧澤李茫,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站尚揣,受9級特大地震影響涌矢,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜快骗,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一娜庇、第九天 我趴在偏房一處隱蔽的房頂上張望塔次。 院中可真熱鬧,春花似錦名秀、人聲如沸励负。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽继榆。三九已至,卻和暖如春汁掠,著一層夾襖步出監(jiān)牢的瞬間略吨,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工考阱, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留翠忠,地道東北人。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓乞榨,卻偏偏與公主長得像秽之,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子吃既,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容