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);
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations