Search in sources :

Example 6 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class StatsProviderManagerDelegateImpl method createSubTreeNode.

private TreeNode createSubTreeNode(TreeNode parent, String child) {
    TreeNode childNode = parent.getChild(child);
    if (childNode == null) {
        childNode = TreeNodeFactory.createTreeNode(child, null, child);
        parent.addChild(childNode);
    } else {
        // the childNode is found, but ensure that its enabled
        enableTreeNode(childNode);
    }
    return childNode;
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode)

Example 7 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class JVMStatsImpl method getFirstTreeNodeAsLong.

// @author bnevins
private long getFirstTreeNodeAsLong(TreeNode parent, String name) {
    List<TreeNode> nodes = parent.getNodes(name);
    if (!nodes.isEmpty()) {
        TreeNode node = nodes.get(0);
        Object val = node.getValue();
        if (val != null) {
            try {
                CountStatistic cs = (CountStatistic) val;
                return cs.getCount();
            } catch (Exception e) {
            // TODO: handle exception
            }
        }
    }
    return 0L;
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode) CountStatistic(org.glassfish.external.statistics.CountStatistic)

Example 8 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class JVMStatsImpl method process.

public ActionReport process(final ActionReport report, final String filter) {
    if (monitoringService != null) {
        String level = monitoringService.getMonitoringLevel("jvm");
        if ((level != null) && (level.equals(ContainerMonitoring.LEVEL_OFF))) {
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setMessage(localStrings.getLocalString("level.off", "Monitoring level for jvm is off"));
            return report;
        }
    }
    if (mrdr == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(localStrings.getLocalString("mrdr.null", "MonitoringRuntimeDataRegistry is null"));
        return report;
    }
    TreeNode serverNode = mrdr.get("server");
    if (serverNode == null) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(localStrings.getLocalString("mrdr.null", "MonitoringRuntimeDataRegistry server node is null"));
        return report;
    }
    if ((filter != null) && (filter.length() > 0)) {
        if ("heapmemory".equals(filter)) {
            return (heapMemory(report, serverNode));
        } else if ("nonheapmemory".equals(filter)) {
            return (nonHeapMemory(report, serverNode));
        }
    } else {
        return (v2JVM(report, serverNode));
    }
    return null;
}
Also used : TreeNode(org.glassfish.flashlight.datatree.TreeNode)

Example 9 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class MonitoringResource method constructEntity.

private void constructEntity(List<TreeNode> nodeList, RestActionReporter ar) {
    Map<String, Object> entity = new TreeMap<String, Object>();
    Map<String, String> links = new TreeMap<String, String>();
    for (TreeNode node : nodeList) {
        // process only the leaf nodes, if any
        if (!node.hasChildNodes()) {
            // getValue() on leaf node will return one of the following -
            // Statistic object, String object or the object for primitive type
            Object value = node.getValue();
            if (value != null) {
                try {
                    if (value instanceof Statistic) {
                        Statistic statisticObject = (Statistic) value;
                        entity.put(node.getName(), getStatistic(statisticObject));
                    } else if (value instanceof Stats) {
                        Map<String, Map> subMap = new TreeMap<String, Map>();
                        for (Statistic statistic : ((Stats) value).getStatistics()) {
                            subMap.put(statistic.getName(), getStatistic(statistic));
                        }
                        entity.put(node.getName(), subMap);
                    } else {
                        entity.put(node.getName(), jsonValue(value));
                    }
                } catch (Exception exception) {
                // log exception message as warning
                }
            }
        } else {
            String name = node.getName();
            // Grizzly will barf if it sees backslash
            name = name.replace("\\.", ".");
            links.put(name, getElementLink(uriInfo, name));
        }
    }
    ar.getExtraProperties().put("entity", entity);
    ar.getExtraProperties().put("childResources", links);
}
Also used : Statistic(org.glassfish.external.statistics.Statistic) TreeNode(org.glassfish.flashlight.datatree.TreeNode) Stats(org.glassfish.external.statistics.Stats) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 10 with TreeNode

use of org.glassfish.flashlight.datatree.TreeNode in project Payara by payara.

the class MonitoringResource method getChildNodes.

@GET
@Path("domain{path:.*}")
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getChildNodes(@PathParam("path") List<PathSegment> pathSegments) {
    Response.ResponseBuilder responseBuilder = Response.status(OK);
    RestActionReporter ar = new RestActionReporter();
    ar.setActionDescription("Monitoring Data");
    ar.setMessage("");
    ar.setSuccess();
    String currentInstanceName = System.getProperty("com.sun.aas.instanceName");
    // TODO this needs to come from an API. Check with admin team
    boolean isRunningOnDAS = "server".equals(currentInstanceName);
    MonitoringRuntimeDataRegistry monitoringRegistry = habitat.getRemoteLocator().getService(MonitoringRuntimeDataRegistry.class);
    TreeNode rootNode = monitoringRegistry.get(currentInstanceName);
    // The pathSegments will always contain "domain". Discard it
    pathSegments = pathSegments.subList(1, pathSegments.size());
    if (!pathSegments.isEmpty()) {
        PathSegment lastSegment = pathSegments.get(pathSegments.size() - 1);
        if (lastSegment.getPath().isEmpty()) {
            // if there is a trailing '/' (like monitoring/domain/), a spurious pathSegment is added. Discard it.
            pathSegments = pathSegments.subList(0, pathSegments.size() - 1);
        }
    }
    if (!pathSegments.isEmpty()) {
        String firstPathElement = pathSegments.get(0).getPath();
        if (firstPathElement.equals(currentInstanceName)) {
            // Query for current instance. Execute it
            // iterate over pathsegments and build a dotted name to look up in monitoring registry
            StringBuilder pathInMonitoringRegistry = new StringBuilder();
            for (PathSegment pathSegment : pathSegments.subList(1, pathSegments.size())) {
                if (pathInMonitoringRegistry.length() > 0) {
                    pathInMonitoringRegistry.append('.');
                }
                // Need to escape '.' before passing it to monitoring code
                pathInMonitoringRegistry.append(pathSegment.getPath().replaceAll("\\.", "\\\\."));
            }
            TreeNode resultNode = pathInMonitoringRegistry.length() > 0 && rootNode != null ? rootNode.getNode(pathInMonitoringRegistry.toString()) : rootNode;
            if (resultNode != null) {
                List<TreeNode> list = new ArrayList<TreeNode>();
                if (resultNode.hasChildNodes()) {
                    list.addAll(resultNode.getEnabledChildNodes());
                } else {
                    list.add(resultNode);
                }
                constructEntity(list, ar);
                responseBuilder.entity(new ActionReportResult(ar));
            } else {
                // No monitoring data, so nothing to list
                responseBuilder.status(NOT_FOUND);
                ar.setFailure();
                responseBuilder.entity(new ActionReportResult(ar));
            }
        } else {
            // firstPathElement != currentInstanceName => A proxy request
            if (isRunningOnDAS) {
                // Attempt to forward to instance if running on Das
                // TODO validate that firstPathElement corresponds to a valid server name
                Properties proxiedResponse = new MonitoringProxyImpl().proxyRequest(uriInfo, Util.getJerseyClient(), habitat.getRemoteLocator());
                ar.setExtraProperties(proxiedResponse);
                responseBuilder.entity(new ActionReportResult(ar));
            } else {
                // Not running on DAS and firstPathElement != currentInstanceName => Reject the request as invalid
                return Response.status(FORBIDDEN).build();
            }
        }
    } else {
        // Called for /monitoring/domain/
        List<TreeNode> list = new ArrayList<TreeNode>();
        if (rootNode != null) {
            // Add currentInstance to response
            list.add(rootNode);
        }
        constructEntity(list, ar);
        if (isRunningOnDAS) {
            // Add links to instances from the cluster
            Domain domain = habitat.getRemoteLocator().getService(Domain.class);
            Map<String, String> links = (Map<String, String>) ar.getExtraProperties().get("childResources");
            for (Server s : domain.getServers().getServer()) {
                if (!s.getName().equals("server")) {
                    // add all non 'server' instances
                    links.put(s.getName(), getElementLink(uriInfo, s.getName()));
                }
            }
        }
        responseBuilder.entity(new ActionReportResult(ar));
    }
    return responseBuilder.build();
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) Server(com.sun.enterprise.config.serverbeans.Server) MonitoringRuntimeDataRegistry(org.glassfish.flashlight.MonitoringRuntimeDataRegistry) ArrayList(java.util.ArrayList) PathSegment(javax.ws.rs.core.PathSegment) Properties(java.util.Properties) Response(javax.ws.rs.core.Response) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) TreeNode(org.glassfish.flashlight.datatree.TreeNode) Domain(com.sun.enterprise.config.serverbeans.Domain) Map(java.util.Map) TreeMap(java.util.TreeMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

TreeNode (org.glassfish.flashlight.datatree.TreeNode)23 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Pattern (java.util.regex.Pattern)2 StatsProviderRegistryElement (org.glassfish.admin.monitor.StatsProviderRegistry.StatsProviderRegistryElement)2 ProbeClientMethodHandle (org.glassfish.flashlight.client.ProbeClientMethodHandle)2 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 PathSegment (javax.ws.rs.core.PathSegment)1