Search in sources :

Example 1 with AlertConfigurationBuilder

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

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

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

Example 4 with AlertConfigurationBuilder

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

the class AlertConfigParser method parseFromMemory.

public static AlertConfiguration parseFromMemory(String memoryConfig) {
    if (memoryConfig == null) {
        return new AlertConfiguration(AlertMetricType.MEMORY, false, 0f, 0, 0);
    }
    String[] tokens = memoryConfig.split(" ");
    Map<String, ParseConfigValue<AlertConfigurationBuilder>> parsers = new HashMap<>();
    parsers.put("memory-threshold", new ParseConfigValue<>(true, (config, arg) -> config.setThreshold(Float.parseFloat(arg))));
    parsers.put("memory-trigger-cooldown", new ParseConfigValue<>(true, (config, arg) -> config.setCooldown(Long.parseLong(arg))));
    parsers.put("memory-trigger-profilingDuration", new ParseConfigValue<>(true, (config, arg) -> config.setProfileDuration(Long.parseLong(arg))));
    parsers.put("memory-trigger-enabled", new ParseConfigValue<>(true, (config, arg) -> config.setEnabled(Boolean.parseBoolean(arg))));
    return parseConfig(new AlertConfigurationBuilder(), tokens, parsers).setType(AlertMetricType.MEMORY).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)

Aggregations

AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)4 CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)4 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)3 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)3 AlertMetricType (com.microsoft.applicationinsights.alerting.config.AlertMetricType)2 AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)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 AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)1