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