use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.
the class ManagedBeanAttributeDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
data.clear();
Datasource mbeanDs = getDsContext().get("mbeanDs");
ManagedBeanInfo mbean = (ManagedBeanInfo) mbeanDs.getItem();
if (mbean != null) {
try {
jmxControlAPI.loadAttributes(mbean);
} catch (JmxControlException e) {
log.error("Error loading attributes", e);
}
if (mbean.getAttributes() != null) {
for (ManagedBeanAttribute attr : mbean.getAttributes()) {
data.put(attr.getId(), attr);
}
}
}
}
use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.
the class ServerLogWindow method updateLogTail.
public void updateLogTail(boolean isTimedEvent) {
if (logFileNameField.getValue() != null) {
String logFileName = logFileNameField.getValue();
String value;
try {
value = jmxRemoteLoggingAPI.getTail(getSelectedConnection(), logFileName);
} catch (LogControlException | JmxControlException e) {
log.error("Error loading log tail", e);
if (!isTimedEvent)
showNotification(getMessage("exception.logControl"), NotificationType.ERROR);
return;
}
// transform to XHTML
value = StringEscapeUtils.escapeHtml(value);
value = StringUtils.replace(value, " ", " ");
// highlight log
StringBuilder coloredLog = new StringBuilder();
BufferedReader reader = new BufferedReader(new StringReader(value));
try {
List<String> logLevels = new LinkedList<>();
// highlight tomcat catalina levels
logLevels.add("WARNING");
logLevels.add("SEVERE");
// highlight log4j levels
for (Level level : LoggingHelper.getLevels()) {
logLevels.add(level.toString());
}
String line;
while ((line = reader.readLine()) != null) {
// replace one level per line
for (String level : logLevels) {
String highlightedLine = highlightLevel(line, level);
if (!Objects.equals(highlightedLine, line)) {
line = highlightedLine;
break;
}
}
coloredLog.append(line).append("<br/>");
}
} catch (IOException e) {
log.warn("Error updating log tail", e);
return;
}
logTailLabel.setValue(coloredLog.toString());
} else {
showNotification(getMessage("log.notSelected"), NotificationType.HUMANIZED);
}
logContainer.unwrap(CubaScrollBoxLayout.class).setScrollTop(30000);
}
use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.
the class ServerLogWindow method init.
@Override
public void init(Map<String, Object> params) {
localJmxField.setValue(jmxControlAPI.getLocalNodeName());
localJmxField.setEditable(false);
localJmxInstance = jmxControlAPI.getLocalInstance();
jmxInstancesDs.refresh();
jmxConnectionField.setValue(localJmxInstance);
jmxConnectionField.setRequired(true);
jmxConnectionField.addValueChangeListener(e -> {
JmxInstance jmxInstance = (JmxInstance) e.getValue();
try {
refreshHostInfo();
} catch (JmxControlException ex) {
showNotification(getMessage("exception.unableToConnectToInterface"), NotificationType.WARNING);
if (jmxInstance != localJmxInstance) {
jmxConnectionField.setValue(localJmxInstance);
}
}
});
autoRefreshCheck.addValueChangeListener(e -> {
if (Boolean.TRUE.equals(e.getValue())) {
updateLogTailTimer.start();
} else {
updateLogTailTimer.stop();
}
});
jmxConnectionField.removeAllActions();
LookupAction action = LookupAction.create(jmxConnectionField);
action.setAfterLookupCloseHandler((window, actionId) -> {
jmxInstancesDs.refresh();
});
jmxConnectionField.addAction(action);
jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
instanceEditor.addCloseListener(actionId -> {
if (COMMIT_ACTION_ID.equals(actionId)) {
jmxInstancesDs.refresh();
jmxConnectionField.setValue(instanceEditor.getItem());
}
});
}));
logTailLabel.setSizeAuto();
logTailLabel.setHtmlEnabled(true);
logTailLabel.setStyleName("c-log-content");
loggerLevelField.setOptionsList(LoggingHelper.getLevels());
appenderLevelField.setOptionsList(LoggingHelper.getLevels());
refreshHostInfo();
loggerNameField.addValueChangeListener(e -> {
List<String> currentLoggers = new ArrayList<>(jmxRemoteLoggingAPI.getLoggerNames(getSelectedConnection()));
Collections.sort(currentLoggers);
currentLoggers.add(0, getMessage("logger.new"));
if (e.getValue() != null && e.getValue().equals(currentLoggers.get(0))) {
openAddLoggerDialog();
}
});
downloadButton.setEnabled(security.isSpecificPermitted("cuba.gui.administration.downloadlogs"));
ComboBox comboBox = logFileNameField.unwrap(ComboBox.class);
comboBox.addShortcutListener(new ShortcutListener("", KeyCode.D, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {
@Override
public void handleAction(Object sender, Object target) {
downloadLog();
}
});
comboBox.addShortcutListener(new ShortcutListener("", KeyCode.S, new int[] { ModifierKey.CTRL, ModifierKey.SHIFT }) {
@Override
public void handleAction(Object sender, Object target) {
showLogTail();
}
});
downloadButton.setDescription("CTRL-SHIFT-D");
showTailButton.setDescription("CTRL-SHIFT-S");
}
use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.
the class StatisticsDatasource method loadCurrentValues.
protected void loadCurrentValues() {
refreshCount++;
for (PerformanceParameter parameter : getItems()) {
parameter.setRefreshCount(refreshCount);
}
try {
ManagedBeanAttribute uptimeAttr = findAttribute("java.lang:type=Runtime", "Uptime");
if (uptimeAttr != null) {
getParameter("Uptime").setCurrentLong((Long) uptimeAttr.getValue());
}
ManagedBeanAttribute startTimeAttr = findAttribute("java.lang:type=Runtime", "StartTime");
if (startTimeAttr != null) {
getParameter("Start Time").setCurrentLong((Long) startTimeAttr.getValue());
}
ManagedBeanAttribute heapUsage = findAttribute("java.lang:type=Memory", "HeapMemoryUsage");
if (heapUsage != null) {
CompositeData heapData = (CompositeData) heapUsage.getValue();
PerformanceParameter parameter = getParameter("Heap Memory Usage");
parameter.setCurrentLong((Long) heapData.get("used"));
String max = kilobyteFormatter.format(((Long) heapData.get("max")).doubleValue());
parameter.setDisplayName(parameter.getParameterName() + " (Max = " + max + ")");
}
setAverageParameter("Heap Memory Usage", "AvgHeapMemoryUsage", true);
ManagedBeanAttribute nonHeapUsage = findAttribute("java.lang:type=Memory", "NonHeapMemoryUsage");
if (nonHeapUsage != null) {
CompositeData nonHeapData = (CompositeData) nonHeapUsage.getValue();
PerformanceParameter parameter = getParameter("Non-Heap Memory Usage");
parameter.setCurrentLong((Long) nonHeapData.get("used"));
String max = kilobyteFormatter.format(((Long) nonHeapData.get("max")).doubleValue());
parameter.setDisplayName(parameter.getParameterName() + " (Max = " + max + ")");
}
setAverageParameter("Non-Heap Memory Usage", "AvgNonHeapMemoryUsage", true);
ManagedBeanAttribute attr = findAttribute("java.lang:type=OperatingSystem", "FreePhysicalMemorySize");
if (attr != null) {
PerformanceParameter param = getParameter("Free Physical Memory Size");
param.setCurrentLong((Long) attr.getValue());
attr = findAttribute("java.lang:type=OperatingSystem", "TotalPhysicalMemorySize");
if (attr != null) {
String max = kilobyteFormatter.format(((Long) attr.getValue()).doubleValue());
param.setDisplayName(param.getParameterName() + " (Total = " + max + ")");
}
}
attr = findAttribute("java.lang:type=OperatingSystem", "FreeSwapSpaceSize");
if (attr != null) {
PerformanceParameter param = getParameter("Free Swap Space Size");
param.setCurrentLong((Long) attr.getValue());
attr = findAttribute("java.lang:type=OperatingSystem", "TotalSwapSpaceSize");
if (attr != null) {
String max = kilobyteFormatter.format(((Long) attr.getValue()).doubleValue());
param.setDisplayName(param.getParameterName() + " (Total = " + max + ")");
}
}
setAverageParameter("Free Physical Memory Size", "AvgFreePhysicalMemorySize", true);
setAverageParameter("Free Swap Space Size", "AvgFreeSwapSpaceSize", true);
setParameters("java.lang:type=OperatingSystem", new String[] { "SystemCpuLoad", "ProcessCpuLoad" }, new String[] { "System CPU Load", "Process CPU Load" });
setAverageParameter("System CPU Load", "AvgSystemCpuLoad", true);
setAverageParameter("Process CPU Load", "AvgProcessCpuLoad", true);
attr = findAttribute(coreAppName + ".cuba:type=StatisticsCounter", "DbConnectionPoolNumActive");
if (attr != null) {
PerformanceParameter param = getParameter("Active Connections");
param.setCurrent(((Integer) attr.getValue()).doubleValue());
attr = findAttribute(coreAppName + ".cuba:type=StatisticsCounter", "DbConnectionPoolMaxTotal");
if (attr != null) {
String max = integerFormatter.format(((Integer) attr.getValue()).doubleValue());
param.setDisplayName(param.getParameterName() + " (Max = " + max + ")");
}
}
setParameters(coreAppName + ".cuba:type=StatisticsCounter", new String[] { "DbConnectionPoolNumIdle" }, new String[] { "Idle Connections" });
setAverageParameter("Active Connections", "AvgDbConnectionPoolNumActive", true);
setAverageParameter("Idle Connections", "AvgDbConnectionPoolNumIdle", true);
setParameters(coreAppName + ".cuba:type=StatisticsCounter", new String[] { "ActiveTransactionsCount" }, new String[] { "Active Transactions" });
setAverageParameter("Active Transactions", "AvgActiveTransactions", true);
setTxPerSecParameter();
setAverageParameter("Transactions per Second", "TransactionsPerSecond", true);
attr = findAttribute("java.lang:type=Threading", "ThreadCount");
if (attr != null) {
PerformanceParameter param = getParameter("Thread Count");
param.setCurrent(((Integer) attr.getValue()).doubleValue());
attr = findAttribute("java.lang:type=Threading", "PeakThreadCount");
if (attr != null) {
String max = integerFormatter.format(((Integer) attr.getValue()).doubleValue());
param.setDisplayName(param.getParameterName() + " (Peak = " + max + ")");
}
}
setAverageParameter("Thread Count", "AvgThreadCount", true);
setParameters(coreAppName + ".cuba:type=UserSessions", new String[] { "Count" }, new String[] { "User Sessions" });
setAverageParameter("User Sessions", "AvgUserSessions", true);
setWebRequestsPerSecParameter();
setAverageParameter("Web Requests per Second", "WebRequestsPerSecond", false);
setMiddlewareRequestsPerSecParameter();
setAverageParameter("Middleware Requests per Second", "MiddlewareRequestsPerSecond", true);
setCubaScheduledTasksPerSecParameter();
setAverageParameter("CUBA Scheduled Tasks per Second", "CubaScheduledTasksPerSecond", true);
setMiddlewareSpringScheduledTasksPerSecParameter();
setAverageParameter("Middleware Spring Scheduled Tasks per Second", "SpringScheduledTasksPerSecond", true);
setWebSpringScheduledTasksPerSecParameter();
setAverageParameter("Web Spring Scheduled Tasks per Second", "SpringScheduledTasksPerSecond", false);
} catch (InstanceNotFoundException | ReflectionException e) {
throw new JmxControlException(e);
}
}
use of com.haulmont.cuba.web.jmx.JmxControlException in project cuba by cuba-platform.
the class StatisticsWindow method initJMXTable.
protected void initJMXTable() {
localJmxInstance = jmxControlAPI.getLocalInstance();
jmxInstancesDs.refresh();
jmxConnectionField.setValue(localJmxInstance);
jmxConnectionField.setRequired(true);
jmxConnectionField.addValueChangeListener(e -> {
try {
setNode(jmxConnectionField.getValue());
} catch (JmxControlException ex) {
JmxInstance jmxInstance = jmxConnectionField.getValue();
showNotification(messages.getMessage("com.haulmont.cuba.web.app.ui.jmxcontrol", "unableToConnectToInterface"), NotificationType.WARNING);
if (jmxInstance != localJmxInstance) {
jmxConnectionField.setValue(localJmxInstance);
}
}
});
jmxConnectionField.removeAllActions();
jmxConnectionField.addAction(new PickerField.LookupAction(jmxConnectionField) {
@Override
public void afterCloseLookup(String actionId) {
jmxInstancesDs.refresh();
}
});
jmxConnectionField.addAction(new BaseAction("actions.Add").withIcon("icons/plus-btn.png").withHandler(event -> {
JmxInstanceEditor instanceEditor = (JmxInstanceEditor) openEditor(metadata.create(JmxInstance.class), OpenType.DIALOG);
instanceEditor.addCloseWithCommitListener(() -> {
jmxInstancesDs.refresh();
jmxConnectionField.setValue(instanceEditor.getItem());
});
}));
localNodeLab.setValue(jmxControlAPI.getLocalNodeName());
localNodeLab.setEditable(false);
}
Aggregations