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