From e5365eae94e50a7b51cd1d1ab2ed0cd029738eb4 Mon Sep 17 00:00:00 2001 From: zhouhaibin <283595276@qq.com> Date: Fri, 10 Aug 2012 09:58:18 +0800 Subject: [PATCH] update the slowSqlView function --- .../druid/support/http/StatViewServlet.java | 20 ++++++++++++++++- .../support/http/resources/js/sql.js | 10 +++++++-- .../resources/support/http/resources/sql.html | 22 ++++++++++--------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java index 009a0e373d..693dcf4e42 100644 --- a/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java +++ b/src/main/java/com/alibaba/druid/support/http/StatViewServlet.java @@ -1,6 +1,8 @@ package com.alibaba.druid.support.http; import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.List; import javax.servlet.ServletException; @@ -35,6 +37,7 @@ public class StatViewServlet extends HttpServlet { private static JSONDruidStatService jsonDruidStatService = JSONDruidStatService.getInstance(); public String templatePage; + private static DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss:SSS"); public void init() throws ServletException { try { @@ -131,7 +134,22 @@ public class StatViewServlet extends HttpServlet { content.append("
"); content.append("

API:com.alibaba.druid.sql.SQLUtils.format(sql,DBType);

"); content.append("
"); - + + if (sqlStat.getLastSlowParameters() != null && sqlStat.getLastSlowParameters().trim().length() > 0) { + content.append("

LastSlow SQL View:

"); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append(""); + content.append("
MaxTimespanOccurTime" + format.format(sqlStat.getExecuteNanoSpanMaxOccurTime()) + "
LastSlowParameters" + sqlStat.getLastSlowParameters() + "
"); + content.append("
"); + } + List statementList = SQLUtils.parseStatements(sqlStat.getSql(), sqlStat.getDbType()); if (!statementList.isEmpty()) { content.append("

Parse View:

"); diff --git a/src/main/resources/support/http/resources/js/sql.js b/src/main/resources/support/http/resources/js/sql.js index 02172ba557..ef769229b8 100644 --- a/src/main/resources/support/http/resources/js/sql.js +++ b/src/main/resources/support/http/resources/js/sql.js @@ -94,6 +94,7 @@ function ajaxResponseForDataSourceSqlStatInfo() { for ( var i = 0; i < sqlStatList.length; i++) { var sqlStat = sqlStatList[i]; var newRow = sqlStatTable.insertRow(-1); + newRow.insertCell(-1).innerHTML = i+1; newRow.insertCell(-1).innerHTML = '' + subSqlString(sqlStat.SQL, 25) + ''; // if (sqlStat.File) // newRow.insertCell(-1).innerHTML = sqlStat.File; @@ -105,7 +106,12 @@ function ajaxResponseForDataSourceSqlStatInfo() { // newRow.insertCell(-1).innerHTML = ''; newRow.insertCell(-1).innerHTML = sqlStat.ExecuteCount; newRow.insertCell(-1).innerHTML = sqlStat.TotalTime; - newRow.insertCell(-1).innerHTML = sqlStat.MaxTimespan; + //显示执行的时间比配置的均值时间慢的SQL链接 + var lastSlowHtml = sqlStat.MaxTimespan; + if(sqlStat.LastSlowParameters!=null&&sqlStat.LastSlowParameters.length>0){ + lastSlowHtml =''+sqlStat.MaxTimespan+''; + } + newRow.insertCell(-1).innerHTML = lastSlowHtml; newRow.insertCell(-1).innerHTML = sqlStat.InTransactionCount; newRow.insertCell(-1).innerHTML = sqlStat.ErrorCount; newRow.insertCell(-1).innerHTML = sqlStat.EffectedRowCount; @@ -120,8 +126,8 @@ function ajaxResponseForDataSourceSqlStatInfo() { // hiHtml += 'ExecAndRsHold'; newRow.insertCell(-1).innerHTML = '[' + sqlStat.Histogram + ']'; + newRow.insertCell(-1).innerHTML = '[' + sqlStat.ExecuteAndResultHoldTimeHistogram + ']'; newRow.insertCell(-1).innerHTML = '[' + sqlStat.FetchRowCountHistogram + ']'; newRow.insertCell(-1).innerHTML = '[' + sqlStat.EffectedRowCountHistogram + ']'; - newRow.insertCell(-1).innerHTML = '[' + sqlStat.ExecuteAndResultHoldTimeHistogram + ']'; } } \ No newline at end of file diff --git a/src/main/resources/support/http/resources/sql.html b/src/main/resources/support/http/resources/sql.html index a2515003be..480de266ce 100644 --- a/src/main/resources/support/http/resources/sql.html +++ b/src/main/resources/support/http/resources/sql.html @@ -24,6 +24,7 @@ + @@ -44,6 +45,16 @@ -- ] + - +
N-- SQL Execute Count Execute Millis Total ExecAndRsHold
[ + - + - + - + - + - + - + - + - ] +
FetchRow
[ - - @@ -60,16 +71,7 @@ - - ]
ExecAndRsHold
[ - - - - - - - - - - - - - - - - ] -