摘要: 微軟動態CRM專家羅勇 ,回復321或者20190322可方便獲取本文,同時可以在第一間得到我發布的最新博文信息,follow me!
分析Dynamics 365 Customer Engagement性能有時候需要分析前端服務器的IIS Log,這時候可以用一個工具,就是 Log Parser,下載地址是 https://www.microsoft.com/en-us/download/details.aspx?id=24659 。
下載完畢安裝后,打開安裝目錄 C:\Program Files (x86)\Log Parser 2.2 ,將其中的文件 LogParser.exe 復制到 C:\Windows\System32 文件夾中,這樣在cmd或者PowerShell中就可以直接使用命令分析日志了,也可以方便的查看幫助。打開界面輸入 logparser 結果如下:
如果IIS 沒有啟動Log功能(默認安裝情況下不啟用),建議先啟用。
在服務器上輸入 INETMGR 打開 Internet Infomation Services (IIS) Manager ,打開IIS上的Logging
IIS日志默認情況下是沒有記錄Bytes Sent和Bytes Received兩個字段的,建議勾選。從Directory: 就知道IIS日志存放的路徑。
如果訪問量很大,IIS Log文件會很大,打開麻煩,可以考慮每個日志文件達到多大的時候生成一個新文件來記錄IIS 日志。
將 IIS Log拿到后就可以用Log Parser對它進行分析了,我這里查看一個文件所有記錄,以另外一種格式來看看。首先截圖原文是啥樣的,不是很好閱讀。
我是用下面語句來以另外一種格式化一下以另外一種形式展示:
logparser "select * from D:\u_ex190322.log" -o:datagrid
展示的樣子如下:
默認只展示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 | 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 | 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. Note The value in the time-taken field does not include network time if one of the following conditions is true:
我來簡單理解就是請求從接到到發送給客戶端消耗的時間,應該是毫秒為單位。如果客戶端請求的或者服務器端返回的內容比較大,且網絡不是很好的話,是可能比較耗時的。 |
當然也可以做一些統計,比如統計耗時超過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中。