MonitoringInfoCollectorpublic class MonitoringInfoCollector extends InterruptableCollector To collect monitoring information of application server components,
applications deployed, jvm etc., |
Fields Summary |
---|
Set | restrictedProperties | public static final String | DOTTED_NAME_REGISTRY_OPERATION_NAME | public static final String | KEY_NOT_FOUND | public static final String | LIST_COMMAND | public static final String | GET_COMMAND | public static final String | MONITOR_OPTION | private String | instanceName | private String | nodeAgentName | private PrintStream | out | private String | fileName | private String | destFolder | private static Logger | logger |
Constructors Summary |
---|
public MonitoringInfoCollector(String nodeAgentName, String instanceName, String destFolder)Creates a new instance of MonitoringInfoCollector
if (instanceName != null) {
this.instanceName = instanceName;
}
if(nodeAgentName !=null){
this.nodeAgentName = nodeAgentName;
}
this.destFolder = destFolder;
initializeRestrictedPropertiesLookUp();
|
Methods Summary |
---|
public com.sun.enterprise.diagnostics.Data | capture()Capture information
FileData data = null;
if (destFolder != null) {
File destFolderObj = new File(destFolder);
fileName = destFolder + File.separator +
Defaults.MONITORING_INFO_FILE;
if (!destFolderObj.exists()) {
destFolderObj.mkdirs();
}
try {
out = new PrintStream(
new BufferedOutputStream(
new FileOutputStream(fileName)), true);
File reportFile = new File(fileName);
if(this.instanceName.equalsIgnoreCase(Constants.SERVER)) {
data = new FileData( reportFile.getName(), DataType.MONITORING_INFO);
}else{
data = new FileData(nodeAgentName + File.separator + instanceName + File.separator + reportFile.getName(), DataType.MONITORING_INFO);
}
ArrayList<String> cmdOutput = new ArrayList<String>();
MonitoringInfoHelper cmd = new MonitoringInfoHelper();
cmd.setName(LIST_COMMAND);
ArrayList<String> dottedNames = new ArrayList<String>();
if (instanceName != null) {
dottedNames.add(instanceName.trim() + ".*");
cmd.setOperands(dottedNames);
cmd.setOption(MonitoringInfoHelper.SECURE, "true");
cmd.setOption(MONITOR_OPTION, "true");
cmd.runCommand(cmdOutput);
if (checkInterrupted()) {
logger.log(Level.WARNING, "diagnostic-service." +
"monitoring_info_collector_timeout",
new Object[]{Thread.currentThread().getName(),
this.getClass().getName()});
if(out!=null){
out.print("Monitoring Info Collector Timeout");
out.close();
}
return data;
}
ArrayList<String> list = getIndividualProperties(cmdOutput);
MBeanServer mbs = AppServerMBeanServerFactory.
getMBeanServerInstance();
final String[] types = new String[]{String.class.getName()};
for (String value : list) {
if (checkInterrupted()) {
logger.log(Level.WARNING, "diagnostic-service." +
"monitoring_info_collector_timeout",
new Object[]{Thread.currentThread().
getName(), this.getClass().
getName()});
if(out!=null){
out.print("Monitoring Info Collector Timeout");
out.close();
}
return data;
}
Object[] params = new Object[]{value};
ObjectName dottedNameRegistry = (ObjectName) mbs.invoke(
new ObjectName("com.sun.appserv:name=" +
"dotted-name-monitoring-registry," +
"type=dotted-name-support"),
DOTTED_NAME_REGISTRY_OPERATION_NAME, params,
types);
Set set = getAllAttributeNames(mbs, dottedNameRegistry);
Iterator attributesIterator = set.iterator();
ArrayList<String> properties = new ArrayList<String>();
while (attributesIterator.hasNext()) {
String attr = (String) attributesIterator.next();
if (!isRestircted(attr)) {
properties.add(value + "." + attr);
}
}
if (properties.size() > 0) {
cmd.setName(GET_COMMAND);
cmd.setOperands(properties);
ArrayList<String> result = new ArrayList<String>();
cmd.runCommand(result);
for (String attributeValue : result) {
if (!(attributeValue.toLowerCase().
indexOf(KEY_NOT_FOUND) >= 0)) {
out.println(attributeValue);
}
}
}
if (checkInterrupted()) {
logger.log(Level.WARNING, "diagnostic-service." +
"monitoring_info_collector_timeout",
new Object[]{Thread.currentThread().
getName(),
this.getClass().getName()});
if(out!=null){
out.print("Monitoring Info Collector Timeout");
out.close();
}
return data;
}
}
out.close();
}
return data;
}
catch (FileNotFoundException fnfe) {
logger.log(Level.WARNING, "File Not Found exception occurred " +
"while collecting Monitoring information", fnfe);
}
catch (IOException ioe) {
logger.log(Level.WARNING, "IO Exception occurred while " +
"collecting Monitoring information", ioe);
}
catch (Exception e) {
logger.log(Level.WARNING, "Exception occurred while collecting"+
" Monitoring information", e);
}
}
return data;
| public void | cleanUp()To cleanup the resources before exiting
out.close();
| public static java.util.Set | getAllAttributeNames(javax.management.MBeanServer server, javax.management.ObjectName objectName)
final Set<String> allNames = new HashSet<String>();
// add the Attribute names
final MBeanInfo info = server.getMBeanInfo(objectName);
final MBeanAttributeInfo[] attrsInfo = info.getAttributes();
if (attrsInfo != null) {
for (MBeanAttributeInfo aAttrsInfo : attrsInfo) {
allNames.add(aAttrsInfo.getName());
}
}
return (allNames);
| public java.util.ArrayList | getIndividualProperties(java.util.ArrayList list)To remove the non-properties.
eg: Ignores, Server.transaction-service and accepts server.
transaction-service.commitedcount
ArrayList<String> modifiedList = new ArrayList<String>();
String current = null;
Collections.reverse(list);
for (String next : list) {
if (current != null) {
if (current.indexOf(next) != 0) {
modifiedList.add(next);
current = next;
}
} else {
modifiedList.add(next);
current = next;
}
}
return modifiedList;
| private void | initializeRestrictedPropertiesLookUp()Initialize the list of properties that need to be ignored.
restrictedProperties = new HashSet<String>();
restrictedProperties.add("-description");
restrictedProperties.add("-name");
restrictedProperties.add("-lowerbound");
restrictedProperties.add("-starttime");
restrictedProperties.add("-upperbound");
| private boolean | isRestircted(java.lang.String dottedName)To check whether a particular property is in restricted list
boolean restricted = false;
if (dottedName != null) {
int index = dottedName.lastIndexOf("-");
if (index >= 0) {
String property = dottedName.substring(index);
if (restrictedProperties != null) {
restricted = restrictedProperties.contains(property);
}
}
}
return restricted;
|
|