Search in sources :

Example 46 with TelemetryItem

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

the class GcEventMonitor method emitGcEvent.

/**
 * If gc reporting is enabled, send gc event to Application Insights.
 */
private static void emitGcEvent(TelemetryClient telemetryClient, GcEventMonitorConfiguration gcEventMonitorConfiguration, GcCollectionEvent event) {
    boolean reportEvent = gcEventMonitorConfiguration.reportingLevel == GcReportingLevel.ALL;
    reportEvent |= gcEventMonitorConfiguration.reportingLevel == GcReportingLevel.TENURED_ONLY && event.getCollector().isTenuredCollector();
    if (!reportEvent) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    TelemetryEventData data = new TelemetryEventData();
    TelemetryClient.getActive().initEventTelemetry(telemetry, data);
    data.setName("GcEvent");
    Map<String, String> properties = new HashMap<>();
    properties.put("collector", event.getCollector().getName());
    properties.put("type", event.getGcCause());
    properties.put("action", event.getGcAction());
    properties.put("jvm_instance_id", JVM_INSTANCE_UID);
    data.setProperties(properties);
    Map<String, Double> measurements = new HashMap<>();
    measurements.put("id", (double) event.getId());
    measurements.put("duration_ms", (double) event.getDuration());
    measurements.put("end_time_ms", (double) event.getEndTime());
    measurements.put("thread_count", (double) event.getGcThreadCount());
    measurements.put("collection_count", (double) event.getCollector().getCollectionCount());
    measurements.put("cumulative_collector_time_sec", (double) event.getCollector().getCollectionTime());
    addMemoryUsage("young", "before", measurements, event.getMemoryUsageBeforeGc(event.getYoungPools()));
    addMemoryUsage("young", "after", measurements, event.getMemoryUsageAfterGc(event.getYoungPools()));
    Optional<MemoryPool> tenuredPool = event.getTenuredPool();
    if (tenuredPool.isPresent()) {
        MemoryUsage beforeOg = event.getMemoryUsageBeforeGc(tenuredPool.get());
        addMemoryUsage("tenured", "before", measurements, beforeOg);
        MemoryUsage afterOg = event.getMemoryUsageAfterGc(tenuredPool.get());
        addMemoryUsage("tenured", "after", measurements, afterOg);
    }
    data.setMeasurements(measurements);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    telemetryClient.trackAsync(telemetry);
}
Also used : HashMap(java.util.HashMap) TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MemoryUsage(java.lang.management.MemoryUsage) TelemetryEventData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData) MemoryPool(com.microsoft.gcmonitor.memorypools.MemoryPool)

Example 47 with TelemetryItem

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

the class ProfilerServiceInitializer method sendMessageTelemetry.

private static void sendMessageTelemetry(TelemetryClient telemetryClient, String message) {
    TelemetryItem telemetry = new TelemetryItem();
    MessageData data = new MessageData();
    telemetryClient.initMessageTelemetry(telemetry, data);
    data.setMessage(message);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)

Example 48 with TelemetryItem

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

the class FeatureStatsbeat method send.

@Override
protected void send(TelemetryClient telemetryClient) {
    String metricName = FEATURE_METRIC_NAME;
    long encodedLong;
    String featureType;
    if (type == FeatureType.FEATURE) {
        encodedLong = getFeature();
        featureType = "0";
    } else {
        encodedLong = getInstrumentation();
        featureType = "1";
    }
    TelemetryItem telemetryItem = createStatsbeatTelemetry(telemetryClient, metricName, 0);
    Map<String, String> properties = TelemetryUtil.getProperties(telemetryItem.getData().getBaseData());
    properties.put("feature", String.valueOf(encodedLong));
    properties.put("type", featureType);
    telemetryClient.trackStatsbeatAsync(telemetryItem);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 49 with TelemetryItem

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

the class NetworkStatsbeat method sendIntervalMetric.

private void sendIntervalMetric(TelemetryClient telemetryClient, String ikey, IntervalMetrics local, String host) {
    if (local.requestSuccessCount.get() != 0) {
        TelemetryItem requestSuccessCountSt = createStatsbeatTelemetry(telemetryClient, REQUEST_SUCCESS_COUNT_METRIC_NAME, local.requestSuccessCount.get());
        addCommonProperties(requestSuccessCountSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(requestSuccessCountSt);
    }
    if (local.requestFailureCount.get() != 0) {
        TelemetryItem requestFailureCountSt = createStatsbeatTelemetry(telemetryClient, REQUEST_FAILURE_COUNT_METRIC_NAME, local.requestFailureCount.get());
        addCommonProperties(requestFailureCountSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(requestFailureCountSt);
    }
    double durationAvg = local.getRequestDurationAvg();
    if (durationAvg != 0) {
        TelemetryItem requestDurationSt = createStatsbeatTelemetry(telemetryClient, REQUEST_DURATION_METRIC_NAME, durationAvg);
        addCommonProperties(requestDurationSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(requestDurationSt);
    }
    if (local.retryCount.get() != 0) {
        TelemetryItem retryCountSt = createStatsbeatTelemetry(telemetryClient, RETRY_COUNT_METRIC_NAME, local.retryCount.get());
        addCommonProperties(retryCountSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(retryCountSt);
    }
    if (local.throttlingCount.get() != 0) {
        TelemetryItem throttleCountSt = createStatsbeatTelemetry(telemetryClient, THROTTLE_COUNT_METRIC_NAME, local.throttlingCount.get());
        addCommonProperties(throttleCountSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(throttleCountSt);
    }
    if (local.exceptionCount.get() != 0) {
        TelemetryItem exceptionCountSt = createStatsbeatTelemetry(telemetryClient, EXCEPTION_COUNT_METRIC_NAME, local.exceptionCount.get());
        addCommonProperties(exceptionCountSt, ikey, host);
        telemetryClient.trackStatsbeatAsync(exceptionCountSt);
    }
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 50 with TelemetryItem

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

the class IntegrationTests method integrationTest.

@Test
public void integrationTest() throws Exception {
    List<TelemetryItem> telemetryItems = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        TelemetryItem item = TestUtils.createMetricTelemetry("metric" + i, i, INSTRUMENTATION_KEY);
        item.setTime(OffsetDateTime.parse("2021-11-09T03:12:19.06Z"));
        telemetryItems.add(item);
    }
    ExecutorService executorService = Executors.newFixedThreadPool(10);
    for (int i = 0; i < 10; i++) {
        executorService.execute(() -> {
            for (int j = 0; j < 10; j++) {
                CompletableResultCode completableResultCode = telemetryChannel.send(telemetryItems);
                completableResultCode.join(10, SECONDS);
                assertThat(completableResultCode.isSuccess()).isFalse();
            }
        });
    }
    executorService.shutdown();
    executorService.awaitTermination(10, TimeUnit.MINUTES);
    Thread.sleep(1000);
    assertThat(localFileCache.getPersistedFilesCache().size()).isEqualTo(100);
    for (int i = 100; i > 0; i--) {
        LocalFileLoader.PersistedFile file = localFileLoader.loadTelemetriesFromDisk();
        assertThat(ungzip(file.rawBytes.array())).isEqualTo(new String(getByteBufferFromFile("ungzip-source.txt").array(), UTF_8));
        assertThat(file.instrumentationKey).isEqualTo(INSTRUMENTATION_KEY);
        assertThat(localFileCache.getPersistedFilesCache().size()).isEqualTo(i - 1);
    }
    assertThat(localFileCache.getPersistedFilesCache().size()).isEqualTo(0);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.jupiter.api.Test)

Aggregations

TelemetryItem (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)51 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)9 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)8 MetricsData (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData)7 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)7 HashMap (java.util.HashMap)7 MetricDataPoint (com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint)6 MessageData (com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)5 TelemetryExceptionData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryExceptionData)4 RemoteDependencyData (com.microsoft.applicationinsights.agent.internal.exporter.models.RemoteDependencyData)3 RequestData (com.microsoft.applicationinsights.agent.internal.exporter.models.RequestData)3 TelemetryEventData (com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)3 FinalCounters (com.microsoft.applicationinsights.agent.internal.quickpulse.QuickPulseDataCollector.FinalCounters)3 Attributes (io.opentelemetry.api.common.Attributes)3 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)3 MemoryUsage (java.lang.management.MemoryUsage)3 Date (java.util.Date)3 HttpRequest (com.azure.core.http.HttpRequest)1 SerializedString (com.fasterxml.jackson.core.io.SerializedString)1