Search in sources :

Example 11 with MetricsData

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

the class TelemetryUtil method createMetricsTelemetry.

public static TelemetryItem createMetricsTelemetry(TelemetryClient telemetryClient, String name, double value) {
    TelemetryItem telemetry = new TelemetryItem();
    MetricsData data = new MetricsData();
    MetricDataPoint point = new MetricDataPoint();
    telemetryClient.initMetricTelemetry(telemetry, data, point);
    point.setName(name);
    point.setValue(value);
    point.setDataPointType(DataPointType.MEASUREMENT);
    telemetry.setTime(FormattedTime.offSetDateTimeFromNow());
    return telemetry;
}
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)

Example 12 with MetricsData

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

the class AlertingServiceFactory method addObserver.

private static void addObserver(AlertingSubsystem alertingSubsystem, TelemetryObservers telemetryObservers) {
    telemetryObservers.addObserver(telemetry -> {
        MonitorDomain data = telemetry.getData().getBaseData();
        if (!(data instanceof MetricsData)) {
            return;
        }
        MetricDataPoint point = ((MetricsData) data).getMetrics().get(0);
        AlertMetricType alertMetricType = null;
        if (point.getName().equals(TOTAL_CPU_PC_METRIC_NAME)) {
            alertMetricType = AlertMetricType.CPU;
        }
        if (alertMetricType != null) {
            alertingSubsystem.track(alertMetricType, point.getValue());
        }
    });
}
Also used : MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) AlertMetricType(com.microsoft.applicationinsights.alerting.config.AlertMetricType) MetricDataPoint(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricDataPoint) MonitorDomain(com.microsoft.applicationinsights.agent.internal.exporter.models.MonitorDomain)

Example 13 with MetricsData

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

the class HeartbeatTests method heartbeatMetricIsNonZeroWhenFailureConditionPresent.

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

Example 14 with MetricsData

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

the class HeartbeatTests method cannotAddUnknownDefaultProperty.

@Test
void cannotAddUnknownDefaultProperty() throws Exception {
    DefaultHeartBeatPropertyProvider base = new DefaultHeartBeatPropertyProvider();
    String testKey = "testKey";
    Field field = base.getClass().getDeclaredField("defaultFields");
    field.setAccessible(true);
    Set<String> defaultFields = (Set<String>) field.get(base);
    defaultFields.add(testKey);
    HeartBeatProvider provider = new HeartBeatProvider();
    provider.initialize(TelemetryClient.createForTest());
    base.setDefaultPayload(provider).call();
    MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
    assertThat(t.getProperties().containsKey("testKey")).isFalse();
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) MetricsData(com.microsoft.applicationinsights.agent.internal.exporter.models.MetricsData) Test(org.junit.jupiter.api.Test)

Example 15 with MetricsData

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

the class HeartbeatTests method heartbeatMetricCountsForAllFailures.

@Test
void heartbeatMetricCountsForAllFailures() {
    // given
    HeartBeatProvider provider = new HeartBeatProvider();
    provider.initialize(TelemetryClient.createForTest());
    // then
    assertThat(provider.addHeartBeatProperty("test", "testVal", false)).isTrue();
    assertThat(provider.addHeartBeatProperty("test1", "testVal1", false)).isTrue();
    MetricsData t = (MetricsData) provider.gatherData().getData().getBaseData();
    assertThat(t.getMetrics().get(0).getValue()).isEqualTo(2);
}
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