| | |
| | | */ |
| | | package org.opends.server.monitors; |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.TreeMap; |
| | | |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.opends.server.admin.std.server.StackTraceMonitorProviderCfg; |
| | | import org.opends.server.api.MonitorProvider; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.types.*; |
| | | |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeBuilder; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.InitializationException; |
| | | |
| | | /** |
| | | * This class defines a Directory Server monitor provider that can be used to |
| | |
| | | public class StackTraceMonitorProvider |
| | | extends MonitorProvider<StackTraceMonitorProviderCfg> |
| | | { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void initializeMonitorProvider( |
| | | StackTraceMonitorProviderCfg configuration) |
| | | throws ConfigException, InitializationException |
| | |
| | | // No initialization is required. |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the name of this monitor provider. It should be unique among all |
| | | * monitor providers, including all instances of the same monitor provider. |
| | | * |
| | | * @return The name of this monitor provider. |
| | | */ |
| | | @Override |
| | | public String getMonitorInstanceName() |
| | | { |
| | | return "JVM Stack Trace"; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves a set of attributes containing monitor data that should be |
| | | * returned to the client if the corresponding monitor entry is requested. |
| | | * |
| | | * @return A set of attributes containing monitor data that should be |
| | | * returned to the client if the corresponding monitor entry is |
| | | * requested. |
| | | */ |
| | | public ArrayList<Attribute> getMonitorData() |
| | | @Override |
| | | public List<Attribute> getMonitorData() |
| | | { |
| | | Map<Thread,StackTraceElement[]> threadStacks = Thread.getAllStackTraces(); |
| | | |
| | | |
| | | // Re-arrange all of the elements by thread ID so that there is some logical order. |
| | | TreeMap<Long,Map.Entry<Thread,StackTraceElement[]>> orderedStacks = new TreeMap<>(); |
| | | for (Map.Entry<Thread,StackTraceElement[]> e : threadStacks.entrySet()) |
| | |
| | | orderedStacks.put(e.getKey().getId(), e); |
| | | } |
| | | |
| | | |
| | | AttributeType attrType = |
| | | DirectoryServer.getDefaultAttributeType("jvmThread"); |
| | | AttributeBuilder builder = new AttributeBuilder(attrType); |
| | |
| | | StackTraceElement[] stackElements = e.getValue(); |
| | | |
| | | long id = t.getId(); |
| | | |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append("id="); |
| | | buffer.append(id); |
| | | buffer.append(" ---------- "); |
| | | buffer.append(t.getName()); |
| | | buffer.append(" ----------"); |
| | | builder.add(buffer.toString()); |
| | | builder.add("id=" + id + " ---------- " + t.getName() + " ----------"); |
| | | |
| | | // Create an attribute for the stack trace. |
| | | if (stackElements != null) |
| | | { |
| | | for (int j=0; j < stackElements.length; j++) |
| | | { |
| | | buffer = new StringBuilder(); |
| | | StringBuilder buffer = new StringBuilder(); |
| | | buffer.append("id="); |
| | | buffer.append(id); |
| | | buffer.append(" frame["); |