Search in sources :

Example 6 with MetricData

use of com.microsoft.applicationinsights.smoketest.schemav2.MetricData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method trackMetric.

@Test
@TargetUri("/trackMetric")
public void trackMetric() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    List<Envelope> mdList = mockedIngestion.waitForItems("MetricData", 1);
    Envelope rdEnvelope = rdList.get(0);
    Envelope mdEnvelope = mdList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    MetricData md = (MetricData) ((Data<?>) mdEnvelope.getData()).getBaseData();
    List<DataPoint> metrics = md.getMetrics();
    assertEquals(1, metrics.size());
    DataPoint dp = metrics.get(0);
    final double expectedValue = 111222333.0;
    double epsilon = Math.ulp(expectedValue);
    assertEquals(DataPointType.Measurement, dp.getKind());
    assertEquals(expectedValue, dp.getValue(), epsilon);
    assertEquals("TimeToRespond", dp.getName());
    assertNull("getCount was non-null", dp.getCount());
    assertNull("getMin was non-null", dp.getMin());
    assertNull("getMax was non-null", dp.getMax());
    assertNull("getStdDev was non-null", dp.getStdDev());
    assertParentChild(rd, rdEnvelope, mdEnvelope, "GET /CoreAndFilter/trackMetric");
}
Also used : DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 7 with MetricData

use of com.microsoft.applicationinsights.smoketest.schemav2.MetricData in project ApplicationInsights-Java by microsoft.

the class PerfCountersDataTest method testPerformanceCounterData.

@Test
@TargetUri(value = "index.jsp", delay = 5000)
public void testPerformanceCounterData() throws Exception {
    System.out.println("Waiting for performance data...");
    long start = System.currentTimeMillis();
    // need to accommodate for START_COLLECTING_DELAY_IN_MILLIS = 60 seconds
    int timeout = 70;
    Envelope availableMem = mockedIngestion.waitForItem(getPerfMetricPredicate("\\Memory\\Available Bytes"), timeout, TimeUnit.SECONDS);
    Envelope totalCpu = mockedIngestion.waitForItem(getPerfMetricPredicate("\\Processor(_Total)\\% Processor Time"), timeout, TimeUnit.SECONDS);
    Envelope processIo = mockedIngestion.waitForItem(getPerfMetricPredicate("\\Process(??APP_WIN32_PROC??)\\IO Data Bytes/sec"), timeout, TimeUnit.SECONDS);
    Envelope processMemUsed = mockedIngestion.waitForItem(getPerfMetricPredicate("\\Process(??APP_WIN32_PROC??)\\Private Bytes"), timeout, TimeUnit.SECONDS);
    Envelope processCpu = mockedIngestion.waitForItem(getPerfMetricPredicate("\\Process(??APP_WIN32_PROC??)\\% Processor Time"), timeout, TimeUnit.SECONDS);
    System.out.println("PerformanceCounterData are good: " + (System.currentTimeMillis() - start));
    MetricData metricMem = getBaseData(availableMem);
    assertPerfMetric(metricMem);
    assertEquals("\\Memory\\Available Bytes", metricMem.getMetrics().get(0).getName());
    MetricData pdCpu = getBaseData(totalCpu);
    assertPerfMetric(pdCpu);
    assertEquals("\\Processor(_Total)\\% Processor Time", pdCpu.getMetrics().get(0).getName());
    assertPerfMetric(getBaseData(processIo));
    assertPerfMetric(getBaseData(processMemUsed));
    assertPerfMetric(getBaseData(processCpu));
    start = System.currentTimeMillis();
    System.out.println("Waiting for metric data...");
    Envelope deadlocks = mockedIngestion.waitForItem(getPerfMetricPredicate("Suspected Deadlocked Threads"), timeout, TimeUnit.SECONDS);
    Envelope heapUsed = mockedIngestion.waitForItem(getPerfMetricPredicate("Heap Memory Used (MB)"), timeout, TimeUnit.SECONDS);
    Envelope gcTotalCount = mockedIngestion.waitForItem(getPerfMetricPredicate("GC Total Count"), timeout, TimeUnit.SECONDS);
    Envelope gcTotalTime = mockedIngestion.waitForItem(getPerfMetricPredicate("GC Total Time"), timeout, TimeUnit.SECONDS);
    System.out.println("MetricData are good: " + (System.currentTimeMillis() - start));
    MetricData mdDeadlocks = getBaseData(deadlocks);
    assertPerfMetric(mdDeadlocks);
    assertEquals(0.0, mdDeadlocks.getMetrics().get(0).getValue(), Math.ulp(0.0));
    MetricData mdHeapUsed = getBaseData(heapUsed);
    assertPerfMetric(mdHeapUsed);
    assertTrue(mdHeapUsed.getMetrics().get(0).getValue() > 0.0);
    MetricData mdGcTotalCount = getBaseData(gcTotalCount);
    assertPerfMetric(mdGcTotalCount);
    MetricData mdGcTotalTime = getBaseData(gcTotalTime);
    assertPerfMetric(mdGcTotalTime);
}
Also used : Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 8 with MetricData

use of com.microsoft.applicationinsights.smoketest.schemav2.MetricData in project ApplicationInsights-Java by microsoft.

the class MicrometerTest method doMostBasicTest.

@Test
@TargetUri("/test")
public void doMostBasicTest() throws Exception {
    Telemetry telemetry = getTelemetry(0);
    assertEquals("GET /test", telemetry.rd.getName());
    assertTrue(telemetry.rd.getUrl().matches("http://localhost:[0-9]+/test"));
    assertEquals("200", telemetry.rd.getResponseCode());
    assertTrue(telemetry.rd.getSuccess());
    assertNull(telemetry.rd.getSource());
    assertTrue(telemetry.rd.getProperties().isEmpty());
    assertTrue(telemetry.rd.getMeasurements().isEmpty());
    // sleep a bit and make sure that the excluded metric is not reported
    Thread.sleep(10000);
    List<Envelope> metricItems = mockedIngestion.getItemsEnvelopeDataType("MetricData").stream().filter(e -> {
        MetricData data = (MetricData) ((Data<?>) e.getData()).getBaseData();
        List<DataPoint> points = data.getMetrics();
        DataPoint point = points.get(0);
        return point.getValue() == 1;
    }).collect(Collectors.toList());
    MetricData data = (MetricData) ((Data<?>) metricItems.get(0).getData()).getBaseData();
    List<DataPoint> points = data.getMetrics();
    assertEquals(1, points.size());
    DataPoint point = points.get(0);
    assertEquals(DataPointType.Measurement, point.getKind());
    // (this was verified above in Predicate also)
    assertEquals(1, point.getValue(), 0);
    assertEquals("test_counter", point.getName());
    assertNull("getCount was non-null", point.getCount());
    assertNull("getMin was non-null", point.getMin());
    assertNull("getMax was non-null", point.getMax());
    assertNull("getStdDev was non-null", point.getStdDev());
    assertEquals(1, data.getProperties().size());
    assertEquals("value1", data.getProperties().get("tag1"));
}
Also used : List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Assert.assertTrue(org.junit.Assert.assertTrue) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) DataPointType(com.microsoft.applicationinsights.smoketest.schemav2.DataPointType) DataPoint(com.microsoft.applicationinsights.smoketest.schemav2.DataPoint) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) List(java.util.List) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 9 with MetricData

use of com.microsoft.applicationinsights.smoketest.schemav2.MetricData in project ApplicationInsights-Java by microsoft.

the class StatsbeatSmokeTest method testStatsbeat.

@Test
@TargetUri(value = "/index.jsp")
public void testStatsbeat() throws Exception {
    List<Envelope> metrics = mockedIngestion.waitForItems(getMetricPredicate("Feature"), 2, 70, TimeUnit.SECONDS);
    MetricData data = (MetricData) ((Data<?>) metrics.get(0).getData()).getBaseData();
    assertCommon(data);
    assertNotNull(data.getProperties().get("feature"));
    assertNotNull(data.getProperties().get("type"));
    assertEquals("0", data.getProperties().get("type"));
    assertEquals(9, data.getProperties().size());
    MetricData instrumentationData = (MetricData) ((Data<?>) metrics.get(1).getData()).getBaseData();
    assertCommon(instrumentationData);
    assertNotNull(instrumentationData.getProperties().get("feature"));
    assertNotNull(instrumentationData.getProperties().get("type"));
    assertEquals("1", instrumentationData.getProperties().get("type"));
    assertEquals(9, instrumentationData.getProperties().size());
    List<Envelope> attachMetrics = mockedIngestion.waitForItems(getMetricPredicate("Attach"), 1, 70, TimeUnit.SECONDS);
    MetricData attachData = (MetricData) ((Data<?>) attachMetrics.get(0).getData()).getBaseData();
    assertCommon(attachData);
    assertNotNull(attachData.getProperties().get("rpId"));
    assertEquals(8, attachData.getProperties().size());
    List<Envelope> requestSuccessCountMetrics = mockedIngestion.waitForItems(getMetricPredicate("Request Success Count"), 1, 70, TimeUnit.SECONDS);
    MetricData requestSuccessCountData = (MetricData) ((Data<?>) requestSuccessCountMetrics.get(0).getData()).getBaseData();
    assertCommon(requestSuccessCountData);
    assertNotNull(requestSuccessCountData.getProperties().get("endpoint"));
    assertNotNull(requestSuccessCountData.getProperties().get("host"));
    assertEquals(9, requestSuccessCountData.getProperties().size());
    List<Envelope> requestDurationMetrics = mockedIngestion.waitForItems(getMetricPredicate("Request Duration"), 1, 70, TimeUnit.SECONDS);
    MetricData requestDurationData = (MetricData) ((Data<?>) requestDurationMetrics.get(0).getData()).getBaseData();
    assertCommon(requestDurationData);
    assertNotNull(requestSuccessCountData.getProperties().get("endpoint"));
    assertNotNull(requestSuccessCountData.getProperties().get("host"));
    assertEquals(9, requestDurationData.getProperties().size());
}
Also used : Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) MetricData(com.microsoft.applicationinsights.smoketest.schemav2.MetricData) Test(org.junit.Test)

Example 10 with MetricData

use of com.microsoft.applicationinsights.smoketest.schemav2.MetricData in project Server_Management_Plugin_vRealize by Huawei.

the class MezzBean method convert2Resource.

@Override
public ResourceKey convert2Resource(String id, String adapterKind, Map<ResourceKey, List<MetricData>> metricsByResource) {
    ResourceKey resourceKey = new ResourceKey(this.name, Constant.KIND_MEZZ, adapterKind);
    // 设定唯一的标识,保证同名的资源可以正常显示
    ResourceIdentifierConfig dnIdentifier = new ResourceIdentifierConfig(Constant.ATTR_ID, id + this.uuid, true);
    resourceKey.addIdentifier(dnIdentifier);
    long timestamp = System.currentTimeMillis();
    List<MetricData> metricData = new ArrayList<>();
    // 写入resource属性
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_NAME), timestamp, this.name));
    metricData.add(new MetricData(new MetricKey(false).add(Constant.ATTR_MEZZ_HEALTH_STATUS), timestamp, ConvertUtils.convertHealthState(this.getMezzHealthStatus())));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_PRESENTSTATE), timestamp, ConvertUtils.convertPresentState(this.presentState)));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MEZZ_INFO), timestamp, this.mezzInfo));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MEZZ_LOCATION), timestamp, this.mezzLocation));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MEZZ_ETH_MAC), timestamp, this.mezzETHMac));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MEZZ_IB_MAC), timestamp, this.mezzIBMac));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MEZZ_FCWWPN), timestamp, this.mezzFCWWPN));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_MOID), timestamp, this.moId));
    metricData.add(new MetricData(new MetricKey(true).add(Constant.ATTR_UUID), timestamp, this.uuid));
    // 关联key和属性值
    metricsByResource.put(resourceKey, metricData);
    return resourceKey;
}
Also used : ResourceIdentifierConfig(com.integrien.alive.common.adapter3.config.ResourceIdentifierConfig) MetricKey(com.integrien.alive.common.adapter3.MetricKey) ArrayList(java.util.ArrayList) ResourceKey(com.integrien.alive.common.adapter3.ResourceKey) MetricData(com.integrien.alive.common.adapter3.MetricData)

Aggregations

MetricData (com.integrien.alive.common.adapter3.MetricData)14 MetricKey (com.integrien.alive.common.adapter3.MetricKey)14 ArrayList (java.util.ArrayList)14 ResourceKey (com.integrien.alive.common.adapter3.ResourceKey)13 ResourceIdentifierConfig (com.integrien.alive.common.adapter3.config.ResourceIdentifierConfig)12 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)5 MetricData (com.microsoft.applicationinsights.smoketest.schemav2.MetricData)5 Test (org.junit.Test)5 DataPoint (com.microsoft.applicationinsights.smoketest.schemav2.DataPoint)4 ServerDeviceBean (com.huawei.esight.service.bean.ServerDeviceBean)1 DiscoveryResult (com.integrien.alive.common.adapter3.DiscoveryResult)1 Relationships (com.integrien.alive.common.adapter3.Relationships)1 ResourceConfig (com.integrien.alive.common.adapter3.config.ResourceConfig)1 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)1 DataPointType (com.microsoft.applicationinsights.smoketest.schemav2.DataPointType)1 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNull (org.junit.Assert.assertNull)1