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