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