/** * <p>hasThresholds</p> * * @param attributes a {@link java.util.Map} object. * @return a boolean. */ public boolean hasThresholds(Map<String, Double> attributes) { if (hasThresholds()) { for (String ds : attributes.keySet()) if (hasThresholds("if", ds)) return true; } return false; }
/** * Should be called when thresholds configuration has been reloaded */ public void refreshThresholds() { if (m_thresholdingSet != null) m_thresholdingSet.reinitialize(); }
setupSnmpInterfaceDatabase(m_db, "127.0.0.1", ifName); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, "127.0.0.1", "HTTP", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); // Global Test Map<String, Double> attributes = new HashMap<String, Double>(); attributes.put("http", 90.0); assertTrue(thresholdingSet.hasThresholds(attributes)); // Datasource Test List<Event> triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 0); for (int i = 1; i <= 3; i++) { LOG.debug("testLatencyThresholdingSet: ------------------------------------ trigger number {}", i); if (thresholdingSet.hasThresholds(attributes)) { triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 0); triggerEvents = thresholdingSet.applyThresholds("http", attributes); for (int i = 4; i <= 5; i++) { LOG.debug("testLatencyThresholdingSet: ------------------------------------ trigger number {}", i); if (thresholdingSet.hasThresholds(attributes)) { triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 0); if (thresholdingSet.hasThresholds(attributes)) { triggerEvents = thresholdingSet.applyThresholds("http", attributes); if (i < 8) assertTrue(triggerEvents.size() == 0);
private void applyThresholds(String rrdPath, MonitoredService service, String dsName, Map<String, Number> entries) { try { if (m_thresholdingSet == null) { RrdRepository repository = new RrdRepository(); repository.setRrdBaseDir(new File(rrdPath)); m_thresholdingSet = new LatencyThresholdingSet(service.getNodeId(), service.getIpAddr(), service.getSvcName(), service.getNodeLocation(), repository, m_resourceStorageDao); } LinkedHashMap<String, Double> attributes = new LinkedHashMap<String, Double>(); for (String ds : entries.keySet()) { Number sampleValue = entries.get(ds); if (sampleValue == null) { attributes.put(ds, Double.NaN); } else { attributes.put(ds, sampleValue.doubleValue()); } } if (m_thresholdingSet.isNodeInOutage()) { LOG.info("applyThresholds: the threshold processing will be skipped because the service {} is on a scheduled outage.", service); } else if (m_thresholdingSet.hasThresholds(attributes)) { List<Event> events = m_thresholdingSet.applyThresholds(dsName, attributes); if (events.size() > 0) { ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(events); proxy.sendAllEvents(); } } } catch(Throwable e) { LOG.error("Failed to threshold on {} for {} because of an exception", service, dsName, e); } }
/** {@inheritDoc} */ public List<Event> applyThresholds(String svcName, Map<String, Double> attributes) { LatencyCollectionResource latencyResource = new LatencyCollectionResource(svcName, m_hostAddress, m_location); LatencyCollectionAttributeType latencyType = new LatencyCollectionAttributeType(); Map<String, CollectionAttribute> attributesMap = new HashMap<String, CollectionAttribute>(); for (final Entry<String, Double> entry : attributes.entrySet()) { final String ds = entry.getKey(); attributesMap.put(ds, new LatencyCollectionAttribute(latencyResource, latencyType, ds, entry.getValue())); } //The timestamp is irrelevant; latency is never a COUNTER (which is the only reason the date is used). //Yes, we have to know a little too much about the implementation details of CollectionResourceWrapper to say that, but // we have little choice CollectionResourceWrapper resourceWrapper = new CollectionResourceWrapper(new Date(), m_nodeId, m_hostAddress, m_serviceName, m_repository, latencyResource, attributesMap, m_resourceStorageDao); return Collections.unmodifiableList(applyThresholds(resourceWrapper, attributesMap)); }
@Test @JUnitTemporaryDatabase(tempDbClass=MockDatabase.class) public void testBug3488() throws Exception { String ipAddress = "127.0.0.1"; setupSnmpInterfaceDatabase(m_db, ipAddress, null); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, ipAddress, "HTTP", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); // Global Test Map<String, Double> attributes = new HashMap<String, Double>(); attributes.put("http", 200.0); assertTrue(thresholdingSet.hasThresholds(attributes)); // Datasource Test List<Event> triggerEvents = new ArrayList<>(); for (int i=0; i<5; i++) triggerEvents.addAll(thresholdingSet.applyThresholds("http", attributes)); assertTrue(triggerEvents.size() == 1); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "HTTP", 5, 100.0, 50.0, 200.0, IfLabel.NO_IFLABEL, "127.0.0.1[http]", "http", IfLabel.NO_IFLABEL, null, m_eventIpcManager.getEventAnticipator(), m_anticipatedEvents); ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.sendAllEvents(); verifyEvents(0); }
setupSnmpInterfaceDatabase(m_db, "127.0.0.1", ifName); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, "127.0.0.1", "HTTP", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); // Global Test Map<String, Double> attributes = new HashMap<String, Double>(); attributes.put("http", 90.0); assertTrue(thresholdingSet.hasThresholds(attributes)); // Datasource Test List<Event> triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 0); for (int i = 1; i < 5; i++) { LOG.debug("testLatencyThresholdingSet: run number {}", i); if (thresholdingSet.hasThresholds(attributes)) { triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 0); if (thresholdingSet.hasThresholds(attributes)) { LOG.debug("testLatencyThresholdingSet: run number 5"); triggerEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(triggerEvents.size() == 1); if (thresholdingSet.hasThresholds(attributes)) { attributes.put("http", 40.0); rearmEvents = thresholdingSet.applyThresholds("http", attributes); assertTrue(rearmEvents.size() == 1);
@Test @JUnitTemporaryDatabase(tempDbClass=MockDatabase.class) public void testBug3575() throws Exception { initFactories("/threshd-configuration-bug3575.xml","/test-thresholds-bug3575.xml"); String ipAddress = "127.0.0.1"; String ifName = "eth0"; setupSnmpInterfaceDatabase(m_db, ipAddress, ifName); LatencyThresholdingSet thresholdingSet = new LatencyThresholdingSet(1, ipAddress, "StrafePing", null, getRepository(), m_resourceStorageDao); assertTrue(thresholdingSet.hasThresholds()); Map<String, Double> attributes = new HashMap<String, Double>(); for (double i=1; i<21; i++) { attributes.put("ping" + i, 2 * i); } attributes.put("loss", 60.0); attributes.put("median", 100.0); attributes.put(PollStatus.PROPERTY_RESPONSE_TIME, 100.0); assertTrue(thresholdingSet.hasThresholds(attributes)); List<Event> triggerEvents = thresholdingSet.applyThresholds("StrafePing", attributes); assertTrue(triggerEvents.size() == 1); addEvent(EventConstants.HIGH_THRESHOLD_EVENT_UEI, "127.0.0.1", "StrafePing", 1, 50.0, 25.0, 60.0, ifName, "127.0.0.1[StrafePing]", "loss", "eth0", null, m_eventIpcManager.getEventAnticipator(), m_anticipatedEvents); ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(triggerEvents); proxy.sendAllEvents(); verifyEvents(0); }