Search in sources :

Example 1 with MonitoredAttribute

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);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MonitoredAttribute

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");
            }
        }
    }
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute)

Example 3 with MonitoredAttribute

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;
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) MalformedObjectNameException(javax.management.MalformedObjectNameException) LinkedList(java.util.LinkedList) ObjectName(javax.management.ObjectName)

Aggregations

MonitoredAttribute (fish.payara.jmx.monitoring.configuration.MonitoredAttribute)3 Config (com.sun.enterprise.config.serverbeans.Config)1 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)1 MonitoringServiceConfiguration (fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration)1 Notifier (fish.payara.nucleus.notification.configuration.Notifier)1 NotifierConfigurationType (fish.payara.nucleus.notification.configuration.NotifierConfigurationType)1 BaseNotifierService (fish.payara.nucleus.notification.service.BaseNotifierService)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 ActionReport (org.glassfish.api.ActionReport)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 ConfigView (org.jvnet.hk2.config.ConfigView)1