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