use of fish.payara.jmx.monitoring.configuration.MonitoredAttribute in project Payara by payara.
the class GetMonitoringConfiguration method execute.
/**
* Method that is invoked when the asadmin command is performed.
* Pretty prints the Monitoring Service Configuration values.
* @param context
*/
@Override
public void execute(AdminCommandContext context) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config name: " + targetUtil);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ActionReport actionReport = context.getActionReport();
ActionReport notifiersReport = actionReport.addSubActionsReport();
ActionReport attributeReport = actionReport.addSubActionsReport();
ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
actionReport.appendMessage(StringUtils.EOL);
Map<String, Object> map = new HashMap<>();
Properties extraProps = new Properties();
map.put("enabled", monitoringConfig.getEnabled());
map.put("amx", monitoringConfig.getAmx());
map.put("logfrequency", monitoringConfig.getLogFrequency());
map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
extraProps.put("jmxmonitoringConfiguration", map);
List<Map<String, String>> monitoredAttributes = new ArrayList<>();
for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
Object[] values = new Object[3];
values[0] = monitoredBean.getObjectName();
values[1] = monitoredBean.getAttributeName();
values[2] = monitoredBean.getDescription();
Map<String, String> monitoredAttribute = new HashMap<>();
monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
monitoredAttributes.add(monitoredAttribute);
attributeColumnFormatter.addRow(values);
}
// Cannot change key in line below - required for admingui propertyDescTable.inc
extraProps.put("monitored-beans", monitoredAttributes);
actionReport.setExtraProperties(extraProps);
if (!monitoringConfig.getNotifierList().isEmpty()) {
List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {
@Override
public Class<Notifier> apply(Notifier input) {
return resolveNotifierClass(input);
}
});
Properties notifierProps = new Properties();
for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
if (notifier != null) {
ConfigView view = ConfigSupport.getImpl(notifier);
NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
if (notifierClassList.contains(view.<Notifier>getProxyType())) {
Object[] values = new Object[2];
values[0] = annotation.type();
values[1] = notifier.getEnabled();
notifiersColumnFormatter.addRow(values);
Map<String, Object> mapNotifiers = new HashMap<>(2);
mapNotifiers.put("notifierName", values[0]);
mapNotifiers.put("notifierEnabled", values[1]);
notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
}
}
actionReport.getExtraProperties().putAll(notifierProps);
}
}
notifiersReport.setMessage(notifiersColumnFormatter.toString());
notifiersReport.appendMessage(StringUtils.EOL);
attributeReport.setMessage(attributeColumnFormatter.toString());
attributeReport.appendMessage(StringUtils.EOL);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of fish.payara.jmx.monitoring.configuration.MonitoredAttribute in project Payara by payara.
the class SetMonitoringConfiguration method updateAttributes.
/**
* Updates monitoring attributes through adding a new property and/or deleting an existing one.
*
* @param actionReport
* @param monitoringConfig
* @throws PropertyVetoException
* @throws TransactionFailure
*/
private void updateAttributes(MonitoringServiceConfiguration monitoringConfig, ActionReport report) throws PropertyVetoException, TransactionFailure {
List<MonitoredAttribute> attributes = monitoringConfig.getMonitoredAttributes();
// If there are attributes to be removed
if (attributesToRemove != null && !attributesToRemove.isEmpty()) {
// Loop through them
for (String attributeToRemove : attributesToRemove) {
// Parse the provided attribute
MonitoredAttribute monitoredAttribute = parseToMonitoredAttribute(attributeToRemove, monitoringConfig.createChild(MonitoredAttribute.class));
boolean removed = false;
// Find the attribute matching the one specified
for (MonitoredAttribute attribute : attributes) {
if (attribute.equals(monitoredAttribute)) {
attributes.remove(attribute);
report.appendMessage(monitoringService.getLocalStringManager().getLocalString("jmxmonitoring.configure.attribute.remove", "Attribute 'objectName={0} attributeName={1}' successfully deleted.", monitoredAttribute.getObjectName(), monitoredAttribute.getAttributeName()) + "\n");
removed = true;
break;
}
}
if (!removed) {
report.appendMessage(monitoringService.getLocalStringManager().getLocalString("jmxmonitoring.configure.attribute.remove.error", "Attribute 'objectName={0} attributeName={1}' doesn't exist, so was ignored.", monitoredAttribute.getObjectName(), monitoredAttribute.getAttributeName()) + "\n");
}
}
}
if (attributesToAdd != null && !attributesToAdd.isEmpty()) {
for (String attributeToAdd : attributesToAdd) {
MonitoredAttribute monitoredAttribute = parseToMonitoredAttribute(attributeToAdd, monitoringConfig.createChild(MonitoredAttribute.class));
boolean attributeExists = false;
for (MonitoredAttribute attribute : attributes) {
if (attribute.equals(monitoredAttribute)) {
attributeExists = true;
report.appendMessage(monitoringService.getLocalStringManager().getLocalString("jmxmonitoring.configure.attribute.add.error", "Attribute 'objectName={0} attributeName={1}' already exists, so was ignored.", monitoredAttribute.getObjectName(), monitoredAttribute.getAttributeName()) + "\n");
break;
}
}
if (!attributeExists) {
attributes.add(monitoredAttribute);
report.appendMessage(monitoringService.getLocalStringManager().getLocalString("jmxmonitoring.configure.attribute.add", "Attribute 'objectName={0} attributeName={1}' successfully added.", monitoredAttribute.getObjectName(), monitoredAttribute.getAttributeName()) + "\n");
}
}
}
}
use of fish.payara.jmx.monitoring.configuration.MonitoredAttribute in project Payara by payara.
the class MonitoringService method buildJobs.
/**
* Builds the monitoring jobs from the service configuration.
*
* @return List of built jobs.
*/
private List<MonitoringJob> buildJobs() {
List<MonitoringJob> jobs = new LinkedList<>();
for (MonitoredAttribute mbean : configuration.getMonitoredAttributes()) {
boolean exists = false;
for (MonitoringJob job : jobs) {
if (job.getMBean().getCanonicalKeyPropertyListString().equals(mbean.getObjectName())) {
job.addAttribute(mbean.getAttributeName());
exists = true;
break;
}
}
if (!exists) {
ObjectName name;
List<String> list;
try {
name = new ObjectName(mbean.getObjectName());
list = new LinkedList<>();
list.add(mbean.getAttributeName());
jobs.add(new MonitoringJob(name, list));
} catch (MalformedObjectNameException ex) {
Logger.getLogger(MonitoringService.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return jobs;
}
Aggregations