@Test public void testAlertAfter2Failures() throws Exception { Check check = createCheckCheckingMean(2, 6); when(alertingPlugin.getChecks()).thenReturn(Collections.singletonMap(check.getId(), check)); checkMetrics(); verify(alerter, times(0)).alert(any(Alerter.AlertArguments.class)); verify(incidentRepository).createIncident(any(Incident.class)); checkMetrics(); verify(alerter).alert(any(Alerter.AlertArguments.class)); verify(incidentRepository).updateIncident(any(Incident.class)); }
private void checkMetrics(Map<String, Map<MetricName, Metric>> metricsGroupedByName, Check check) { List<CheckResult> checkResults = new LinkedList<CheckResult>(); Map<MetricName, Metric> metricsOfName = metricsGroupedByName.get(check.getTarget().getName()); if (metricsOfName == null) { metricsOfName = Collections.emptyMap(); } for (Map.Entry<MetricName, Metric> entry : metricsOfName.entrySet()) { if (entry.getKey().matches(check.getTarget())) { try { checkResults.addAll(check.check(entry.getKey(), asMap(entry.getValue()))); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } } try { addIncident(check, checkResults); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } }
ThresholdMonitoringReporter extends ScheduledMetrics2Reporter { private void checkMetrics(Map<String, Map<MetricName, Metric>> metricsGroupedByName, Check check) { List<CheckResult> checkResults = new LinkedList<CheckResult>(); Map<MetricName, Metric> metricsOfName = metricsGroupedByName.get(check.getTarget().getName()); if (metricsOfName == null) { metricsOfName = Collections.emptyMap(); } for (Map.Entry<MetricName, Metric> entry : metricsOfName.entrySet()) { if (entry.getKey().matches(check.getTarget())) { try { checkResults.addAll(check.check(entry.getKey(), asMap(entry.getValue()))); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } } try { addIncident(check, checkResults); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } }
ThresholdMonitoringReporter extends ScheduledMetrics2Reporter { private void checkMetrics(Map<String, Map<MetricName, Metric>> metricsGroupedByName, Check check) { List<CheckResult> checkResults = new LinkedList<CheckResult>(); Map<MetricName, Metric> metricsOfName = metricsGroupedByName.get(check.getTarget().getName()); if (metricsOfName == null) { metricsOfName = Collections.emptyMap(); } for (Map.Entry<MetricName, Metric> entry : metricsOfName.entrySet()) { if (entry.getKey().matches(check.getTarget())) { try { checkResults.addAll(check.check(entry.getKey(), asMap(entry.getValue()))); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } } try { addIncident(check, checkResults); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } ThresholdMonitoringReporter(ThresholdMonitoringReporterBuilder builder); }
ThresholdMonitoringReporter extends ScheduledMetrics2Reporter { private void checkMetrics(Map<String, Map<MetricName, Metric>> metricsGroupedByName, Check check) { List<CheckResult> checkResults = new LinkedList<CheckResult>(); Map<MetricName, Metric> metricsOfName = metricsGroupedByName.get(check.getTarget().getName()); if (metricsOfName == null) { metricsOfName = Collections.emptyMap(); } for (Map.Entry<MetricName, Metric> entry : metricsOfName.entrySet()) { if (entry.getKey().matches(check.getTarget())) { try { checkResults.addAll(check.check(entry.getKey(), asMap(entry.getValue()))); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } } try { addIncident(check, checkResults); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } ThresholdMonitoringReporter(ThresholdMonitoringReporterBuilder builder); static ThresholdMonitoringReporterBuilder forRegistry(Metric2Registry registry); @Override void reportMetrics(Map<MetricName, Gauge> gauges, Map<MetricName, Counter> counters, Map<MetricName, Histogram> histograms, Map<MetricName, Meter> meters, Map<MetricName, Timer> timers); }
ThresholdMonitoringReporter extends ScheduledMetrics2Reporter { private void checkMetrics(Map<String, Map<MetricName, Metric>> metricsGroupedByName, Check check) { List<CheckResult> checkResults = new LinkedList<CheckResult>(); Map<MetricName, Metric> metricsOfName = metricsGroupedByName.get(check.getTarget().getName()); if (metricsOfName == null) { metricsOfName = Collections.emptyMap(); } for (Map.Entry<MetricName, Metric> entry : metricsOfName.entrySet()) { if (entry.getKey().matches(check.getTarget())) { try { checkResults.addAll(check.check(entry.getKey(), asMap(entry.getValue()))); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } } try { addIncident(check, checkResults); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); } } ThresholdMonitoringReporter(ThresholdMonitoringReporterBuilder builder); static ThresholdMonitoringReporterBuilder forRegistry(Metric2Registry registry); @Override void reportMetrics(Map<MetricName, Gauge> gauges, Map<MetricName, Counter> counters, Map<MetricName, Histogram> histograms, Map<MetricName, Meter> meters, Map<MetricName, Timer> timers);  }