Search in sources :

Example 1 with StatsProviderRegistryElement

use of org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement in project Payara by payara.

the class StatsProviderManagerDelegateImpl method setHandlesForStatsProviders.

public void setHandlesForStatsProviders(Object statsProvider, Collection<ProbeClientMethodHandle> handles) {
    // save the handles also against statsProvider so you can unregister when statsProvider is unregistered
    StatsProviderRegistryElement spre = this.statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
    spre.setHandles(handles);
}
Also used : StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)

Example 2 with StatsProviderRegistryElement

use of org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement in project Payara by payara.

the class StatsProviderManagerDelegateImpl method updateAllStatsProviders.

/**
 * called from SPMD, when monitoring-enabled flag is turned on
 */
public void updateAllStatsProviders() {
    // Looks like the monitoring-enabled flag is just turned ON. Lets do the catchup
    for (String configElement : statsProviderRegistry.getConfigElementList()) {
        Collection<StatsProviderRegistryElement> spreList = statsProviderRegistry.getStatsProviderRegistryElement(configElement);
        boolean isConfigEnabled = getEnabledValue(configElement);
        // Continue with the next configElement if this is not enabled
        if (!isConfigEnabled) {
            continue;
        }
        for (StatsProviderRegistryElement spre : spreList) {
            // Assuming the spre's are disabled to start with
            boolean isEnableAllowed = spre.isEnableAllowed(getMonitoringLevel(configElement));
            if (isEnableAllowed) {
                enableStatsProvider(spre);
            }
        }
    }
}
Also used : StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)

Example 3 with StatsProviderRegistryElement

use of org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement in project Payara by payara.

the class StatsProviderManagerDelegateImpl method tryToRegister.

/**
 * throws RuntimeException maybe
 * note the default visibility so that MonitoringBootstrap can call it.
 */
void tryToRegister(StatsProviderInfo spInfo) {
    final String configElement = spInfo.getConfigElement();
    Object statsProvider = spInfo.getStatsProvider();
    // register the statsProvider
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine("registering a statsProvider");
    }
    StatsProviderRegistryElement spre;
    // If configElement is null, create it
    if (monitoringService != null && monitoringService.getContainerMonitoring(configElement) == null && monitoringService.getMonitoringLevel(configElement) == null) {
        createConfigElement(configElement);
    }
    // First check if the configElement associated for statsProvider is 'ON'
    if (getMonitoringEnabled() && getEnabledValue(configElement)) {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine(" enabled is true ");
        }
        spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
        if (spre == null) {
            statsProviderRegistry.registerStatsProvider(spInfo);
            spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
        }
        // Enable the StatsProvider if the enable is allowed
        if (spre.isEnableAllowed(getMonitoringLevel(configElement))) {
            enableStatsProvider(spre);
        }
    } else {
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine(" enabled is false ");
        }
        // Register with null values so to know that we need to register them individually and config is on
        statsProviderRegistry.registerStatsProvider(spInfo);
        spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
    }
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine(spre.toString());
        LOGGER.fine("=========================================================");
    }
}
Also used : StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)

Example 4 with StatsProviderRegistryElement

use of org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement in project Payara by payara.

the class StatsProviderManagerDelegateImpl method unregister.

@Override
public void unregister(Object statsProvider) {
    // Unregisters the statsProvider
    try {
        StatsProviderRegistryElement spre = statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
        if (spre == null) {
            LOGGER.log(Level.INFO, invalidStatsProvider, new Object[] { statsProvider.getClass().getName() });
            return;
        }
        // get the Parent node and delete all children nodes (only that we know of)
        String parentNodePath = spre.getParentTreeNodePath();
        List<String> childNodeNames = spre.getChildTreeNodeNames();
        TreeNode rootNode = mrdr.get(instanceName);
        if ((rootNode != null) && (parentNodePath != null)) {
            // This has to return one node
            List<TreeNode> nodeList = rootNode.getNodes(parentNodePath, false, true);
            if (!nodeList.isEmpty()) {
                TreeNode parentNode = nodeList.get(0);
                // Remove each of the child nodes
                Collection<TreeNode> childNodes = parentNode.getChildNodes();
                for (TreeNode childNode : childNodes) {
                    if (childNodeNames.contains(childNode.getName())) {
                        parentNode.removeChild(childNode);
                    }
                }
                if (!parentNode.hasChildNodes()) {
                    removeParentNode(parentNode);
                }
            }
        }
        // get the handles and unregister the listeners from Flashlight
        Collection<ProbeClientMethodHandle> handles = spre.getHandles();
        if (handles != null) {
            for (ProbeClientMethodHandle handle : handles) {
                // handle.remove????? Mahesh?
                // TODO IMPLEMENTATION
                // For now disable the handle => remove the client from invokerlist
                handle.disable();
            }
        }
        // unregister the statsProvider from Gmbal
        if (spre.getManagedObjectManager() != null) {
            unregisterGmbal(spre);
        }
        // Unregister from the MonitoringDataTreeRegistry and the map entries
        statsProviderRegistry.unregisterStatsProvider(statsProvider);
    } catch (Exception ex) {
        String msg = MessageFormat.format(errorUnregisteringStatsProvider, statsProvider.getClass().getName());
        LOGGER.log(Level.SEVERE, msg, ex);
    }
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode) StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement) ProbeClientMethodHandle(org.glassfish.flashlight.client.ProbeClientMethodHandle) PropertyVetoException(java.beans.PropertyVetoException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with StatsProviderRegistryElement

use of org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement in project Payara by payara.

the class StatsProviderManagerDelegateImpl method createTreeForStatsProvider.

private List<String> createTreeForStatsProvider(TreeNode parentNode, Object statsProvider) {
    /* construct monitoring tree at PluginPoint using subTreePath */
    List<String> childNodeNames = new ArrayList<>();
    /* Check for custom reset method and store for later to be called instead of
         standard reset methods on Statistic classes*/
    for (Method m : statsProvider.getClass().getMethods()) {
        ManagedAttribute ma = m.getAnnotation(ManagedAttribute.class);
        Reset resetMeth = m.getAnnotation(Reset.class);
        if (resetMeth != null) {
            StatsProviderRegistryElement spre = this.statsProviderRegistry.getStatsProviderRegistryElement(statsProvider);
            spre.setResetMethod(m);
        }
        if (ma != null) {
            String methodName = m.getName();
            String id = ma.id();
            if (id.isEmpty()) {
                // if id not specified, derive from method name
                String methodNameLower = methodName.toLowerCase(Locale.ENGLISH);
                if (methodNameLower.startsWith("get") && methodNameLower.length() > 3) {
                    id = methodNameLower.substring(3);
                }
            }
            TreeNode attrNode = TreeNodeFactory.createMethodInvoker(id, statsProvider, id, m);
            parentNode.addChild(attrNode);
            childNodeNames.add(attrNode.getName());
        }
    }
    return childNodeNames;
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode) Method(java.lang.reflect.Method) Reset(org.glassfish.external.statistics.annotations.Reset) StatsProviderRegistryElement(org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement) ManagedAttribute(org.glassfish.gmbal.ManagedAttribute)

Aggregations

StatsProviderRegistryElement (org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)8 ProbeClientMethodHandle (org.glassfish.flashlight.client.ProbeClientMethodHandle)2 TreeNode (org.glassfish.flashlight.datatree.TreeNode)2 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 Reset (org.glassfish.external.statistics.annotations.Reset)1 ManagedAttribute (org.glassfish.gmbal.ManagedAttribute)1 ManagedObjectManager (org.glassfish.gmbal.ManagedObjectManager)1