Search in sources :

Example 1 with CollectionPlanConfiguration

use of com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystemTest method manualAlertDoesNotTriggerAfterExpired.

@Test
void manualAlertDoesNotTriggerAfterExpired() {
    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().minus(100, ChronoUnit.SECONDS), 120, "a-settings-moniker")));
    assertThat(called.get()).isNull();
}
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 2 with CollectionPlanConfiguration

use of com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystemTest method getAlertMonitor.

private static AlertingSubsystem getAlertMonitor(Consumer<AlertBreach> consumer) {
    AlertingSubsystem monitor = AlertingSubsystem.create(consumer, Executors.newSingleThreadExecutor());
    monitor.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(), 120, "a-settings-moniker")));
    return monitor;
}
Also used : 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)

Example 3 with CollectionPlanConfiguration

use of com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertConfigParserTest method saneDataIsParsed.

@Test
void saneDataIsParsed() {
    AlertingConfiguration config = AlertConfigParser.parse("--cpu-trigger-enabled true --cpu-threshold 80 --cpu-trigger-profilingDuration 30 --cpu-trigger-cooldown 14400", "--memory-trigger-enabled true --memory-threshold 20 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400", "--sampling-enabled true --sampling-rate 5 --sampling-profiling-duration 120", "--single --mode immediate --immediate-profiling-duration 120  --expiration 5249157885138288517 --settings-moniker a-settings-moniker");
    assertThat(config.getCpuAlert()).isEqualTo(new AlertConfiguration(AlertMetricType.CPU, true, 80, 30, 14400));
    assertThat(config.getMemoryAlert()).isEqualTo(new AlertConfiguration(AlertMetricType.CPU, true, 20, 120, 14400));
    assertThat(config.getDefaultConfiguration()).isEqualTo(new DefaultConfiguration(true, 5, 120));
    assertThat(config.getCollectionPlanConfiguration()).isEqualTo(new CollectionPlanConfiguration(true, EngineMode.immediate, CollectionPlanConfigurationBuilder.parseBinaryDate(5249157885138288517L), 120, "a-settings-moniker"));
}
Also used : 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 4 with CollectionPlanConfiguration

use of com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystem method evaluateManualTrigger.

/**
 * Determine if a manual alert has been requested.
 */
private void evaluateManualTrigger(AlertingConfiguration alertConfig) {
    CollectionPlanConfiguration config = alertConfig.getCollectionPlanConfiguration();
    boolean shouldTrigger = config.isSingle() && config.getMode() == EngineMode.immediate && ZonedDateTime.now().isBefore(config.getExpiration()) && !manualTriggersExecuted.contains(config.getSettingsMoniker());
    if (shouldTrigger) {
        manualTriggersExecuted.add(config.getSettingsMoniker());
        AlertBreach alertBreach = new AlertBreach(AlertMetricType.MANUAL, 0.0, new AlertConfigurationBuilder().setType(AlertMetricType.MANUAL).setEnabled(true).setProfileDuration(config.getImmediateProfilingDuration()).setThreshold(0.0f).setCooldown(0).createAlertConfiguration());
        alertHandler.accept(alertBreach);
    }
}
Also used : AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) AlertConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)

Example 5 with CollectionPlanConfiguration

use of com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration in project ApplicationInsights-Java by microsoft.

the class AlertingSubsystem method create.

public static AlertingSubsystem create(Consumer<AlertBreach> alertHandler, ExecutorService executorService) {
    AlertingSubsystem alertingSubsystem = new AlertingSubsystem(alertHandler, executorService);
    // init with disabled config
    alertingSubsystem.initialize(new AlertingConfiguration(new AlertConfigurationBuilder().setType(AlertMetricType.CPU).setEnabled(false).setThreshold(0).setProfileDuration(0).setCooldown(0).createAlertConfiguration(), new AlertConfigurationBuilder().setType(AlertMetricType.MEMORY).setEnabled(false).setThreshold(0).setProfileDuration(0).setCooldown(0).createAlertConfiguration(), new DefaultConfiguration(false, 0, 0), new CollectionPlanConfiguration(false, EngineMode.immediate, ZonedDateTime.now(), 0, "")));
    return alertingSubsystem;
}
Also used : DefaultConfiguration(com.microsoft.applicationinsights.alerting.config.DefaultConfiguration) CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) AlertingConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration) AlertConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)

Aggregations

CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)6 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)5 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)5 AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)4 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)3 Test (org.junit.jupiter.api.Test)3 AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2