Search in sources :

Example 1 with CounterInfo

use of com.vmware.vim.binding.vim.PerformanceManager.CounterInfo in project flowgate by vmware.

the class VCDataService method getMetricsCounters.

private Map<Integer, String> getMetricsCounters(PerformanceManager performanceManager) {
    CounterInfo[] counterInfos = performanceManager.getPerfCounter();
    Map<Integer, String> counters = new HashMap<Integer, String>();
    for (int i = 0; i < counterInfos.length; i++) {
        CounterInfo counterInfo = counterInfos[i];
        int counterId = counterInfo.getKey();
        String groupKey = counterInfo.getGroupInfo().getKey();
        String nameKey = counterInfo.getNameInfo().getKey();
        switch(groupKey) {
            case VCConstants.HOST_CPU_GROUP:
                switch(nameKey) {
                    case VCConstants.HOST_METRIC_USAGE:
                    case VCConstants.HOST_METRIC_USAGEMHZ:
                        counters.put(counterId, groupKey.concat(nameKey));
                        break;
                }
                break;
            case VCConstants.HOST_MEMORY_GROUP:
                switch(nameKey) {
                    case VCConstants.HOST_METRIC_USAGE:
                    case VCConstants.HOST_METRIC_MEM_ACTIVE:
                    case VCConstants.HOST_METRIC_MEM_SHARED:
                    case VCConstants.HOST_METRIC_MEM_CONSUMED:
                    case VCConstants.HOST_METRIC_MEM_SWAP:
                    case VCConstants.HOST_METRIC_MEM_BALLON:
                        counters.put(counterId, groupKey.concat(nameKey));
                        break;
                }
                break;
            case VCConstants.HOST_DISK_GROUP:
                switch(nameKey) {
                    case VCConstants.HOST_METRIC_USAGE:
                        counters.put(counterId, groupKey.concat(nameKey));
                        break;
                }
                break;
            case VCConstants.HOST_NETWORK_GROUP:
                switch(nameKey) {
                    case VCConstants.HOST_METRIC_USAGE:
                        counters.put(counterId, groupKey.concat(nameKey));
                        break;
                }
                break;
            case VCConstants.HOST_POWER_GROUP:
                switch(nameKey) {
                    case VCConstants.HOST_METRIC_POWER_POWER:
                    case VCConstants.HOST_METRIC_POWER_ENERGY:
                        counters.put(counterId, groupKey.concat(nameKey));
                        break;
                }
            default:
                break;
        }
    }
    return counters;
}
Also used : HashMap(java.util.HashMap) CounterInfo(com.vmware.vim.binding.vim.PerformanceManager.CounterInfo)

Example 2 with CounterInfo

use of com.vmware.vim.binding.vim.PerformanceManager.CounterInfo in project flowgate by vmware.

the class VCDataServiceTest method testFeedHostUsageData.

@Test
public void testFeedHostUsageData() {
    Asset hostMappingAsset = Mockito.mock(Asset.class);
    HostSystem host = Mockito.mock(HostSystem.class);
    when(hostMappingAsset.getId()).thenReturn("hostid");
    PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
    when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
    CounterInfo[] counterInfos = new CounterInfo[4];
    counterInfos[0] = Mockito.mock(CounterInfo.class);
    when(counterInfos[0].getKey()).thenReturn(1);
    ElementDescription edGroup = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
    when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
    ElementDescription edName = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getNameInfo()).thenReturn(edName);
    when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[1] = Mockito.mock(CounterInfo.class);
    when(counterInfos[1].getKey()).thenReturn(2);
    ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
    when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
    ElementDescription edName1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getNameInfo()).thenReturn(edName1);
    when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[2] = Mockito.mock(CounterInfo.class);
    when(counterInfos[2].getKey()).thenReturn(3);
    ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
    when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getNameInfo()).thenReturn(edName2);
    when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
    counterInfos[3] = Mockito.mock(CounterInfo.class);
    when(counterInfos[3].getKey()).thenReturn(4);
    ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
    when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getNameInfo()).thenReturn(edName3);
    when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
    when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
    MetricId[] metrics = new MetricId[4];
    metrics[0] = Mockito.mock(MetricId.class);
    metrics[1] = Mockito.mock(MetricId.class);
    metrics[2] = Mockito.mock(MetricId.class);
    metrics[3] = Mockito.mock(MetricId.class);
    when(metrics[0].getCounterId()).thenReturn(1);
    when(metrics[1].getCounterId()).thenReturn(2);
    when(metrics[2].getCounterId()).thenReturn(3);
    when(metrics[3].getCounterId()).thenReturn(4);
    when(metrics[0].getInstance()).thenReturn(null);
    when(metrics[1].getInstance()).thenReturn(null);
    when(metrics[2].getInstance()).thenReturn(null);
    when(metrics[3].getInstance()).thenReturn(null);
    when(performanceManager.queryAvailableMetric(host._getRef(), null, null, new Integer(20))).thenReturn(metrics);
    ProviderSummary summary = Mockito.mock(ProviderSummary.class);
    when(summary.getRefreshRate()).thenReturn(1);
    when(performanceManager.queryProviderSummary(host._getRef())).thenReturn(summary);
    EntityMetric[] metricBase = new EntityMetric[4];
    metricBase[0] = Mockito.mock(EntityMetric.class);
    long[] values = { 1L, 2L, 3L, 4L };
    IntSeries[] metricSerieses1 = new IntSeries[4];
    metricSerieses1[0] = Mockito.mock(IntSeries.class);
    MetricId metricID = Mockito.mock(MetricId.class);
    when(metricSerieses1[0].getId()).thenReturn(metricID);
    when(metricID.getCounterId()).thenReturn(1);
    IntSeries intSeries1 = Mockito.mock(IntSeries.class);
    intSeries1 = metricSerieses1[0];
    when((intSeries1.getValue())).thenReturn(values);
    when(metricID.getCounterId()).thenReturn(1);
    metricSerieses1[1] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[1].getId()).thenReturn(metricID);
    when(metricID.getCounterId()).thenReturn(1);
    IntSeries intSeries2 = Mockito.mock(IntSeries.class);
    intSeries2 = metricSerieses1[1];
    when(intSeries2.getValue()).thenReturn(values);
    MetricId metricID2 = Mockito.mock(MetricId.class);
    metricSerieses1[2] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[2].getId()).thenReturn(metricID2);
    when(metricID2.getCounterId()).thenReturn(3);
    IntSeries intSeries3 = Mockito.mock(IntSeries.class);
    intSeries3 = metricSerieses1[2];
    when(intSeries3.getValue()).thenReturn(values);
    MetricId metricID3 = Mockito.mock(MetricId.class);
    metricSerieses1[3] = Mockito.mock(IntSeries.class);
    when(metricSerieses1[3].getId()).thenReturn(metricID3);
    when(metricID3.getCounterId()).thenReturn(4);
    IntSeries intSeries4 = Mockito.mock(IntSeries.class);
    intSeries4 = metricSerieses1[3];
    when(intSeries4.getValue()).thenReturn(values);
    when(metricBase[0].getValue()).thenReturn(metricSerieses1);
    SampleInfo[] sampleInfos1 = new SampleInfo[4];
    sampleInfos1[0] = Mockito.mock(SampleInfo.class);
    Calendar time = Calendar.getInstance();
    when(sampleInfos1[0].getTimestamp()).thenReturn(time);
    sampleInfos1[1] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[1].getTimestamp()).thenReturn(time);
    sampleInfos1[2] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[2].getTimestamp()).thenReturn(time);
    sampleInfos1[3] = Mockito.mock(SampleInfo.class);
    when(sampleInfos1[3].getTimestamp()).thenReturn(time);
    when(metricBase[0].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[1] = Mockito.mock(EntityMetric.class);
    when(metricBase[1].getValue()).thenReturn(metricSerieses1);
    when(metricBase[1].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[2] = Mockito.mock(EntityMetric.class);
    when(metricBase[2].getValue()).thenReturn(metricSerieses1);
    when(metricBase[2].getSampleInfo()).thenReturn(sampleInfos1);
    metricBase[3] = Mockito.mock(EntityMetric.class);
    when(metricBase[3].getValue()).thenReturn(metricSerieses1);
    when(metricBase[3].getSampleInfo()).thenReturn(sampleInfos1);
    when(performanceManager.queryStats(any())).thenReturn(metricBase);
    service.feedHostUsageData(vsphereClient, hostMappingAsset.getId(), host._getRef());
}
Also used : Calendar(java.util.Calendar) SampleInfo(com.vmware.vim.binding.vim.PerformanceManager.SampleInfo) MetricId(com.vmware.vim.binding.vim.PerformanceManager.MetricId) PerformanceManager(com.vmware.vim.binding.vim.PerformanceManager) EntityMetric(com.vmware.vim.binding.vim.PerformanceManager.EntityMetric) HostSystem(com.vmware.vim.binding.vim.HostSystem) IntSeries(com.vmware.vim.binding.vim.PerformanceManager.IntSeries) Asset(com.vmware.flowgate.common.model.Asset) CounterInfo(com.vmware.vim.binding.vim.PerformanceManager.CounterInfo) ProviderSummary(com.vmware.vim.binding.vim.PerformanceManager.ProviderSummary) ElementDescription(com.vmware.vim.binding.vim.ElementDescription) Test(org.junit.Test)

Example 3 with CounterInfo

use of com.vmware.vim.binding.vim.PerformanceManager.CounterInfo in project flowgate by vmware.

the class VCDataServiceTest method testFeedHostUsageDataNotAvailableMetricId.

@Test
public void testFeedHostUsageDataNotAvailableMetricId() {
    PerformanceManager performanceManager = Mockito.mock(PerformanceManager.class);
    when(vsphereClient.getPerformanceManager()).thenReturn(performanceManager);
    CounterInfo[] counterInfos = new CounterInfo[4];
    counterInfos[0] = Mockito.mock(CounterInfo.class);
    when(counterInfos[0].getKey()).thenReturn(1);
    ElementDescription edGroup = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getGroupInfo()).thenReturn(edGroup);
    when(edGroup.getKey()).thenReturn(VCConstants.HOST_CPU_GROUP);
    ElementDescription edName = Mockito.mock(ElementDescription.class);
    when(counterInfos[0].getNameInfo()).thenReturn(edName);
    when(edName.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[1] = Mockito.mock(CounterInfo.class);
    when(counterInfos[1].getKey()).thenReturn(2);
    ElementDescription edGroup1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getGroupInfo()).thenReturn(edGroup1);
    when(edGroup1.getKey()).thenReturn(VCConstants.HOST_MEMORY_GROUP);
    ElementDescription edName1 = Mockito.mock(ElementDescription.class);
    when(counterInfos[1].getNameInfo()).thenReturn(edName1);
    when(edName1.getKey()).thenReturn(VCConstants.HOST_METRIC_USAGE);
    counterInfos[2] = Mockito.mock(CounterInfo.class);
    when(counterInfos[2].getKey()).thenReturn(3);
    ElementDescription edGroup2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getGroupInfo()).thenReturn(edGroup2);
    when(edGroup2.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName2 = Mockito.mock(ElementDescription.class);
    when(counterInfos[2].getNameInfo()).thenReturn(edName2);
    when(edName2.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_ENERGY);
    counterInfos[3] = Mockito.mock(CounterInfo.class);
    when(counterInfos[3].getKey()).thenReturn(4);
    ElementDescription edGroup3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getGroupInfo()).thenReturn(edGroup3);
    when(edGroup3.getKey()).thenReturn(VCConstants.HOST_POWER_GROUP);
    ElementDescription edName3 = Mockito.mock(ElementDescription.class);
    when(counterInfos[3].getNameInfo()).thenReturn(edName3);
    when(edName3.getKey()).thenReturn(VCConstants.HOST_METRIC_POWER_POWER);
    when(performanceManager.getPerfCounter()).thenReturn(counterInfos);
    HostSystem host = Mockito.mock(HostSystem.class);
    ManagedObjectReference managedObjectReference = host._getRef();
    when(performanceManager.queryAvailableMetric(managedObjectReference, null, null, new Integer(20))).thenReturn(null);
    service.feedHostUsageData(vsphereClient, "avbaebhqw9", managedObjectReference);
}
Also used : PerformanceManager(com.vmware.vim.binding.vim.PerformanceManager) HostSystem(com.vmware.vim.binding.vim.HostSystem) CounterInfo(com.vmware.vim.binding.vim.PerformanceManager.CounterInfo) ElementDescription(com.vmware.vim.binding.vim.ElementDescription) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Aggregations

CounterInfo (com.vmware.vim.binding.vim.PerformanceManager.CounterInfo)3 ElementDescription (com.vmware.vim.binding.vim.ElementDescription)2 HostSystem (com.vmware.vim.binding.vim.HostSystem)2 PerformanceManager (com.vmware.vim.binding.vim.PerformanceManager)2 Test (org.junit.Test)2 Asset (com.vmware.flowgate.common.model.Asset)1 EntityMetric (com.vmware.vim.binding.vim.PerformanceManager.EntityMetric)1 IntSeries (com.vmware.vim.binding.vim.PerformanceManager.IntSeries)1 MetricId (com.vmware.vim.binding.vim.PerformanceManager.MetricId)1 ProviderSummary (com.vmware.vim.binding.vim.PerformanceManager.ProviderSummary)1 SampleInfo (com.vmware.vim.binding.vim.PerformanceManager.SampleInfo)1 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1