Search in sources :

Example 1 with AMXConfiguration

use of fish.payara.admin.amx.config.AMXConfiguration in project Payara by payara.

the class GetMonitoringConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    ActionReport monitoringServiceReport = actionReport.addSubActionsReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        actionReport.setMessage("No such config named: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    MonitoringService monitoringService = config.getMonitoringService();
    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
    CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("get-rest-monitoring-configuration", actionReport, context.getSubject());
    commandInvocation.execute();
    commandInvocation = commandRunner.getCommandInvocation("get-jmx-monitoring-configuration", actionReport, context.getSubject());
    commandInvocation.execute();
    final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
    extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
    extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
    extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
    Properties extraProperties = new Properties();
    extraProperties.put("getMonitoringConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
    monitoringServiceReport.setMessage(columnFormatter.toString());
    monitoringServiceReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) CommandRunner(org.glassfish.api.admin.CommandRunner) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 2 with AMXConfiguration

use of fish.payara.admin.amx.config.AMXConfiguration in project Payara by payara.

the class GetMonitoringServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    MonitoringService monitoringService = config.getMonitoringService();
    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
    final ActionReport actionReport = context.getActionReport();
    final String[] headers = { "Monitoring Enabled", "AMX Enabled", "MBeans Enabled", "DTrace Enabled" };
    ColumnFormatter columnFormatter = new ColumnFormatter(headers);
    columnFormatter.addRow(new Object[] { monitoringService.getMonitoringEnabled(), amxConfiguration.getEnabled(), monitoringService.getMbeanEnabled(), monitoringService.getDtraceEnabled() });
    actionReport.appendMessage(columnFormatter.toString());
    Map<String, Object> extraPropertiesMap = new HashMap<>();
    extraPropertiesMap.put("monitoringEnabled", monitoringService.getMonitoringEnabled());
    extraPropertiesMap.put("amxEnabled", amxConfiguration.getEnabled());
    extraPropertiesMap.put("mbeanEnabled", monitoringService.getMbeanEnabled());
    extraPropertiesMap.put("dtraceEnabled", monitoringService.getDtraceEnabled());
    Properties extraProperties = new Properties();
    extraProperties.put("getMonitoringServiceConfiguration", extraPropertiesMap);
    actionReport.setExtraProperties(extraProperties);
    actionReport.setMessage(columnFormatter.toString());
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) HashMap(java.util.HashMap) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter)

Example 3 with AMXConfiguration

use of fish.payara.admin.amx.config.AMXConfiguration in project Payara by payara.

the class SetMonitoringServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    config = targetUtil.getConfig(target);
    if (config != null) {
        monitoringService = config.getMonitoringService();
    } else {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

            @Override
            public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                if (monitoringEnabled != null) {
                    monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled));
                }
                if (mbeanEnabled != null) {
                    monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled));
                }
                if (dtraceEnabled != null) {
                    monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled));
                }
                if (amxEnabled != null) {
                    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
                    ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {

                        @Override
                        public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                            amxConfigurationProxy.setEnabled((String.valueOf(amxEnabled)));
                            return amxConfigurationProxy;
                        }
                    }, amxConfiguration);
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringServiceProxy;
            }
        }, monitoringService);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Failed to execute the command set-monitoring-service-configuration: {0}", ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Example 4 with AMXConfiguration

use of fish.payara.admin.amx.config.AMXConfiguration in project Payara by payara.

the class SetAmxEnabled method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config targetConfig = targetUtil.getConfig(target);
    AMXConfiguration metricsConfiguration = targetConfig.getExtensionByType(AMXConfiguration.class);
    try {
        ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {

            @Override
            public Object run(final AMXConfiguration configProxy) throws PropertyVetoException, TransactionFailure {
                configProxy.setEnabled(enabled.toString());
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return configProxy;
            }
        }, metricsConfiguration);
        AMXBootService bootService = habitat.getService(AMXBootService.class);
        bootService.setEnabled(enabled, dynamic);
    } catch (TransactionFailure ex) {
        LOGGER.log(Level.WARNING, "Exception during command set-amx-enabled: {0}", ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) AMXBootService(fish.payara.admin.amx.AMXBootService)

Example 5 with AMXConfiguration

use of fish.payara.admin.amx.config.AMXConfiguration in project Payara by payara.

the class JMXMonitoringService method bootstrapMonitoringService.

/**
 * Bootstraps the monitoring service.
 * Schedules the AMXBoot class to execute if AMX
 * is enabled. Schedules the JMXMonitoringFormatter to execute at a
 * specified fixed rate if enabled in the configuration.
 */
public void bootstrapMonitoringService() {
    if (configuration != null && configuration.getEnabled().equalsIgnoreCase("true")) {
        // To make sure that there aren't multiple monitoring services running
        shutdownMonitoringService();
        final MBeanServer server = getPlatformMBeanServer();
        formatter = new JMXMonitoringFormatter(server, buildJobs(), this, notificationEventBus, notificationFactory, enabledNotifiers);
        Logger.getLogger(JMXMonitoringService.class.getName()).log(Level.INFO, "JMX Monitoring Service will startup");
        if (Boolean.valueOf(configuration.getAmx())) {
            AMXConfiguration amxConfig = habitat.getService(AMXConfiguration.class);
            try {
                amxConfig.setEnabled(String.valueOf(configuration.getAmx()));
                configuration.setAmx(null);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(JMXMonitoringService.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        monitoringFuture = executor.scheduleAtFixedRate(formatter, monitoringDelay * 1000, TimeUnit.MILLISECONDS.convert(Long.valueOf(configuration.getLogFrequency()), TimeUnit.valueOf(configuration.getLogFrequencyUnit())), TimeUnit.MILLISECONDS);
        bootstrapNotifierList();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer)

Aggregations

AMXConfiguration (fish.payara.admin.amx.config.AMXConfiguration)6 PropertyVetoException (java.beans.PropertyVetoException)4 ActionReport (org.glassfish.api.ActionReport)4 Config (com.sun.enterprise.config.serverbeans.Config)3 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 AMXBootService (fish.payara.admin.amx.AMXBootService)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ManagementFactory.getPlatformMBeanServer (java.lang.management.ManagementFactory.getPlatformMBeanServer)1 MBeanServer (javax.management.MBeanServer)1 CommandRunner (org.glassfish.api.admin.CommandRunner)1 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)1