Skip to content

Commit

Permalink
Computed delta metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
BalakrishnaV committed Jul 21, 2015
1 parent 02d6598 commit da1761e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|\<Tier\>|Custom Metrics|Network|** followed by the individual metrics below:
Metrics value reported is the computed delta value (present value - previous value)

###Network Interface
**Note: \<network_interface\> is replaced with the actual network interface name, e.g eth0**

| Metric | Description |
| ----- | ----- |
| \<network_interface\>&#124;RX Bytes | The total bytes received |
| \<network_interface\>&#124;RX KiloBytes | The total kilo bytes received |
| \<network_interface\>&#124;RX Dropped | The number of dropped packets due to reception errors |
| \<network_interface\>&#124;RX Errors | The number of damaged packets received |
| \<network_interface\>&#124;RX Frame | The number received packets that experienced frame errors |
| \<network_interface\>&#124;RX Overruns | The number of received packets that experienced data overruns |
| \<network_interface\>&#124;RX Packets | The number of packets received |
| \<network_interface\>&#124;Speed | The speed in bits per second |
| \<network_interface\>&#124;TX Bytes | The total bytes transmitted |
| \<network_interface\>&#124;TX KiloBytes | The total kilo bytes transmitted |
| \<network_interface\>&#124;TX Carrier | The number received packets that experienced loss of carriers |
| \<network_interface\>&#124;TX Collision | The number of transmitted packets that experienced Ethernet collisions |
| \<network_interface\>&#124;TX Dropped | The number of dropped transmitted packets due to transmission errors |
Expand Down Expand Up @@ -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).

7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.appdynamics.extension</groupId>
<artifactId>network-monitoring-extension</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<properties>
<sigar.version>1.6.3.82</sigar.version>
Expand Down Expand Up @@ -173,10 +173,10 @@
<fileset dir="src/main/resources" includes="scripts/**" />
</copy>
<copy todir="${target.dir}">
<fileset dir="${build.directory}"
<fileset dir="${project.build.directory}"
includes="${project.artifactId}.${project.packaging}" />
</copy>
<zip destfile="${target.dir}.zip">
<zip destfile="${target.dir}-${project.version}.zip">
<zipfileset dir="${target.dir}" filemode="755"
prefix="NetworkMonitor/" />
</zip>
Expand All @@ -194,6 +194,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8</version>
<configuration>
<skipTests>true</skipTests>
<systemProperties>
<property>
<name>java.library.path</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/appdynamics/extensions/network/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ 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"),
NIC_RX_OVERRUNS("%s" + DEFAULT_DELIMETER + "RX Overruns"),
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +36,17 @@ public class NetworkMonitor extends AManagedMonitor {

private String metricPrefix;

public TaskOutput execute(Map<String, String> args,
private Cache<String, BigInteger> 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<String, String> args,
TaskExecutionContext arg1) throws TaskExecutionException {

LOGGER.info("Starting Network Monitoring task");
Expand Down Expand Up @@ -118,9 +132,28 @@ private long getScriptTimeout(Configuration config) {

private void uploadMetrics(Map<String, BigInteger> metrics) {
for (Map.Entry<String, BigInteger> 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,
Expand All @@ -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,
Expand Down

0 comments on commit da1761e

Please sign in to comment.