Search in sources :

Example 6 with AlertConfiguration

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

the class AlertConfigParser method parseFromCpu.

public static AlertConfiguration parseFromCpu(String cpuConfig) {
    if (cpuConfig == null) {
        return new AlertConfiguration(AlertMetricType.CPU, false, 0f, 0, 0);
    }
    String[] tokens = cpuConfig.split(" ");
    Map<String, ParseConfigValue<AlertConfigurationBuilder>> parsers = new HashMap<>();
    parsers.put("cpu-threshold", new ParseConfigValue<>(true, (config, arg) -> config.setThreshold(Float.parseFloat(arg))));
    parsers.put("cpu-trigger-cooldown", new ParseConfigValue<>(true, (config, arg) -> config.setCooldown(Long.parseLong(arg))));
    parsers.put("cpu-trigger-profilingDuration", new ParseConfigValue<>(true, (config, arg) -> config.setProfileDuration(Long.parseLong(arg))));
    parsers.put("cpu-trigger-enabled", new ParseConfigValue<>(true, (config, arg) -> config.setEnabled(Boolean.parseBoolean(arg))));
    return parseConfig(new AlertConfigurationBuilder(), tokens, parsers).setType(AlertMetricType.CPU).createAlertConfiguration();
}
Also used : CollectionPlanConfiguration(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration) EngineMode(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration.EngineMode) DefaultConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.DefaultConfigurationBuilder) HashMap(java.util.HashMap) Instant(java.time.Instant) CollectionPlanConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.CollectionPlanConfigurationBuilder) DefaultConfiguration(com.microsoft.applicationinsights.alerting.config.DefaultConfiguration) ProfilerConfiguration(com.microsoft.applicationinsights.profiler.ProfilerConfiguration) Map(java.util.Map) AlertConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder) AlertMetricType(com.microsoft.applicationinsights.alerting.config.AlertMetricType) AlertingConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration) ZoneOffset(java.time.ZoneOffset) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) HashMap(java.util.HashMap) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) AlertConfigurationBuilder(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)

Example 7 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration 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 8 with AlertConfiguration

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

the class AlertTriggerTest method doesNotReTriggerDueToCooldown.

@Test
void doesNotReTriggerDueToCooldown() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1000);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isTrue();
    called.set(false);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.1);
    }
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.51);
    }
    assertThat(called.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with AlertConfiguration

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

the class AlertTriggerTest method underThresholdDataDoesNotTrigger.

@Test
void underThresholdDataDoesNotTrigger() {
    AlertConfiguration config = new AlertConfiguration(AlertMetricType.CPU, true, 0.5f, 1, 1000);
    AtomicBoolean called = new AtomicBoolean(false);
    AlertPipelineTrigger trigger = getAlertTrigger(config, called);
    for (int i = 0; i < 100; i++) {
        trigger.accept(0.4);
    }
    assertThat(called.get()).isFalse();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AlertPipelineTrigger(com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger) AlertConfiguration(com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration) Test(org.junit.jupiter.api.Test)

Example 10 with AlertConfiguration

use of com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration 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)

Aggregations

AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)11 Test (org.junit.jupiter.api.Test)7 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)6 CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)6 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)6 AlertPipelineTrigger (com.microsoft.applicationinsights.alerting.analysis.AlertPipelineTrigger)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)2 AlertMetricType (com.microsoft.applicationinsights.alerting.config.AlertMetricType)2 AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)2 EngineMode (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration.EngineMode)2 CollectionPlanConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfigurationBuilder)2 DefaultConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.DefaultConfigurationBuilder)2 ProfilerConfiguration (com.microsoft.applicationinsights.profiler.ProfilerConfiguration)2 Instant (java.time.Instant)2 ZoneOffset (java.time.ZoneOffset)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2