Search in sources :

Example 6 with MetricsData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.

the class HeartbeatTests method heartBeatPayloadContainsDataByDefault.

@Test
void heartBeatPayloadContainsDataByDefault() throws InterruptedException {
    // given
    HeartBeatProvider provider = new HeartBeatProvider();
    provider.initialize(TelemetryClient.createForTest());
    // some of the initialization above happens in a separate thread
    Thread.sleep(500);
    // then
    MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
    assertThat(t).isNotNull();
    assertThat(t.getProperties().size() > 0).isTrue();
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) Test(org.junit.jupiter.api.Test)

Example 7 with MetricsData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.

the class TestUtils method createMetricTelemetry.

public static TelemetryItem createMetricTelemetry(String name, int value, String instrumentationKey) {
    TelemetryItem telemetry = new TelemetryItem();
    telemetry.setVersion(1);
    telemetry.setName("Metric");
    telemetry.setInstrumentationKey(instrumentationKey);
    Map<String, String> tags = new HashMap<>();
    tags.put("ai.internal.sdkVersion", "test_version");
    tags.put("ai.internal.nodeName", "test_role_name");
    tags.put("ai.cloud.roleInstance", "test_cloud_name");
    telemetry.setTags(tags);
    MetricsData data = new MetricsData();
    List<MetricDataPoint> dataPoints = new ArrayList<>();
    MetricDataPoint dataPoint = new MetricDataPoint();
    dataPoint.setDataPointType(DataPointType.MEASUREMENT);
    dataPoint.setName(name);
    dataPoint.setValue(value);
    dataPoint.setCount(1);
    dataPoints.add(dataPoint);
    Map<String, String> properties = new HashMap<>();
    properties.put("state", "blocked");
    data.setMetrics(dataPoints);
    data.setProperties(properties);
    MonitorBase monitorBase = new MonitorBase();
    monitorBase.setBaseType("MetricData");
    monitorBase.setBaseData(data);
    telemetry.setData(monitorBase);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    return telemetry;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) ArrayList(java.util.ArrayList) MonitorBase(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorBase)

Example 8 with MetricsData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.

the class BaseStatsbeat method createStatsbeatTelemetry.

protected TelemetryItem createStatsbeatTelemetry(TelemetryClient telemetryClient, String name, double value) {
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    telemetryClient.initMetricTelemetry(telemetry, data, point);
    // overwrite the default name (which is "Metric")
    telemetry.setName(STATSBEAT_TELEMETRY_NAME);
    point.setName(name);
    point.setValue(value);
    point.setDataPointType(DataPointType.MEASUREMENT);
    telemetry.setInstrumentationKey(telemetryClient.getStatsbeatInstrumentationKey());
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    Map<String, String> properties = new HashMap<>();
    customDimensions.populateProperties(properties, telemetryClient.getInstrumentationKey());
    data.setProperties(properties);
    return telemetry;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Example 9 with MetricsData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.

the class DeadLockDetectorPerformanceCounter method report.

@Override
public void report(TelemetryClient telemetryClient) {
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
    point.setName(METRIC_NAME);
    point.setValue(0);
    point.setDataPointType(DataPointType.MEASUREMENT);
    long[] threadIds = threadBean.findDeadlockedThreads();
    int blockedThreadCount = threadIds == null ? 0 : threadIds.length;
    data.getMetrics().get(0).setValue(blockedThreadCount);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    telemetryClient.trackAsync(telemetry);
    if (blockedThreadCount > 0) {
        sendDetailedMessage(telemetryClient, threadIds);
    }
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Example 10 with MetricsData

use of com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData in project ApplicationInsights-Java by microsoft.

the class BytecodeUtilImpl method trackMetric.

// TODO do not track if perf counter (?)
@Override
public void trackMetric(Date timestamp, String name, double value, Integer count, Double min, Double max, Double stdDev, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    TelemetryClient.getActive().initMetricTelemetry(telemetry, data, point);
    point.setName(name);
    point.setValue(value);
    point.setCount(count);
    point.setMin(min);
    point.setMax(max);
    point.setStdDev(stdDev);
    if (count != null || min != null || max != null || stdDev != null) {
        point.setDataPointType(DataPointType.AGGREGATION);
    } else {
        point.setDataPointType(DataPointType.MEASUREMENT);
    }
    if (!properties.isEmpty()) {
        Map<String, String> existingProperties = data.getProperties();
        if (existingProperties == null) {
            data.setProperties(properties);
        } else {
            existingProperties.putAll(properties);
        }
    }
    if (timestamp != null) {
        telemetry.setTime(FormattedTime.offSetDateTimeFromDate(timestamp));
    } else {
        telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    }
    selectivelySetTags(telemetry, tags);
    if (instrumentationKey != null) {
        telemetry.setInstrumentationKey(instrumentationKey);
    }
    track(telemetry, false);
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)

Aggregations

MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)15 MetricDataPoint (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)8 TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)4 MonitorDomain (com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)2 Map (java.util.Map)2 Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)1 AvailabilityData (com.microsoft.applicationinsights.agent.internal.exporter.models.AvailabilityData)1 MessageData (com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)1 MonitorBase (com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorBase)1 PageViewData (com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewData)1 PageViewPerfData (com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewPerfData)1 RemoteDependencyData (com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)1 RequestData (com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData)1 TelemetryEventData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)1 TelemetryExceptionData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)1 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)1 AlertMetricType (com.microsoft.applicationinsights.alerting.config.AlertMetricType)1 Field (java.lang.reflect.Field)1