From da1761e5ed1529eaa416d8b21ac02f76e1d5758c Mon Sep 17 00:00:00 2001 From: BalakrishnaV Date: Tue, 21 Jul 2015 15:12:30 +0530 Subject: [PATCH] Computed delta metrics --- README.md | 7 +-- pom.xml | 7 +-- .../extensions/network/Metrics.java | 2 + .../network/NetworkMetricsCollector.java | 8 ++-- .../extensions/network/NetworkMonitor.java | 47 +++++++++++++++++-- 5 files changed, 58 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 579af39..43a04b7 100644 --- a/README.md +++ b/README.md @@ -73,20 +73,21 @@ echo "name=TCP|State|Listen,value=" `netstat -an | grep -i LISTEN | wc -l` ##Metrics Metric path is typically: **Application Infrastructure Performance|\|Custom Metrics|Network|** followed by the individual metrics below: +Metrics value reported is the computed delta value (present value - previous value) ###Network Interface **Note: \ is replaced with the actual network interface name, e.g eth0** | Metric | Description | | ----- | ----- | -| \|RX Bytes | The total bytes received | +| \|RX KiloBytes | The total kilo bytes received | | \|RX Dropped | The number of dropped packets due to reception errors | | \|RX Errors | The number of damaged packets received | | \|RX Frame | The number received packets that experienced frame errors | | \|RX Overruns | The number of received packets that experienced data overruns | | \|RX Packets | The number of packets received | | \|Speed | The speed in bits per second | -| \|TX Bytes | The total bytes transmitted | +| \|TX KiloBytes | The total kilo bytes transmitted | | \|TX Carrier | The number received packets that experienced loss of carriers | | \|TX Collision | The number of transmitted packets that experienced Ethernet collisions | | \|TX Dropped | The number of dropped transmitted packets due to transmission errors | @@ -153,5 +154,5 @@ Always feel free to fork and contribute any changes directly here on GitHub ##Support -For any questions or feature request, please contact [AppDynamics Center of Excellence](mailto:ace-request@appdynamics.com). +For any questions or feature request, please contact [AppDynamics Center of Excellence](mailto:help@appdynamics.com). diff --git a/pom.xml b/pom.xml index 1a44f58..3fdd605 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.appdynamics.extension network-monitoring-extension - 1.0.0 + 1.0.1 1.6.3.82 @@ -173,10 +173,10 @@ - - + @@ -194,6 +194,7 @@ maven-surefire-plugin 2.8 + true java.library.path diff --git a/src/main/java/com/appdynamics/extensions/network/Metrics.java b/src/main/java/com/appdynamics/extensions/network/Metrics.java index ba8c5d8..4e2719b 100644 --- a/src/main/java/com/appdynamics/extensions/network/Metrics.java +++ b/src/main/java/com/appdynamics/extensions/network/Metrics.java @@ -12,6 +12,7 @@ public enum Metrics { // Network card metrics NIC_RX_BYTES("%s" + DEFAULT_DELIMETER + "RX Bytes"), + NIC_RX_KILOBYTES("%s" + DEFAULT_DELIMETER + "RX KB"), NIC_RX_DROPPED("%s" + DEFAULT_DELIMETER + "RX Dropped"), NIC_RX_ERRORS("%s" + DEFAULT_DELIMETER + "RX Errors"), NIC_RX_FRAME("%s" + DEFAULT_DELIMETER + "RX Frame"), @@ -19,6 +20,7 @@ public enum Metrics { NIC_RX_PACKETS("%s" + DEFAULT_DELIMETER + "RX Packets"), NIC_SPEED("%s" + DEFAULT_DELIMETER + "Speed"), NIC_TX_BYTES("%s" + DEFAULT_DELIMETER + "TX Bytes"), + NIC_TX_KILOBYTES("%s" + DEFAULT_DELIMETER + "TX KB"), NIC_TX_CARRIER("%s" + DEFAULT_DELIMETER + "TX Carrier"), NIC_TX_COLLISIONS("%s" + DEFAULT_DELIMETER + "TX Collision"), NIC_TX_DROPPED("%s" + DEFAULT_DELIMETER + "TX Dropped"), diff --git a/src/main/java/com/appdynamics/extensions/network/NetworkMetricsCollector.java b/src/main/java/com/appdynamics/extensions/network/NetworkMetricsCollector.java index 7134f20..eef46c9 100644 --- a/src/main/java/com/appdynamics/extensions/network/NetworkMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/network/NetworkMetricsCollector.java @@ -106,7 +106,7 @@ private void collectOtherMetrics() { private void addRxBytesMetric(String netInterfaceName) { BigInteger value = null; - String metricName = getFormattedMetricName(Metrics.NIC_RX_BYTES, netInterfaceName); + String metricName = getFormattedMetricName(Metrics.NIC_RX_KILOBYTES, netInterfaceName); if (isInScriptMetrics(metricName)) { value = scriptMetrics.getMetricValue(metricName); @@ -115,7 +115,7 @@ private void addRxBytesMetric(String netInterfaceName) { value = BigInteger.valueOf(sigarMetrics.getNetInterfaceStat(netInterfaceName).getRxBytes()); } - addMetric(metricName, value); + addMetric(metricName, value.divide(new BigInteger("1042"))); } private void addRxDroppedMetric(String netInterfaceName) { @@ -211,7 +211,7 @@ private void addSpeedMetric(String netInterfaceName) { private void addTxBytesMetric(String netInterfaceName) { BigInteger value = null; - String metricName = getFormattedMetricName(Metrics.NIC_TX_BYTES, netInterfaceName); + String metricName = getFormattedMetricName(Metrics.NIC_TX_KILOBYTES, netInterfaceName); if (isInScriptMetrics(metricName)) { value = scriptMetrics.getMetricValue(metricName); @@ -220,7 +220,7 @@ private void addTxBytesMetric(String netInterfaceName) { value = BigInteger.valueOf(sigarMetrics.getNetInterfaceStat(netInterfaceName).getTxBytes()); } - addMetric(metricName, value); + addMetric(metricName, value.divide(new BigInteger("1042"))); } private void addTxCarrierMetric(String netInterfaceName) { diff --git a/src/main/java/com/appdynamics/extensions/network/NetworkMonitor.java b/src/main/java/com/appdynamics/extensions/network/NetworkMonitor.java index ee161d3..8893818 100644 --- a/src/main/java/com/appdynamics/extensions/network/NetworkMonitor.java +++ b/src/main/java/com/appdynamics/extensions/network/NetworkMonitor.java @@ -6,8 +6,12 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.math.BigInteger; +import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.yaml.snakeyaml.Yaml; @@ -32,7 +36,17 @@ public class NetworkMonitor extends AManagedMonitor { private String metricPrefix; - public TaskOutput execute(Map args, + private Cache prevMetricsMap; + + public NetworkMonitor() { + String msg = "Using Monitor Version [" + getImplementationVersion() + "]"; + LOGGER.info(msg); + System.out.println(msg); + + prevMetricsMap = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build(); + } + + public TaskOutput execute(Map args, TaskExecutionContext arg1) throws TaskExecutionException { LOGGER.info("Starting Network Monitoring task"); @@ -118,9 +132,28 @@ private long getScriptTimeout(Configuration config) { private void uploadMetrics(Map metrics) { for (Map.Entry metric : metrics.entrySet()) { - printCollectiveObservedCurrent(metricPrefix + metric.getKey(), metric.getValue()); - } + //printCollectiveObservedCurrent(metricPrefix + metric.getKey(), metric.getValue()); + BigInteger prevValue = processDelta(metricPrefix + metric.getKey(), metric.getValue()); + if(prevValue != null) { + printCollectiveAverageAverage(metricPrefix + metric.getKey(), getDeltaValue(metric.getValue(), prevValue)); + } + } } + + private BigInteger processDelta(String metricName, BigInteger metricValue) { + BigInteger prevValue = prevMetricsMap.getIfPresent(metricName); + if(metricValue != null) { + prevMetricsMap.put(metricName, metricValue); + } + return prevValue; + } + + private BigInteger getDeltaValue(BigInteger currentValue, BigInteger prevValue) { + if(currentValue == null) { + return prevValue; + } + return currentValue.subtract(prevValue); + } private void printCollectiveObservedCurrent(String metricName, BigInteger metricValue) { printMetric(metricName, metricValue, @@ -129,6 +162,14 @@ private void printCollectiveObservedCurrent(String metricName, BigInteger metric MetricWriter.METRIC_CLUSTER_ROLLUP_TYPE_COLLECTIVE ); } + + private void printCollectiveAverageAverage(String metricName, BigInteger metricValue) { + printMetric(metricName, metricValue, + MetricWriter.METRIC_AGGREGATION_TYPE_AVERAGE, + MetricWriter.METRIC_TIME_ROLLUP_TYPE_AVERAGE, + MetricWriter.METRIC_CLUSTER_ROLLUP_TYPE_COLLECTIVE + ); + } private void printMetric(String metricName, BigInteger metricValue, String aggregation, String timeRollup, String cluster) { MetricWriter metricWriter = getMetricWriter(metricName, aggregation,