@Test public void testGetCounterValueWithWrap() throws Exception { CollectionAgent agent = createCollectionAgent(); SnmpCollectionResource resource = createNodeResource(agent); Date baseDate = new Date(); String attributeName = "myCounter"; String attributeId = "node[1].resourceType[node].instance[null].metric[" + attributeName + "]"; Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>(); BigInteger initialValue = new BigDecimal(Math.pow(2, 32) - 20000).toBigInteger(); SnmpAttribute attribute = addAttributeToCollectionResource(resource, attributeName, "counter", "0", initialValue); attributes.put(attribute.getName(), attribute); CollectionResourceWrapper wrapper = createWrapper(resource, attributes, baseDate); Assert.assertFalse(CollectionResourceWrapper.s_cache.containsKey(attributeId)); Assert.assertEquals(Double.NaN, wrapper.getAttributeValue(attributeName)); Assert.assertEquals(Double.NaN, wrapper.getAttributeValue(attributeName)); Assert.assertEquals(initialValue.doubleValue(), CollectionResourceWrapper.s_cache.get(attributeId).value); attribute = addAttributeToCollectionResource(resource, attributeName, "counter", "0", new BigInteger("40000")); attributes.put(attribute.getName(), attribute); wrapper = createWrapper(resource, attributes, new Date(baseDate.getTime() + 300000)); Assert.assertEquals(initialValue.doubleValue(), CollectionResourceWrapper.s_cache.get(attributeId).value); Assert.assertEquals(200.0, wrapper.getAttributeValue(attributeName)); Assert.assertEquals(40000.0, CollectionResourceWrapper.s_cache.get(attributeId).value); Assert.assertEquals(200.0, wrapper.getAttributeValue(attributeName)); Assert.assertEquals(40000.0, CollectionResourceWrapper.s_cache.get(attributeId).value); Assert.assertEquals(200.0, wrapper.getAttributeValue(attributeName)); Assert.assertEquals(40000.0, CollectionResourceWrapper.s_cache.get(attributeId).value); EasyMock.verify(agent); }
public Double getAttributeValue(String ds) { if (isAnInterfaceResource() && ("snmpifspeed".equalsIgnoreCase(ds) || "snmpiftype".equalsIgnoreCase(ds))) { String value = getIfInfoValue(ds); if (value != null) { try { return Double.parseDouble(value); } catch (Exception e) { return Double.NaN; } } } if (m_attributes == null || m_attributes.get(ds) == null) { log().info("getAttributeValue: can't find attribute called " + ds + " on " + m_resource); return null; } String numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { log().info("getAttributeValue: can't find numeric value for " + ds + " on " + m_resource); return null; } String id = "node[" + m_nodeId + "].resourceType[" + m_resource.getResourceTypeName() + "].instance[" + m_resource.getLabel() + "].metric[" + ds + "]"; Double current = null; try { current = Double.parseDouble(numValue); } catch (NumberFormatException e) { log().error(id + " does not have a numeric value: " + numValue); return null; } if (m_attributes.get(ds).getType().toLowerCase().startsWith("counter") == false) { if (log().isDebugEnabled()) { log().debug("getAttributeValue: id=" + id + ", value= " + current); } return current; } else { return getCounterValue(id, current); } }
CollectionResourceWrapper { public Double getAttributeValue(String ds) { if (isAnInterfaceResource() && ("snmpifspeed".equalsIgnoreCase(ds) || "snmpiftype".equalsIgnoreCase(ds))) { String value = getIfInfoValue(ds); if (value != null) { try { return Double.parseDouble(value); } catch (Exception e) { return Double.NaN; } } } if (m_attributes == null || m_attributes.get(ds) == null) { log().info("getAttributeValue: can't find attribute called " + ds + " on " + m_resource); return null; } String numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { log().info("getAttributeValue: can't find numeric value for " + ds + " on " + m_resource); return null; } String id = "node[" + m_nodeId + "].resourceType[" + m_resource.getResourceTypeName() + "].instance[" + m_resource.getLabel() + "].metric[" + ds + "]"; Double current = null; try { current = Double.parseDouble(numValue); } catch (NumberFormatException e) { log().error(id + " does not have a numeric value: " + numValue); return null; } if (m_attributes.get(ds).getType().toLowerCase().startsWith("counter") == false) { if (log().isDebugEnabled()) { log().debug("getAttributeValue: id=" + id + ", value= " + current); } return current; } else { return getCounterValue(id, current); } } }
CollectionResourceWrapper { public Double getAttributeValue(String ds) { if (isAnInterfaceResource() && ("snmpifspeed".equalsIgnoreCase(ds) || "snmpiftype".equalsIgnoreCase(ds))) { String value = getIfInfoValue(ds); if (value != null) { try { return Double.parseDouble(value); } catch (Exception e) { return Double.NaN; } } } if (m_attributes == null || m_attributes.get(ds) == null) { log().info("getAttributeValue: can't find attribute called " + ds + " on " + m_resource); return null; } String numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { log().info("getAttributeValue: can't find numeric value for " + ds + " on " + m_resource); return null; } String id = "node[" + m_nodeId + "].resourceType[" + m_resource.getResourceTypeName() + "].instance[" + m_resource.getLabel() + "].metric[" + ds + "]"; Double current = null; try { current = Double.parseDouble(numValue); } catch (NumberFormatException e) { log().error(id + " does not have a numeric value: " + numValue); return null; } if (m_attributes.get(ds).getType().toLowerCase().startsWith("counter") == false) { if (log().isDebugEnabled()) { log().debug("getAttributeValue: id=" + id + ", value= " + current); } return current; } else { return getCounterValue(id, current); } } CollectionResourceWrapper(Date collectionTimestamp, int nodeId, String hostAddress, String serviceName, RrdRepository repository, CollectionResource resource, Map<String, CollectionAttribute> attributes); }
CollectionResourceWrapper { public Double getAttributeValue(String ds) { if (isAnInterfaceResource() && ("snmpifspeed".equalsIgnoreCase(ds) || "snmpiftype".equalsIgnoreCase(ds))) { String value = getIfInfoValue(ds); if (value != null) { try { return Double.parseDouble(value); } catch (Exception e) { return Double.NaN; } } } if (m_attributes == null || m_attributes.get(ds) == null) { log().info("getAttributeValue: can't find attribute called " + ds + " on " + m_resource); return null; } String numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { log().info("getAttributeValue: can't find numeric value for " + ds + " on " + m_resource); return null; } String id = "node[" + m_nodeId + "].resourceType[" + m_resource.getResourceTypeName() + "].instance[" + m_resource.getLabel() + "].metric[" + ds + "]"; Double current = null; try { current = Double.parseDouble(numValue); } catch (NumberFormatException e) { log().error(id + " does not have a numeric value: " + numValue); return null; } if (m_attributes.get(ds).getType().toLowerCase().startsWith("counter") == false) { if (log().isDebugEnabled()) { log().debug("getAttributeValue: id=" + id + ", value= " + current); } return current; } else { return getCounterValue(id, current); } } CollectionResourceWrapper(Date collectionTimestamp, int nodeId, String hostAddress, String serviceName, RrdRepository repository, CollectionResource resource, Map<String, CollectionAttribute> attributes); int getNodeId(); String getHostAddress(); String getServiceName(); RrdRepository getRepository(); String getDsLabel(); void setDsLabel(String dsLabel); String getInstance(); String getInstanceLabel(); String getResourceTypeName(); String getResourceId(); String getIfLabel(); String getIfIndex(); boolean isAnInterfaceResource(); boolean isValidInterfaceResource(); Double getAttributeValue(String ds); String getFieldValue(String ds); @Override String toString(); }
CollectionResourceWrapper { public Double getAttributeValue(String ds) { if (isAnInterfaceResource() && ("snmpifspeed".equalsIgnoreCase(ds) || "snmpiftype".equalsIgnoreCase(ds))) { String value = getIfInfoValue(ds); if (value != null) { try { return Double.parseDouble(value); } catch (Exception e) { return Double.NaN; } } } if (m_attributes == null || m_attributes.get(ds) == null) { log().info("getAttributeValue: can't find attribute called " + ds + " on " + m_resource); return null; } String numValue = m_attributes.get(ds).getNumericValue(); if (numValue == null) { log().info("getAttributeValue: can't find numeric value for " + ds + " on " + m_resource); return null; } String id = "node[" + m_nodeId + "].resourceType[" + m_resource.getResourceTypeName() + "].instance[" + m_resource.getLabel() + "].metric[" + ds + "]"; Double current = null; try { current = Double.parseDouble(numValue); } catch (NumberFormatException e) { log().error(id + " does not have a numeric value: " + numValue); return null; } if (m_attributes.get(ds).getType().toLowerCase().startsWith("counter") == false) { if (log().isDebugEnabled()) { log().debug("getAttributeValue: id=" + id + ", value= " + current); } return current; } else { return getCounterValue(id, current); } } CollectionResourceWrapper(Date collectionTimestamp, int nodeId, String hostAddress, String serviceName, RrdRepository repository, CollectionResource resource, Map<String, CollectionAttribute> attributes); int getNodeId(); String getHostAddress(); String getServiceName(); RrdRepository getRepository(); String getDsLabel(); void setDsLabel(String dsLabel); String getInstance(); String getInstanceLabel(); String getResourceTypeName(); String getResourceId(); String getIfLabel(); String getIfIndex(); boolean isAnInterfaceResource(); boolean isValidInterfaceResource(); Double getAttributeValue(String ds); String getFieldValue(String ds); @Override String toString();  }