Search in sources :

Example 1 with MetricsData

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

the class CustomDimensionsTest method testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions.

@Test
public void testCustomDimensionsConfigShouldNotImpactStatsbeatCustomDimensions() {
    Configuration configuration = new Configuration();
    configuration.customDimensions.put("firstTag", "abc");
    configuration.customDimensions.put("secondTag", "def");
    TelemetryClient telemetryClient = TelemetryClient.builder().setCustomDimensions(configuration.customDimensions).build();
    NetworkStatsbeat networkStatsbeat = new NetworkStatsbeat();
    TelemetryItem networkItem = networkStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-network", 0.0);
    assertThat(networkItem.getTags()).doesNotContainKey("firstTag");
    assertThat(networkItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) networkItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
    AttachStatsbeat attachStatsbeat = new AttachStatsbeat(new CustomDimensions());
    TelemetryItem attachItem = attachStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-attach", 0.0);
    assertThat(attachItem.getTags()).doesNotContainKey("firstTag");
    assertThat(attachItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) attachItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
    FeatureStatsbeat featureStatsbeat = new FeatureStatsbeat(new CustomDimensions(), FeatureType.FEATURE);
    TelemetryItem featureItem = featureStatsbeat.createStatsbeatTelemetry(telemetryClient, "test-feature", 0.0);
    assertThat(featureItem.getTags()).doesNotContainKey("firstTag");
    assertThat(featureItem.getTags()).doesNotContainKey("secondTag");
    assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("firstTag");
    assertThat(((MetricsData) featureItem.getData().getBaseData()).getProperties()).doesNotContainKey("secondTag");
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) Configuration(com.microsoft.applicationinsights.agent.internal.configuration.Configuration) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) TelemetryClient(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient) Test(org.junit.jupiter.api.Test)

Example 2 with MetricsData

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

the class HeartBeatProvider method gatherData.

/**
 * Creates and returns the heartbeat telemetry.
 *
 * @return Metric Telemetry which represent heartbeat.
 */
// visible for testing
TelemetryItem gatherData() {
    Map<String, String> properties = new HashMap<>();
    double numHealthy = 0;
    for (Map.Entry<String, HeartBeatPropertyPayload> entry : heartbeatProperties.entrySet()) {
        HeartBeatPropertyPayload payload = entry.getValue();
        properties.put(entry.getKey(), payload.getPayloadValue());
        numHealthy += payload.isHealthy() ? 0 : 1;
    }
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    telemetryClient.initMetricTelemetry(telemetry, data, point);
    point.setName(HEARTBEAT_SYNTHETIC_METRIC_NAME);
    point.setValue(numHealthy);
    point.setDataPointType(DataPointType.MEASUREMENT);
    data.setProperties(properties);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    return telemetry;
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 3 with MetricsData

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

the class TelemetryClient method trackAsync.

public void trackAsync(TelemetryItem telemetry) {
    if (Strings.isNullOrEmpty(instrumentationKey)) {
        return;
    }
    MonitorDomain data = telemetry.getData().getBaseData();
    if (data instanceof MetricsData) {
        MetricsData metricsData = (MetricsData) data;
        if (metricsData.getMetrics().isEmpty()) {
            throw new AssertionError("MetricsData has no metric point");
        }
        MetricDataPoint point = metricsData.getMetrics().get(0);
        String metricName = point.getName();
        if (!nonFilterableMetricNames.contains(metricName)) {
            for (MetricFilter metricFilter : metricFilters) {
                if (!metricFilter.matches(metricName)) {
                    // user configuration filtered out this metric name
                    return;
                }
            }
        }
        if (!Double.isFinite(point.getValue())) {
            // breeze doesn't like these values
            return;
        }
    }
    if (telemetry.getTime() == null) {
        // this is easy to forget when adding new telemetry
        throw new AssertionError("telemetry item is missing time");
    }
    QuickPulseDataCollector.INSTANCE.add(telemetry);
    TelemetryObservers.INSTANCE.getObservers().forEach(consumer -> consumer.accept(telemetry));
    // only that it was successfully delivered to the next layer
    if (data instanceof MetricsData) {
        getMetricsChannelBatcher().trackAsync(telemetry);
    } else {
        getGeneralChannelBatcher().trackAsync(telemetry);
    }
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MonitorDomain(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)

Example 4 with MetricsData

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

the class TelemetryUtil method getProperties.

// TODO (trask) Azure SDK: can we move getProperties up to MonitorDomain, or if not, a common
// interface?
public static Map<String, String> getProperties(MonitorDomain data) {
    if (data instanceof AvailabilityData) {
        AvailabilityData availabilityData = (AvailabilityData) data;
        Map<String, String> properties = availabilityData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            availabilityData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof MessageData) {
        MessageData messageData = (MessageData) data;
        Map<String, String> properties = messageData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            messageData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof MetricsData) {
        MetricsData metricsData = (MetricsData) data;
        Map<String, String> properties = metricsData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            metricsData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof PageViewData) {
        PageViewData pageViewData = (PageViewData) data;
        Map<String, String> properties = pageViewData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            pageViewData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof PageViewPerfData) {
        PageViewPerfData pageViewPerfData = (PageViewPerfData) data;
        Map<String, String> properties = pageViewPerfData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            pageViewPerfData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof RemoteDependencyData) {
        RemoteDependencyData remoteDependencyData = (RemoteDependencyData) data;
        Map<String, String> properties = remoteDependencyData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            remoteDependencyData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof RequestData) {
        RequestData requestData = (RequestData) data;
        Map<String, String> properties = requestData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            requestData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof TelemetryEventData) {
        TelemetryEventData eventData = (TelemetryEventData) data;
        Map<String, String> properties = eventData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            eventData.setProperties(properties);
        }
        return properties;
    } else if (data instanceof TelemetryExceptionData) {
        TelemetryExceptionData exceptionData = (TelemetryExceptionData) data;
        Map<String, String> properties = exceptionData.getProperties();
        if (properties == null) {
            properties = new HashMap<>();
            exceptionData.setProperties(properties);
        }
        return properties;
    } else {
        throw new IllegalArgumentException("Unexpected type: " + data.getClass().getName());
    }
}
Also used : AvailabilityData(com.microsoft.applicationinsights.agent.internal.exporter.models.AvailabilityData) PageViewPerfData(com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewPerfData) HashMap(java.util.HashMap) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData) RemoteDependencyData(com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData) PageViewData(com.microsoft.applicationinsights.agent.internal.exporter.models.PageViewData) MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) RequestData(com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData) HashMap(java.util.HashMap) Map(java.util.Map) TelemetryExceptionData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData) TelemetryEventData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)

Example 5 with MetricsData

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

the class HeartbeatTests method heartBeatPayloadContainsSpecificProperties.

@Test
void heartBeatPayloadContainsSpecificProperties() {
    // given
    HeartBeatProvider provider = new HeartBeatProvider();
    provider.initialize(TelemetryClient.createForTest());
    // then
    assertThat(provider.addHeartBeatProperty("test", "testVal", true)).isTrue();
    MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
    assertThat(t.getProperties().get("test")).isEqualTo("testVal");
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) Test(org.junit.jupiter.api.Test)

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