Search in sources :

Example 11 with TelemetryItem

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

the class JvmHeapMemoryUsedPerformanceCounter method reportHeap.

private static void reportHeap(MemoryMXBean memory, TelemetryClient telemetryClient) {
    MemoryUsage mhu = memory.getHeapMemoryUsage();
    if (mhu != null) {
        long currentHeapUsed = mhu.getUsed() / Megabyte;
        TelemetryItem memoryHeapUsage = TelemetryUtil.createMetricsTelemetry(telemetryClient, HEAP_MEM_USED, currentHeapUsed);
        telemetryClient.trackAsync(memoryHeapUsage);
        float percentage = 100.0f * (((float) mhu.getUsed()) / ((float) mhu.getMax()));
        TelemetryItem memoryHeapUsagePercentage = TelemetryUtil.createMetricsTelemetry(telemetryClient, HEAP_MEM_USED_PERCENTAGE, percentage);
        telemetryClient.trackAsync(memoryHeapUsagePercentage);
    }
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MemoryUsage(java.lang.management.MemoryUsage)

Example 12 with TelemetryItem

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

the class ProcessCpuPerformanceCounter method report.

@Override
public void report(TelemetryClient telemetryClient) {
    if (cpuPerformanceCounterCalculator == null) {
        return;
    }
    Double processCpuUsage = cpuPerformanceCounterCalculator.getProcessCpuUsage();
    if (processCpuUsage == null) {
        return;
    }
    logger.trace("Performance Counter: {}: {}", PROCESS_CPU_PC_METRIC_NAME, processCpuUsage);
    TelemetryItem telemetry = TelemetryUtil.createMetricsTelemetry(telemetryClient, PROCESS_CPU_PC_METRIC_NAME, processCpuUsage);
    telemetryClient.trackAsync(telemetry);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem)

Example 13 with TelemetryItem

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

the class BytecodeUtilImpl method trackEvent.

@Override
public void trackEvent(Date timestamp, String name, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics, String instrumentationKey) {
    if (Strings.isNullOrEmpty(name)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    TelemetryEventData data = new TelemetryEventData();
    TelemetryClient.getActive().initEventTelemetry(telemetry, data);
    data.setName(name);
    data.setMeasurements(metrics);
    // shared
    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, true);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) TelemetryEventData(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryEventData)

Example 14 with TelemetryItem

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

the class BytecodeUtilImpl method trackTrace.

@Override
public void trackTrace(Date timestamp, String message, int severityLevel, Map<String, String> properties, Map<String, String> tags, String instrumentationKey) {
    if (Strings.isNullOrEmpty(message)) {
        return;
    }
    TelemetryItem telemetry = new TelemetryItem();
    MessageData data = new MessageData();
    TelemetryClient.getActive().initMessageTelemetry(telemetry, data);
    data.setMessage(message);
    if (severityLevel != -1) {
        data.setSeverityLevel(getSeverityLevel(severityLevel));
    }
    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, true);
}
Also used : TelemetryItem(com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem) MessageData(com.microsoft.applicationinsights.agent.internal.exporter.models.MessageData)

Example 15 with TelemetryItem

use of com.microsoft.applicationinsights.agent.internal.exporter.models.TelemetryItem 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)

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