Search in sources :

Example 6 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystemTest method manualAlertWorks.

@Test
void manualAlertWorks() {
    AtomicReference<AlertBreach> called = new AtomicReference<>();
    Consumer<AlertBreach> consumer = called::set;
    AlertingSubsystem service = AlertingSubsystem.create(consumer, Executors.newSingleThreadExecutor());
    service.updateConfiguration(new AlertingConfiguration(new AlertConfiguration(AlertMetricType.CPU, true, 80, 30, 14400), new AlertConfiguration(AlertMetricType.MEMORY, true, 20, 120, 14400), new DefaultConfiguration(true, 5, 120), new CollectionPlanConfiguration(true, EngineMode.immediate, ZonedDateTime.now().plus(100, ChronoUnit.SECONDS), 120, "a-settings-moniker")));
    assertThat(called.get().getType()).isEqualTo(AlertMetricType.MANUAL);
}
Also used : AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultConfiguration(com.microsoft.applicationinsights.alerting.config.DefaultConfiguration) CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) AlertingConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration) Test(org.junit.jupiter.api.Test)

Example 7 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.

the class GcEventMonitorTest method endToEndAlertIsTriggered.

@Test
void endToEndAlertIsTriggered() throws ExecutionException, InterruptedException, TimeoutException {
    CompletableFuture<AlertBreach> alertFuture = new CompletableFuture<>();
    AlertingSubsystem alertingSubsystem = getAlertingSubsystem(alertFuture);
    GcMonitorFactory factory = new GcMonitorFactory() {

        @Override
        public MemoryManagement monitorSelf(ExecutorService executorService, GcEventConsumer consumer) {
            consumer.accept(mockGcEvent());
            return null;
        }

        @Override
        public MemoryManagement monitor(MBeanServerConnection connection, ExecutorService executorService, GcEventConsumer consumer) {
            return null;
        }
    };
    GcEventMonitor.init(alertingSubsystem, TelemetryClient.createForTest(), Executors.newSingleThreadExecutor(), new GcEventMonitor.GcEventMonitorConfiguration(GcReportingLevel.NONE), factory);
    AlertBreach alert = alertFuture.get(10, TimeUnit.SECONDS);
    assertThat(alert.getAlertValue()).isEqualTo(90.0);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) GcEventConsumer(com.microsoft.gcmonitor.GcEventConsumer) AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) ExecutorService(java.util.concurrent.ExecutorService) AlertingSubsystem(com.microsoft.applicationinsights.alerting.AlertingSubsystem) MBeanServerConnection(javax.management.MBeanServerConnection) GcMonitorFactory(com.microsoft.gcmonitor.GcMonitorFactory) Test(org.junit.jupiter.api.Test)

Aggregations

AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)7 CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)3 Test (org.junit.jupiter.api.Test)3 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)2 AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)2 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AlertingSubsystem (com.microsoft.applicationinsights.alerting.AlertingSubsystem)1 AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)1 ServiceProfilerServiceConfig (com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig)1 JfrProfiler (com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler)1 GcEventConsumer (com.microsoft.gcmonitor.GcEventConsumer)1 GcMonitorFactory (com.microsoft.gcmonitor.GcMonitorFactory)1 Recording (com.microsoft.jfr.Recording)1 URL (java.net.URL)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 MBeanServerConnection (javax.management.MBeanServerConnection)1