日誌分析工具Log Parser介紹

摘要: 微軟動態CRM專家羅勇 ,回覆321或者20190322可方便獲取本文,同時能夠在第一間獲得我發佈的最新博文信息,follow me!前端

分析Dynamics 365 Customer Engagement性能有時候須要分析前端服務器的IIS Log,這時候能夠用一個工具,就是 Log Parser,下載地址是 https://www.microsoft.com/en-us/download/details.aspx?id=24659 。windows

下載完畢安裝後,打開安裝目錄 C:\Program Files (x86)\Log Parser 2.2 ,將其中的文件 LogParser.exe 複製到 C:\Windows\System32 文件夾中,這樣在cmd或者PowerShell中就能夠直接使用命令分析日誌了,也能夠方便的查看幫助。打開界面輸入 logparser 結果以下:api

 

若是IIS 沒有啓動Log功能(默認安裝狀況下不啓用),建議先啓用。服務器

 

在服務器上輸入 INETMGR 打開 Internet Infomation Services (IIS) Manager ,打開IIS上的Logging網絡

 

IIS日誌默認狀況下是沒有記錄Bytes Sent和Bytes Received兩個字段的,建議勾選。從Directory: 就知道IIS日誌存放的路徑。less

 

若是訪問量很大,IIS Log文件會很大,打開麻煩,能夠考慮每一個日誌文件達到多大的時候生成一個新文件來記錄IIS 日誌。工具

將 IIS Log拿到後就能夠用Log Parser對它進行分析了,我這裏查看一個文件全部記錄,以另一種格式來看看。首先截圖原文是啥樣的,不是很好閱讀。性能

我是用下面語句來以另一種格式化一下以另一種形式展現:spa

logparser "select * from D:\u_ex190322.log" -o:datagrid3d

 

 展現的樣子以下:

默認只展現10行,能夠點擊下面的【All rows】按鈕。列太多,我選一些列來看看。

logparser "select date,time,c-ip,cs-method,cs-uri-stem,cs-uri-query,sc-status,sc-bytes,cs-bytes,time-taken from D:\u_ex190322.log" -o:datagrid

效果以下圖:

我這裏簡單對幾個列的含義作個說明(爲本人理解,不對正確性作保證):

列標題 含義 說明
date 請求發生的日期 UTC 0時區日期
time 請求發生的時間 UTC 0時區時間
c-ip Client IP Address 請求發起的客戶端IP
cs-uri-stem URI Stem

摘自:https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmlog/fc4b49d7-e83f-4389-8063-414f8bad80dd

This field MUST specify the URL actually used by the client. Any query strings MUST be excluded from the URL. (This means that the value of the cs-uri-stem field is equal to the URL actually used by the client, truncated at the first "?" character.)

我簡單理解就是訪問的網址 ? 符號的前面部分

cs-uri-query URI Query

摘自:https://docs.microsoft.com/en-us/dotnet/api/system.uri.query?view=netframework-4.7.2

The Query property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information returned includes the leading question mark.

我簡單理解就是訪問的網址 ? 符號的後面部分

sc-status Protocal Status 對於HTTP請求來說就是返回的HTTP status code
cs-method Method 對於HTTP請求來說就是請求的動做把,好比GET,POST,DELETE,PUT等
sc-byte Bytes Sent 就是服務器端給客戶端發送內容的大小,以字節爲單位
cs-byte Bytes Received 就是客戶端給服務器端發送內容的大小,以字節爲單位
time-taken Time Taken

摘自:https://support.microsoft.com/en-us/help/944884/description-of-the-time-taken-field-in-iis-6-0-and-iis-7-0-http-loggin

The time-taken field measures the length of time that it takes for a request to be processed. The client-request time stamp is initialized when HTTP.sys receives the first byte of the request. HTTP.sys is the kernel-mode component that is responsible for HTTP logging for IIS activity. The client-request time stamp is initialized before HTTP.sys begins parsing the request. The client-request time stamp is stopped when the last IIS response send completion occurs. 

Beginning in IIS 6.0, the time-taken field typically includes network time.

Note The value in the time-taken field does not include network time if one of the following conditions is true:

  • The response size is less than or equal to 2 KB, and the response size is from memory.
  • TCP buffering is used. Applications that use HTTPAPI.dll can set the HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA flag to enable TCP buffering on Windows Server 2003 Service Pack 1 and later. This allows the server to send all of the response data to the client without having to wait for the client’s corresponding acknowledgements.

我來簡單理解就是請求從接到到發送給客戶端消耗的時間,應該是毫秒爲單位。若是客戶端請求的或者服務器端返回的內容比較大,且網絡不是很好的話,是可能比較耗時的。

固然也能夠作一些統計,好比統計耗時超過10s的請求數量:

logparser "select count(*) from D:\u_ex190322.log where time-taken >=10000"

 

固然還能夠導出部分請求,示例以下:

logparser "select date,time,c-ip,cs-method,cs-uri-stem,cs-uri-query,sc-status,sc-bytes,cs-bytes,time-taken from D:\u_ex190322.log where time-taken >=10000" -o:datagrid

在打開的新窗口中是能夠顯示全部符合條件記錄(使用【All rows】按鈕),而後用 Ctrl + A 全選,Ctrl + C 複製,能夠直接粘貼到Excel中。

相關文章
相關標籤/搜索