use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.
the class QueryCommand method execute.
@Override
protected void execute(MBeanServerConnection mbeanServerConnection) throws MBeanServerQueryException, IOException {
if (domainOnlyFlag && (filter == null || filter.isEmpty())) {
for (String eachDomain : mbeanServerConnection.getDomains()) {
LOG.info(eachDomain);
}
return;
}
MBeanServerQuery queryBuilder = new MBeanServerQuery().withFilters(filter).withIgnoresFilter(ignoreFilter).fetchValues(includeValues).showMBeansWithoutAttributes(all).sort(true);
QueryResult result = queryBuilder.execute(mbeanServerConnection);
if (idOnlyFlag) {
for (QueryResult.MBeanResult eachResult : result.getMBeanResults()) {
for (MBeanAttributeInfo eachAttributeInfo : eachResult.attributeResult.attributes) {
LOG.info(toAttributeId(eachResult.objectName, eachAttributeInfo));
}
}
} else {
prettyPrint(result);
}
}
use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.
the class QueryCommand method prettyPrint.
private void prettyPrint(QueryResult result) {
for (QueryResult.MBeanResult eachMBeanResult : result.getMBeanResults()) {
MBeanInfo mbeanInfo = eachMBeanResult.mbeanInfo;
ObjectName objectName = eachMBeanResult.objectName;
QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
LOG.info(String.format("%s", objectName));
LOG.info(String.format("\tdescription: %s", toString(mbeanInfo.getDescription())));
LOG.info(String.format("\tclass name: %s", mbeanInfo.getClassName()));
LOG.info(String.format("\tattributes: (%d/%d)", attributeResult.attributes.size(), attributeResult.totalCount));
for (MBeanAttributeInfo eachAttribute : attributeResult.attributes) {
LOG.info(String.format("\t\t%s", eachAttribute.getName()));
LOG.info(String.format("\t\t\tid: %s", toAttributeId(objectName, eachAttribute)));
LOG.info(String.format("\t\t\tdescription: %s", toString(eachAttribute.getDescription())));
LOG.info(String.format("\t\t\ttype: %s", eachAttribute.getType()));
LOG.info(String.format("\t\t\tisReadable: %s", eachAttribute.isReadable()));
LOG.info(String.format("\t\t\tisWritable: %s", eachAttribute.isWritable()));
LOG.info(String.format("\t\t\tisIs: %s", eachAttribute.isIs()));
if (includeValues) {
LOG.info(String.format("\t\t\tvalue: %s", toString(attributeResult.getValue(eachAttribute))));
}
}
}
if (filter != null && !filter.isEmpty()) {
LOG.info(String.format("Your query '%s' shows %d/%d MBeans.", filter, result.getMBeanResults().size(), result.getTotalMBeanCount()));
} else {
LOG.info(String.format("There are %d registered MBeans", result.getTotalMBeanCount()));
}
if (ignoreFilter != null && !ignoreFilter.isEmpty()) {
LOG.info(String.format("While querying, the following query was used to exclude MBeans/Attributes: '%s'", ignoreFilter));
}
}
use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.
the class JmxDatacollectionConfiggenerator method queryMbeanServer.
private QueryResult queryMbeanServer(List<String> ids, MBeanServerConnection mBeanServerConnection, boolean runStandardVmBeans) throws MBeanServerQueryException {
final MBeanServerQuery query = new MBeanServerQuery().withFilters(ids).fetchValues(// we do not fetch values to improve collection speed
false).showMBeansWithoutAttributes(// we don't need them
false).sort(// sorting makes finding attributes easier
true);
if (!runStandardVmBeans) {
query.withIgnoresFilter(Collections2.transform(standardVmBeans, input -> input + ":*"));
}
final QueryResult result = query.execute(mBeanServerConnection);
return result;
}
use of org.opennms.features.jmxconfiggenerator.jmxconfig.query.QueryResult in project opennms by OpenNMS.
the class JmxDatacollectionConfiggenerator method generateJmxConfigModel.
public JmxDatacollectionConfig generateJmxConfigModel(List<String> ids, MBeanServerConnection mBeanServerConnection, String serviceName, Boolean runStandardVmBeans, Boolean skipNonNumber, Map<String, String> dictionary) throws MBeanServerQueryException, IOException, JMException {
logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: " + runStandardVmBeans + "\n dictionary" + dictionary);
aliasList.clear();
aliasMap.clear();
nameCutter.setDictionary(dictionary);
final QueryResult queryResult = queryMbeanServer(ids, mBeanServerConnection, runStandardVmBeans);
final JmxDatacollectionConfig xmlJmxDatacollectionConfig = createJmxDataCollectionConfig(serviceName, rrd);
final JmxCollection xmlJmxCollection = xmlJmxDatacollectionConfig.getJmxCollectionList().get(0);
for (QueryResult.MBeanResult eachMBeanResult : queryResult.getMBeanResults()) {
final ObjectName objectName = eachMBeanResult.objectName;
final Mbean xmlMbean = createMbean(objectName);
final QueryResult.AttributeResult attributeResult = eachMBeanResult.attributeResult;
for (MBeanAttributeInfo jmxBeanAttributeInfo : attributeResult.attributes) {
// check for CompositeData
if ("javax.management.openmbean.CompositeData".equals(jmxBeanAttributeInfo.getType())) {
CompAttrib compAttrib = createCompAttrib(mBeanServerConnection, objectName, jmxBeanAttributeInfo, skipNonNumber);
if (compAttrib != null) {
xmlMbean.addCompAttrib(compAttrib);
}
}
if (skipNonNumber && !numbers.contains(jmxBeanAttributeInfo.getType())) {
logger.warn("The type of attribute '{}' is '{}' and '--skipNonNumber' is set. Ignoring.", jmxBeanAttributeInfo.getName(), jmxBeanAttributeInfo.getType());
} else {
Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
xmlMbean.addAttrib(xmlJmxAttribute);
}
}
if (!xmlMbean.getAttribList().isEmpty() || !xmlMbean.getCompAttribList().isEmpty()) {
xmlJmxCollection.addMbean(xmlMbean);
}
}
if (xmlJmxCollection.getMbeans().size() != queryResult.getMBeanResults().size()) {
logger.warn("Queried {} MBeans, but only got {} in the result set.", queryResult.getMBeanResults().size(), xmlJmxCollection.getMbeans().size());
}
return xmlJmxDatacollectionConfig;
}
Aggregations