Search in sources :

Example 1 with VmwarePerformanceValues

use of org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues in project opennms by OpenNMS.

the class VmwareViJavaAccessTest method testQueryPerformanceValues.

@Test
public void testQueryPerformanceValues() {
    replay(mockPerformanceManager, mockPerfProviderSummary, mockServiceInstance, ServiceInstance.class);
    VmwarePerformanceValues vmwarePerformanceValues = null;
    try {
        vmwareViJavaAccess.connect();
        vmwarePerformanceValues = vmwareViJavaAccess.queryPerformanceValues(managedEntity);
    } catch (MalformedURLException e) {
        Assert.fail(e.getMessage());
    } catch (RemoteException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(vmwarePerformanceValues);
    for (int i = 0; i < perfCounterInfos.length; i++) {
        PerfCounterInfo perfCounterInfo = perfCounterInfos[i];
        String expectedName = perfCounterInfo.getGroupInfo().getKey() + "." + perfCounterInfo.getNameInfo().getKey() + "." + perfCounterInfo.getRollupType().toString();
        if (vmwarePerformanceValues.hasInstances(expectedName)) {
            Set<String> instances = vmwarePerformanceValues.getInstances(expectedName);
            Assert.assertEquals(instances.size(), ((PerfEntityMetric) perfEntityMetricBases[i]).getValue().length);
            PerfMetricIntSeries[] perfMetricIntSeries = (PerfMetricIntSeries[]) ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
            for (int b = 0; b < perfMetricIntSeries.length; b++) {
                Assert.assertTrue(instances.contains(perfMetricIntSeries[b].getId().getInstance()));
            }
        } else {
            Assert.assertEquals(1, ((PerfEntityMetric) perfEntityMetricBases[i]).getValue().length);
        }
    }
    verify(mockPerformanceManager, mockPerfProviderSummary, mockServiceInstance, ServiceInstance.class);
}
Also used : PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) MalformedURLException(java.net.MalformedURLException) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) RemoteException(java.rmi.RemoteException) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with VmwarePerformanceValues

use of org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues in project opennms by OpenNMS.

the class VmwareCollector method collect.

/**
     * This method collect the data for a given collection agent.
     *
     * @param agent      the collection agent
     * @param parameters the parameters map
     * @return the generated collection set
     * @throws CollectionException
     */
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
    final VmwareCollection collection = (VmwareCollection) parameters.get(VMWARE_COLLECTION_KEY);
    final String vmwareManagementServer = (String) parameters.get(VMWARE_MGMT_SERVER_KEY);
    final String vmwareManagedObjectId = (String) parameters.get(VMWARE_MGED_OBJECT_ID_KEY);
    final VmwareServer vmwareServer = (VmwareServer) parameters.get(VMWARE_SERVER_KEY);
    CollectionSetBuilder builder = new CollectionSetBuilder(agent);
    builder.withStatus(CollectionStatus.FAILED);
    VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(vmwareServer);
    int timeout = ParameterMap.getKeyedInteger(parameters, "timeout", -1);
    if (timeout > 0) {
        if (!vmwareViJavaAccess.setTimeout(timeout)) {
            logger.warn("Error setting connection timeout for VMware management server '{}'", vmwareManagementServer);
        }
    }
    if (collection.getVmwareGroup().length < 1) {
        logger.info("No groups to collect. Returning empty collection set.");
        builder.withStatus(CollectionStatus.SUCCEEDED);
        return builder.build();
    }
    try {
        vmwareViJavaAccess.connect();
    } catch (MalformedURLException e) {
        logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
        return builder.build();
    } catch (RemoteException e) {
        logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
        return builder.build();
    }
    ManagedEntity managedEntity = vmwareViJavaAccess.getManagedEntityByManagedObjectId(vmwareManagedObjectId);
    VmwarePerformanceValues vmwarePerformanceValues = null;
    try {
        vmwarePerformanceValues = vmwareViJavaAccess.queryPerformanceValues(managedEntity);
    } catch (RemoteException e) {
        logger.warn("Error retrieving performance values from VMware management server '" + vmwareManagementServer + "' for managed object '" + vmwareManagedObjectId + "'", e.getMessage());
        vmwareViJavaAccess.disconnect();
        return builder.build();
    }
    for (final VmwareGroup vmwareGroup : collection.getVmwareGroup()) {
        final NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
        if ("node".equalsIgnoreCase(vmwareGroup.getResourceType())) {
            for (Attrib attrib : vmwareGroup.getAttrib()) {
                if (!vmwarePerformanceValues.hasSingleValue(attrib.getName())) {
                    // warning
                    logger.debug("Warning! No single value for '{}' defined as single instance attribute for node {}", attrib.getName(), agent.getNodeId());
                } else {
                    final Long value = vmwarePerformanceValues.getValue(attrib.getName());
                    logger.debug("Storing single instance value {}='{}' for node {}", attrib.getName(), value, agent.getNodeId());
                    final AttributeType type = attrib.getType();
                    if (type.isNumeric()) {
                        builder.withNumericAttribute(nodeResource, vmwareGroup.getName(), attrib.getAlias(), value, type);
                    } else {
                        builder.withStringAttribute(nodeResource, vmwareGroup.getName(), attrib.getAlias(), String.valueOf(value));
                    }
                }
            }
        } else {
            // multi instance value
            final Set<String> instanceSet = new TreeSet<>();
            final HashMap<String, Resource> resources = new HashMap<>();
            for (Attrib attrib : vmwareGroup.getAttrib()) {
                if (!vmwarePerformanceValues.hasInstances(attrib.getName())) {
                    // warning
                    logger.debug("Warning! No multi instance value for '{}' defined as multi instance attribute for node {}", attrib.getName(), agent.getNodeId());
                } else {
                    Set<String> newInstances = vmwarePerformanceValues.getInstances(attrib.getName());
                    for (String instance : newInstances) {
                        if (!instanceSet.contains(instance)) {
                            resources.put(instance, new DeferredGenericTypeResource(nodeResource, vmwareGroup.getResourceType(), instance));
                            instanceSet.add(instance);
                        }
                        final AttributeType type = attrib.getType();
                        final Long value = vmwarePerformanceValues.getValue(attrib.getName(), instance);
                        logger.debug("Storing multi instance value {}[{}='{}' for node {}", attrib.getName(), instance, value, agent.getNodeId());
                        if (type.isNumeric()) {
                            builder.withNumericAttribute(resources.get(instance), vmwareGroup.getName(), attrib.getAlias(), value, type);
                        } else {
                            builder.withStringAttribute(resources.get(instance), vmwareGroup.getName(), attrib.getAlias(), Long.toString(value));
                        }
                    }
                }
            }
            for (String instance : instanceSet) {
                logger.debug("Storing multi instance value {}[{}='{}' for node {}", vmwareGroup.getResourceType() + "Name", instance, instance, agent.getNodeId());
                builder.withStringAttribute(resources.get(instance), vmwareGroup.getName(), vmwareGroup.getResourceType() + "Name", instance);
            }
        }
    }
    builder.withStatus(CollectionStatus.SUCCEEDED);
    vmwareViJavaAccess.disconnect();
    return builder.build();
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) MalformedURLException(java.net.MalformedURLException) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) HashMap(java.util.HashMap) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Attrib(org.opennms.netmgt.config.vmware.vijava.Attrib) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) VmwareGroup(org.opennms.netmgt.config.vmware.vijava.VmwareGroup) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) AttributeType(org.opennms.netmgt.collection.api.AttributeType) TreeSet(java.util.TreeSet) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) RemoteException(java.rmi.RemoteException) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess)

Example 3 with VmwarePerformanceValues

use of org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues in project opennms by OpenNMS.

the class VmwareViJavaAccess method queryPerformanceValues.

/**
     * This method queries performance values for a given managed entity.
     *
     * @param managedEntity the managed entity to query
     * @return the perfomance values
     * @throws RemoteException
     */
public VmwarePerformanceValues queryPerformanceValues(ManagedEntity managedEntity) throws RemoteException {
    VmwarePerformanceValues vmwarePerformanceValues = new VmwarePerformanceValues();
    int refreshRate = getPerformanceManager().queryPerfProviderSummary(managedEntity).getRefreshRate();
    PerfQuerySpec perfQuerySpec = new PerfQuerySpec();
    perfQuerySpec.setEntity(managedEntity.getMOR());
    perfQuerySpec.setMaxSample(Integer.valueOf(1));
    perfQuerySpec.setIntervalId(refreshRate);
    PerfEntityMetricBase[] perfEntityMetricBases = getPerformanceManager().queryPerf(new PerfQuerySpec[] { perfQuerySpec });
    if (perfEntityMetricBases != null) {
        for (int i = 0; i < perfEntityMetricBases.length; i++) {
            PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
            for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) {
                if (perfMetricSeries[j] instanceof PerfMetricIntSeries) {
                    long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue();
                    if (longs.length == 1) {
                        PerfCounterInfo perfCounterInfo = getPerfCounterInfoMap().get(perfMetricSeries[j].getId().getCounterId());
                        String instance = perfMetricSeries[j].getId().getInstance();
                        String name = getHumanReadableName(perfCounterInfo);
                        if (instance != null && !"".equals(instance)) {
                            vmwarePerformanceValues.addValue(name, instance, longs[0]);
                        } else {
                            vmwarePerformanceValues.addValue(name, longs[0]);
                        }
                    }
                }
            }
        }
    }
    return vmwarePerformanceValues;
}
Also used : PerfMetricIntSeries(com.vmware.vim25.PerfMetricIntSeries) PerfCounterInfo(com.vmware.vim25.PerfCounterInfo) PerfMetricSeries(com.vmware.vim25.PerfMetricSeries) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) PerfQuerySpec(com.vmware.vim25.PerfQuerySpec) PerfEntityMetricBase(com.vmware.vim25.PerfEntityMetricBase) PerfEntityMetric(com.vmware.vim25.PerfEntityMetric)

Aggregations

VmwarePerformanceValues (org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues)3 PerfCounterInfo (com.vmware.vim25.PerfCounterInfo)2 PerfEntityMetric (com.vmware.vim25.PerfEntityMetric)2 PerfMetricIntSeries (com.vmware.vim25.PerfMetricIntSeries)2 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 PerfEntityMetricBase (com.vmware.vim25.PerfEntityMetricBase)1 PerfMetricSeries (com.vmware.vim25.PerfMetricSeries)1 PerfQuerySpec (com.vmware.vim25.PerfQuerySpec)1 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 AttributeType (org.opennms.netmgt.collection.api.AttributeType)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)1 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)1 Resource (org.opennms.netmgt.collection.support.builder.Resource)1 VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)1 Attrib (org.opennms.netmgt.config.vmware.vijava.Attrib)1