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);
}
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();
}
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;
}
Aggregations