Skip to content

Commit

Permalink
PAYARA-2349 Imporoved data format of SQL tracing data (#2559)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cousjava authored and arjantijms committed Mar 26, 2018
1 parent 21d01f3 commit 37dfaf8
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018] Payara Foundation and/or affiliates

package org.glassfish.admingui.common.handlers;

import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -65,10 +67,95 @@
import org.glassfish.admingui.common.util.RestUtil;

/**
*
* Handlers for processing monitoring in the admin console
* @author Ana
*/
public class MonitoringHandlers {

final private static List<String> levels = new ArrayList();
static {
levels.add("OFF");
levels.add("LOW");
levels.add("HIGH");
}
//monitoring modulemonitoring.module names
public static final String JVM = GuiUtil.getCommonMessage("monitoring.module.Jvm");

public static final String WEB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Web");

public static final String HTTP_SERVICE = GuiUtil.getCommonMessage("monitoring.module.Http");

public static final String THREAD_POOL = GuiUtil.getCommonMessage("monitoring.module.ThreadPool");

public static final String JDBC_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Jdbc");

public static final String CONNECTOR_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Connector");

public static final String EJB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Ejb");

public static final String TRANSACTION_SERVICE = GuiUtil.getCommonMessage("monitoring.module.TransactionService");

public static final String ORB = GuiUtil.getCommonMessage("monitoring.module.Orb");

public static final String CONNECTOR_SERVICE = GuiUtil.getCommonMessage("monitoring.module.ConnectorService");

public static final String JMS_SERVICE = GuiUtil.getCommonMessage("monitoring.module.JmsService");

public static final String WEB_SERVICES_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.WebServices");

public static final String JPA = GuiUtil.getCommonMessage("monitoring.module.Jpa");

public static final String SECURITY = GuiUtil.getCommonMessage("monitoring.module.Security");

public static final String JERSEY = GuiUtil.getCommonMessage("monitoring.module.Jersey");

public static final String DEPLOYMENT = GuiUtil.getCommonMessage("monitoring.module.Deployment");

final private static List monDisplayList = new ArrayList();

static {
monDisplayList.add(JVM);
monDisplayList.add(WEB_CONTAINER);
monDisplayList.add(HTTP_SERVICE);
monDisplayList.add(THREAD_POOL);
monDisplayList.add(JDBC_CONNECTION_POOL);
monDisplayList.add(CONNECTOR_CONNECTION_POOL);
monDisplayList.add(EJB_CONTAINER);
monDisplayList.add(TRANSACTION_SERVICE);
monDisplayList.add(ORB);
monDisplayList.add(CONNECTOR_SERVICE);
monDisplayList.add(JMS_SERVICE);
monDisplayList.add(WEB_SERVICES_CONTAINER);
monDisplayList.add(JPA);
monDisplayList.add(SECURITY);
monDisplayList.add(JERSEY);
monDisplayList.add(DEPLOYMENT);
}
final private static List monNamesList = new ArrayList();

static {
monNamesList.add("jvm");
monNamesList.add("webContainer");
monNamesList.add("httpService");
monNamesList.add("threadPool");
monNamesList.add("jdbcConnectionPool");
monNamesList.add("connectorConnectionPool");
monNamesList.add("ejbContainer");
monNamesList.add("transactionService");
monNamesList.add("orb");
monNamesList.add("connectorService");
monNamesList.add("jmsService");
monNamesList.add("webServicesContainer");
monNamesList.add("jpa");
monNamesList.add("security");
monNamesList.add("jersey");
monNamesList.add("deployment");
}
final private static List containerDispList = new ArrayList();

final private static List containerNameList = new ArrayList();


@Handler(id = "gf.getMonitorLevels",
input = {
@HandlerInput(name = "endpoint", type = String.class, required = true)},
Expand Down Expand Up @@ -114,7 +201,7 @@ public static void getMonitorLevels(HandlerContext handlerCtx) {
handlerCtx.setOutputValue("monitorCompList", result);
}

/*
/**
* This handler returns a list of statistical data for an endpoint.
* Useful for populating table
*/
Expand Down Expand Up @@ -186,26 +273,33 @@ public static void getStats(HandlerContext handlerCtx) {
if (startTime != -1) {
start = df.format(new Date(startTime));
}
if ("List".equals(unit)){
ArrayList<Map> items = (ArrayList) monAttrs.get("items");
val = processListItems(items);
}

if (monAttrs.containsKey("count")) {
val = monAttrs.get("count") + " " + unit;
} else if (monAttrs.containsKey("current")) {
if (unit != null) {
if (unit.equals("String")) {
if (mname.equals("LiveThreads")) {
switch (unit) {
case "String":
if (mname.equals("LiveThreads")) {
String str = (String) monAttrs.get("current");
val = formatStringForDisplay(str);
} else {
val = (String) monAttrs.get("current");
} break;
case "List":
String str = (String) monAttrs.get("current");
val = formatStringForDisplay(str);
} else {
val = (String) monAttrs.get("current");
}
} else if (unit.equals("List")) {
String str = (String) monAttrs.get("current");
String formatStr = formatActiveIdsForDisplay(str);
if (!formatStr.isEmpty() && !formatStr.equals("")) {
val = formatStr;
}
} else {
Long currentVal = ((BigDecimal) monAttrs.get("current")).longValue();
val = currentVal + unit;
String formatStr = formatActiveIdsForDisplay(str);
if (!formatStr.isEmpty() && !formatStr.equals("")) {
val = formatStr;
} break;
default:
Long currentVal = ((BigDecimal) monAttrs.get("current")).longValue();
val = currentVal + " " + unit;
break;
}
}
} else if (monAttrs.containsKey("applicationtype")) {
Expand Down Expand Up @@ -769,88 +863,30 @@ private static Map<String, Object> getMonitoringStatInfo(String endpoint) {
}
return monitorInfoMap;
}
final private static List<String> levels = new ArrayList();

static {
levels.add("OFF");
levels.add("LOW");
levels.add("HIGH");
}
//monitoring modulemonitoring.module names
public static final String JVM = GuiUtil.getCommonMessage("monitoring.module.Jvm");

public static final String WEB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Web");

public static final String HTTP_SERVICE = GuiUtil.getCommonMessage("monitoring.module.Http");

public static final String THREAD_POOL = GuiUtil.getCommonMessage("monitoring.module.ThreadPool");

public static final String JDBC_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Jdbc");

public static final String CONNECTOR_CONNECTION_POOL = GuiUtil.getCommonMessage("monitoring.module.Connector");

public static final String EJB_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.Ejb");

public static final String TRANSACTION_SERVICE = GuiUtil.getCommonMessage("monitoring.module.TransactionService");

public static final String ORB = GuiUtil.getCommonMessage("monitoring.module.Orb");

public static final String CONNECTOR_SERVICE = GuiUtil.getCommonMessage("monitoring.module.ConnectorService");

public static final String JMS_SERVICE = GuiUtil.getCommonMessage("monitoring.module.JmsService");

public static final String WEB_SERVICES_CONTAINER = GuiUtil.getCommonMessage("monitoring.module.WebServices");

public static final String JPA = GuiUtil.getCommonMessage("monitoring.module.Jpa");

public static final String SECURITY = GuiUtil.getCommonMessage("monitoring.module.Security");

public static final String JERSEY = GuiUtil.getCommonMessage("monitoring.module.Jersey");

public static final String DEPLOYMENT = GuiUtil.getCommonMessage("monitoring.module.Deployment");

final private static List monDisplayList = new ArrayList();

static {
monDisplayList.add(JVM);
monDisplayList.add(WEB_CONTAINER);
monDisplayList.add(HTTP_SERVICE);
monDisplayList.add(THREAD_POOL);
monDisplayList.add(JDBC_CONNECTION_POOL);
monDisplayList.add(CONNECTOR_CONNECTION_POOL);
monDisplayList.add(EJB_CONTAINER);
monDisplayList.add(TRANSACTION_SERVICE);
monDisplayList.add(ORB);
monDisplayList.add(CONNECTOR_SERVICE);
monDisplayList.add(JMS_SERVICE);
monDisplayList.add(WEB_SERVICES_CONTAINER);
monDisplayList.add(JPA);
monDisplayList.add(SECURITY);
monDisplayList.add(JERSEY);
monDisplayList.add(DEPLOYMENT);
}
final private static List monNamesList = new ArrayList();

static {
monNamesList.add("jvm");
monNamesList.add("webContainer");
monNamesList.add("httpService");
monNamesList.add("threadPool");
monNamesList.add("jdbcConnectionPool");
monNamesList.add("connectorConnectionPool");
monNamesList.add("ejbContainer");
monNamesList.add("transactionService");
monNamesList.add("orb");
monNamesList.add("connectorService");
monNamesList.add("jmsService");
monNamesList.add("webServicesContainer");
monNamesList.add("jpa");
monNamesList.add("security");
monNamesList.add("jersey");
monNamesList.add("deployment");
/**
* Generates a table from a {@link List} that contains items with a name and count.
* @param items A {@link List} that is the representation of the values held in a {@link org.glassfish.external.statistics.ListStatistic}
* @return A {@link String} holding the HTML for a table containing the relevant data
* @see org.glassfish.external.statistics.ListStatistic#getCurrentStats()
*/
private static String processListItems(List<Map> items) {
if (items == null){
return "";
}
StringBuilder result = new StringBuilder("<table>");
for (Map item: items){
result.append("<tr><td>");
result.append(item.get("name"));
result.append("</td><td>");
result.append(item.get("count"));
result.append(" ");
result.append(item.get("unit"));
result.append("</td></tr>");
}

result.append("</table>");
return result.toString();
}
final private static List containerDispList = new ArrayList();

final private static List containerNameList = new ArrayList();

}
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public static ResourceBundle getBundle (String resourceName) {
return ResourceBundleManager.getInstance().getBundle(resourceName, locale);
}

/*
/**
* returns the strings from org.glassfish.admingui.core.Strings
* if no such key exists, return the key itself.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@
* holder.
*/

// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]

package com.sun.gjc.monitoring;

import com.sun.gjc.util.SQLTrace;
import fish.payara.jdbc.stats.FrequentSQLTraceCache;
import fish.payara.jdbc.stats.SlowSqlTrace;
import fish.payara.jdbc.stats.SlowSqlTraceCache;
import java.util.List;
import org.glassfish.external.probe.provider.annotations.ProbeListener;
import org.glassfish.external.probe.provider.annotations.ProbeParam;
import org.glassfish.external.statistics.CountStatistic;
import org.glassfish.external.statistics.StringStatistic;
import org.glassfish.external.statistics.impl.CountStatisticImpl;
import org.glassfish.external.statistics.ListStatistic;
import org.glassfish.external.statistics.impl.ListStatisticImpl;
import org.glassfish.external.statistics.impl.StatisticImpl;
import org.glassfish.external.statistics.impl.StringStatisticImpl;
import org.glassfish.gmbal.AMXMetadata;
import org.glassfish.gmbal.Description;
import org.glassfish.gmbal.ManagedAttribute;
Expand All @@ -69,11 +70,11 @@
@Description("JDBC RA Statistics")
public class JdbcStatsProvider {

private StringStatisticImpl freqUsedSqlQueries = new StringStatisticImpl(
private ListStatisticImpl freqUsedSqlQueries = new ListStatisticImpl(
"FreqUsedSqlQueries", "List",
"Most frequently used sql queries");

private StringStatisticImpl slowSqlQueries = new StringStatisticImpl("SlowSqlQueries", "List", "Slowest SQL Queries");
private ListStatisticImpl slowSqlQueries = new ListStatisticImpl("SlowSqlQueries", "List", "Slowest SQL Queries");

private CountStatisticImpl numStatementCacheHit = new CountStatisticImpl(
"NumStatementCacheHit", StatisticImpl.UNIT_COUNT,
Expand Down Expand Up @@ -207,20 +208,32 @@ public CountStatistic getNumStatementCacheMiss() {
}

@ManagedAttribute(id="frequsedsqlqueries")
public StringStatistic getfreqUsedSqlQueries() {
if(freqSqlTraceCache != null) {
//This is to ensure that only the queries in the last "time-to-keep-
//queries-in-minutes" is returned back.
freqUsedSqlQueries.setCurrent(freqSqlTraceCache.getTopQueries());
public ListStatistic getfreqUsedSqlQueries() {
List<SQLTrace> sqlTraces = freqSqlTraceCache.getTopQueries();
freqUsedSqlQueries = new ListStatisticImpl("frequsedsqlqueries", "List", "Most frequently used sql queries");

for (SQLTrace trace : sqlTraces){
CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), "Count", "");
stat.setCount(trace.getNumExecutions());
freqUsedSqlQueries.add(stat);
}

return freqUsedSqlQueries;
}

@ManagedAttribute(id = "slowSqlQueries")
public StringStatistic getSlowSqlQueries() {
if (slowSqlTraceCache != null) {
slowSqlQueries.setCurrent(slowSqlTraceCache.getSlowestSqlQueries());
public ListStatistic getSlowSqlQueries() {
//Make sure no data from previous execution is kept
slowSqlQueries.reset();
slowSqlQueries.clear();
//Get slow queries and process them
List<SlowSqlTrace> slowTraces = slowSqlTraceCache.getSlowestSqlQueries();
for (SlowSqlTrace trace: slowTraces){
CountStatisticImpl stat = new CountStatisticImpl(trace.getQueryName(), StatisticImpl.UNIT_MILLISECOND, "Longest execution time");
stat.setCount(trace.getSlowestExecutionTime());
slowSqlQueries.add(stat);
}

return slowSqlQueries;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]

package fish.payara.jdbc.stats;

Expand Down Expand Up @@ -108,18 +108,12 @@ public void checkAndUpdateCache(SQLTrace cacheObj) {
*
* @return string representation of the list of sql queries sorted
*/
public String getTopQueries() {
public List<SQLTrace> getTopQueries() {
purgeEntries();

List<SQLTrace> sqlTraceList = new ArrayList(cache.values());
Collections.sort(sqlTraceList, SQLTrace.SQLTraceFrequencyComparator);

StringBuilder sb = new StringBuilder();
for (SQLTrace sqlTrace : sqlTraceList) {
sb.append(LINE_BREAK);
sb.append(sqlTrace.getQueryName());
sb.append(" executions: ").append(sqlTrace.getNumExecutions());
}
return sb.toString();
return sqlTraceList;
}
}
Loading

0 comments on commit 37dfaf8

Please sign in to comment.