Search in sources :

Example 1 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.

the class ProfilerServiceTest method getJfrDaemon.

private JfrProfiler getJfrDaemon(AtomicBoolean profileInvoked) throws MalformedURLException {
    return new JfrProfiler(new ServiceProfilerServiceConfig(1, 2, 3, new URL("http://localhost"), null, null, LocalFileSystemUtils.getTempDir())) {

        @Override
        protected void profileAndUpload(AlertBreach alertBreach, Duration duration) {
            profileInvoked.set(true);
            Recording recording = Mockito.mock(Recording.class);
            uploadNewRecording(alertBreach, Instant.now()).accept(recording);
        }

        @Override
        protected File createJfrFile(Recording recording, Instant recordingStart, Instant recordingEnd) throws IOException {
            return File.createTempFile("jfrFile", jfrExtension);
        }
    };
}
Also used : ServiceProfilerServiceConfig(com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig) AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach) Instant(java.time.Instant) JfrProfiler(com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler) Duration(java.time.Duration) Recording(com.microsoft.jfr.Recording) URL(java.net.URL)

Example 2 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach 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 3 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.

the class JfrProfiler method performPeriodicProfile.

/**
 * Action to be performed on a periodic profile request.
 */
public void performPeriodicProfile() {
    LOGGER.info("Received periodic profile request");
    profileAndUpload(new AlertBreach(AlertMetricType.PERIODIC, 0, periodicConfig), Duration.ofSeconds(periodicConfig.getProfileDuration()));
}
Also used : AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach)

Example 4 with AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach 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 AlertBreach

use of com.microsoft.applicationinsights.alerting.alert.AlertBreach in project ApplicationInsights-Java by microsoft.

the class AlertPipelineTrigger method accept.

@Override
public void accept(Double telemetry) {
    if (alertConfig.isEnabled() && telemetry > alertConfig.getThreshold()) {
        if (isOffCooldown()) {
            lastAlertTime = ZonedDateTime.now();
            action.accept(new AlertBreach(alertConfig.getType(), telemetry, alertConfig));
        }
    }
}
Also used : AlertBreach(com.microsoft.applicationinsights.alerting.alert.AlertBreach)

Aggregations

AlertBreach (com.microsoft.applicationinsights.alerting.alert.AlertBreach)7 CollectionPlanConfiguration (com.microsoft.applicationinsights.alerting.config.CollectionPlanConfiguration)3 Test (org.junit.jupiter.api.Test)3 AlertingConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration)2 AlertConfiguration (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfiguration)2 DefaultConfiguration (com.microsoft.applicationinsights.alerting.config.DefaultConfiguration)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AlertingSubsystem (com.microsoft.applicationinsights.alerting.AlertingSubsystem)1 AlertConfigurationBuilder (com.microsoft.applicationinsights.alerting.config.AlertingConfiguration.AlertConfigurationBuilder)1 ServiceProfilerServiceConfig (com.microsoft.applicationinsights.profiler.config.ServiceProfilerServiceConfig)1 JfrProfiler (com.microsoft.applicationinsights.serviceprofilerapi.profiler.JfrProfiler)1 GcEventConsumer (com.microsoft.gcmonitor.GcEventConsumer)1 GcMonitorFactory (com.microsoft.gcmonitor.GcMonitorFactory)1 Recording (com.microsoft.jfr.Recording)1 URL (java.net.URL)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 MBeanServerConnection (javax.management.MBeanServerConnection)1