Search in sources :

Example 1 with MonitorConfigurationException

use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.

the class MBeanWrapper method getObjectName.

/**
 * Gets the names of MBeans controlled by the MBean server
 *
 * @param name MBean name
 * @return MBean object name
 */
ObjectName getObjectName(String name) {
    Set<ObjectName> mBeanNames;
    try {
        mBeanNames = connection.queryNames(new ObjectName(name), null);
    } catch (Exception e) {
        final String errorMsg = "Error getting the names of MBeans on the monitored JVM application. Searched patter is " + name;
        log.error(errorMsg, e);
        throw new MonitorConfigurationException(errorMsg, e);
    }
    if (mBeanNames.size() != 1) {
        final String errorMsg = "Error getting the names of MBeans on the monitored JVM application. Searched patter is " + name + ". We expected to find 1, but found " + mBeanNames + " MBean names.";
        log.error(errorMsg);
        throw new MonitorConfigurationException(errorMsg);
    }
    Iterator<ObjectName> it = mBeanNames.iterator();
    return it.next();
}
Also used : MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) ObjectName(javax.management.ObjectName)

Example 2 with MonitorConfigurationException

use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.

the class MBeanWrapper method getMBeanAttribute.

/**
 * Gets the value of a specific attribute of a named MBean
 *
 * @param objectName the object name
 * @param attributeName the attribute name
 * @return the attribute value
 */
Object getMBeanAttribute(ObjectName objectName, String attributeName) {
    try {
        for (MBeanAttributeInfo attInfo : connection.getMBeanInfo(objectName).getAttributes()) {
            String attName = attInfo.getName();
            if (attName.equals(attributeName)) {
                return connection.getAttribute(objectName, attributeName);
            }
        }
    } catch (Exception e) {
        final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "'";
        log.error(errorMsg, e);
        throw new MonitorConfigurationException(errorMsg, e);
    }
    final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "': The attribute is not found!";
    log.error(errorMsg);
    throw new MonitorConfigurationException(errorMsg);
}
Also used : MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException)

Example 3 with MonitorConfigurationException

use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.

the class ReadingsRepository method readFileFromJar.

private InputStream readFileFromJar(String jarFile) throws MonitorConfigurationException {
    // extract the file path in the jar
    String configurationFile = jarFile.substring(jarFile.lastIndexOf('!') + 2, jarFile.length());
    log.info("Loading monitoring service configuration file '" + configurationFile + "' from " + jarFile);
    try {
        return IoUtils.readFileFromJar(jarFile, configurationFile);
    } catch (IOException e) {
        throw new MonitorConfigurationException("Error loading monitoring service configuration file '" + configurationFile + "' from " + jarFile);
    }
}
Also used : MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) IOException(java.io.IOException)

Example 4 with MonitorConfigurationException

use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.

the class ReadingsRepository method loadConfigurations.

/**
 * Loads the user provided configuration files which ends up in updating the repository with supported readings.
 * URLs could be direct files, in-JAR-files, tmp/work dir extracted files like in WildFly VFS
 *
 * @param configurationFileUrls - list of URLs of configuration files
 * @throws MonitorConfigurationException
 */
public void loadConfigurations(List<URL> configurationFileUrls) throws MonitorConfigurationException {
    try {
        // empty the repository with readings definitions
        cleanRepository();
        // clear previously loaded monitors
        this.alreadyLoadedMonitors.clear();
        for (URL configurationFileUrl : configurationFileUrls) {
            InputStream configurationFileStream = null;
            try {
                configurationFileStream = configurationFileUrl.openStream();
            } catch (IOException e) {
                throw new MonitorConfigurationException("Error reading performance configuration data from '" + configurationFileUrl + "'", e);
            }
            // fill the repository with readings definitions
            readConfiguration(configurationFileUrl, configurationFileStream);
        }
    } catch (MonitorConfigurationException e) {
        // on error empty the repository with readings definitions, so we know it is all clean
        cleanRepository();
        // on error clear previously loaded monitors
        this.alreadyLoadedMonitors.clear();
        throw e;
    }
}
Also used : InputStream(java.io.InputStream) MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with MonitorConfigurationException

use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.

the class ReadingsRepository method readConfiguration.

void readConfiguration(URL configurationFileNameURL, InputStream configurationFileStream) throws MonitorConfigurationException {
    this.readingParseState.rememberConfigurationFileName(configurationFileNameURL.toString());
    Document xmlDocument;
    try {
        xmlDocument = XmlUtils.loadXMLFile(configurationFileStream);
    } catch (IOException e) {
        throw new MonitorConfigurationException("Error reading monitoring service configuration file from '" + configurationFileNameURL + "'", e);
    } catch (SAXException e) {
        throw new MonitorConfigurationException("Error parsing monitoring service configuration file from '" + configurationFileNameURL + "'", e);
    }
    Element rootElement = xmlDocument.getDocumentElement();
    // iterate over all children, all of them being monitors
    NodeList monitorLevelElements = rootElement.getChildNodes();
    for (int i = 0; i < monitorLevelElements.getLength(); i++) {
        Node monitorLevelElement = monitorLevelElements.item(i);
        if (monitorLevelElement.getNodeType() == Node.ELEMENT_NODE && monitorLevelElement.getNodeName().equals(MONITOR_NODE)) {
            extractMonitor((Element) monitorLevelElement);
        }
    }
    this.readingParseState.forgetConfigurationFileName();
}
Also used : MonitorConfigurationException(com.axway.ats.core.monitoring.MonitorConfigurationException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

MonitorConfigurationException (com.axway.ats.core.monitoring.MonitorConfigurationException)10 IOException (java.io.IOException)3 ObjectName (javax.management.ObjectName)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SystemInformationException (com.axway.ats.agent.core.monitoring.systemmonitor.systeminformation.exceptions.SystemInformationException)1 PerformanceMonitor (com.axway.ats.common.performance.monitor.PerformanceMonitor)1 ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)1 MonitoringException (com.axway.ats.core.monitoring.MonitoringException)1 Validator (com.axway.ats.core.validation.Validator)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 SigarException (org.hyperic.sigar.SigarException)1 SigarLoadAverage (org.hyperic.sigar.jmx.SigarLoadAverage)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1