Search in sources :

Example 6 with JmxControlException

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);
            }
        }
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) ManagedBeanInfo(com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 7 with JmxControlException

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, " ", "&nbsp;");
        // 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);
}
Also used : CubaScrollBoxLayout(com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) Level(ch.qos.logback.classic.Level) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) IOException(java.io.IOException)

Example 8 with JmxControlException

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");
}
Also used : LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) LookupAction(com.haulmont.cuba.gui.components.PickerField.LookupAction) Security(com.haulmont.cuba.core.global.Security) ComboBox(com.vaadin.ui.ComboBox) LoggerFactory(org.slf4j.LoggerFactory) ParamsMap(com.haulmont.bali.util.ParamsMap) Settings(com.haulmont.cuba.gui.settings.Settings) Timer(com.haulmont.cuba.gui.components.Timer) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) LogArchiver(com.haulmont.cuba.core.sys.logging.LogArchiver) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) Logger(org.slf4j.Logger) LoggingHelper(com.haulmont.cuba.core.sys.logging.LoggingHelper) LogDataProvider(com.haulmont.cuba.web.export.LogDataProvider) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) IOException(java.io.IOException) JmxRemoteLoggingAPI(com.haulmont.cuba.web.jmx.JmxRemoteLoggingAPI) CubaScrollBoxLayout(com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Level(ch.qos.logback.classic.Level) ModifierKey(com.vaadin.event.ShortcutAction.ModifierKey) StringReader(java.io.StringReader) AppConfig(com.haulmont.cuba.gui.AppConfig) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) ShortcutListener(com.vaadin.event.ShortcutListener) LogControlException(com.haulmont.cuba.core.sys.logging.LogControlException) BufferedReader(java.io.BufferedReader) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ComboBox(com.vaadin.ui.ComboBox) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) ShortcutListener(com.vaadin.event.ShortcutListener) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 9 with JmxControlException

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);
    }
}
Also used : ReflectionException(javax.management.ReflectionException) ManagedBeanAttribute(com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute) CompositeData(javax.management.openmbean.CompositeData) InstanceNotFoundException(javax.management.InstanceNotFoundException) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException)

Example 10 with JmxControlException

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);
}
Also used : JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) ParamsMap(com.haulmont.bali.util.ParamsMap) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) UUID(java.util.UUID) MetaClass(com.haulmont.chile.core.model.MetaClass) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance) Metadata(com.haulmont.cuba.core.global.Metadata) Inject(javax.inject.Inject) JmxControlAPI(com.haulmont.cuba.web.jmx.JmxControlAPI) GroupDatasource(com.haulmont.cuba.gui.data.GroupDatasource) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) Map(java.util.Map) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) OpenType(com.haulmont.cuba.gui.WindowManager.OpenType) JmxInstanceEditor(com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) JmxControlException(com.haulmont.cuba.web.jmx.JmxControlException) JmxInstance(com.haulmont.cuba.core.entity.JmxInstance)

Aggregations

JmxControlException (com.haulmont.cuba.web.jmx.JmxControlException)10 Level (ch.qos.logback.classic.Level)6 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)6 ParamsMap (com.haulmont.bali.util.ParamsMap)4 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)3 Metadata (com.haulmont.cuba.core.global.Metadata)3 OpenType (com.haulmont.cuba.gui.WindowManager.OpenType)3 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)3 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)3 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)3 JmxInstanceEditor (com.haulmont.cuba.web.app.ui.jmxinstance.edit.JmxInstanceEditor)3 JmxControlAPI (com.haulmont.cuba.web.jmx.JmxControlAPI)3 Inject (javax.inject.Inject)3 ManagedBeanAttribute (com.haulmont.cuba.web.jmx.entity.ManagedBeanAttribute)2 ManagedBeanInfo (com.haulmont.cuba.web.jmx.entity.ManagedBeanInfo)2 CubaScrollBoxLayout (com.haulmont.cuba.web.toolkit.ui.CubaScrollBoxLayout)2 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 Map (java.util.Map)2