Skip to content

Commit

Permalink
Linux Monitoring Extensions Code Review Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayAppd19 committed Oct 24, 2017
1 parent bb7942b commit 05bdf24
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ private void printNestedMap(Map<String, Object> map, String metricPath) {

List<MetricData> val = (ArrayList)entry.getValue();
for(MetricData metricData: val) {
System.out.println("IN printNestedMap: Metric: " + metricData.getName());
if(metricData.isCollectDelta()){
String metricVal = MetricUtils.toWholeNumberString(metricData.getStats());
BigDecimal deltaMetricValue = deltaCalculator.calculateDelta(metricPath, new BigDecimal(metricVal));
printMetric(metricPath + key + "|" +metricData.getName() + " Delta", deltaMetricValue != null ? deltaMetricValue.toBigInteger() : new BigInteger("0"), metricData.getMetricType());

}else{
printMetric(metricPath + key + "|" +metricData.getName(), metricData.getStats(), metricData.getMetricType());
}
printMetric(metricPath + key + "|" +metricData.getName(), metricData.getStats(), metricData.getMetricType());

// compute Avg IO utilization using metric in diskstats
if ("time spent doing I/Os (ms)".equals(key)) {
Expand Down Expand Up @@ -162,7 +160,6 @@ private void printMetric(String metricName, Object metricValue, String metricTyp
if (metricValue != null) {
String metric = MetricUtils.toWholeNumberString(metricValue);
metric = metric!=null && metric.trim().length()!=0 ? metric : "0";
System.out.println("Metric name: "+ metricName + " val: " + metric);
this.configuration.getMetricWriter().printMetric(metricName, new BigDecimal(metric), metricType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public String execute(String fileSystem) {
String formattedCommand = "";
try {
formattedCommand = String.format(command[0], fileSystem);
System.out.println("formatted command: " + formattedCommand);
p = rt.exec(new String[]{"bash", "-c", formattedCommand});
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
Expand Down Expand Up @@ -75,7 +74,7 @@ public Map<String, Object> getNFSMetrics(final MountedNFS fileSystem){
if(line.contains(fileSystem.getFileSystem())) {
String[] stats = line.trim().split(SPACE_REGEX);
for (int i = 0; i < NFS_IO_FILE_STATS.length; i++) {
statsMap.put(NFS_IO_FILE_STATS[i], stats[i]);
statsMap.put(NFS_IO_FILE_STATS[i], stats[i+1]);
}
}
}
Expand Down
89 changes: 34 additions & 55 deletions src/main/java/com/appdynamics/extensions/linux/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,45 +53,14 @@ public class Stats {
private static final String SPACE_REGEX = "[\t ]+";
private static final String SPACE_COLON_REGEX = "[\t :]+";

private static String[] CPU_STATS =
{IDENTIFIER, "user", "nice", "system", "idle", "iowait", "irq", "softirq", "steal", "guest", "guest_nice"};
private static String[] PAGE_STATS = {"page", "page in", "page out"};
private static String[] SWAP_STATS = {"swap", "swap page in", "swap page out"};
private static String[] NET_STATS =
{IDENTIFIER, "receive bytes", "receive packets", "receive errs", "receive drop", "receive fifo",
"receive frame", "receive compressed", "receive multicast", "transmit bytes", "transmit packets",
"transmit errs", "transmit drop", "transmit fifo", "transmit colls", "transmit carrier",
"transmit compressed"};
private static String[] DISK_STATS =
{"major", "minor", IDENTIFIER, "reads completed successfully", "reads merged", "sectors read",
"time spent reading (ms)", "writes completed", "writes merged", "sectors written",
"time spent writing (ms)", "I/Os currently in progress", "time spent doing I/Os (ms)",
"weighted time spent doing I/Os (ms)"};
private static String[] DISK_USAGE_STATS =
{IDENTIFIER, "size (MB)", "used (MB)", "available (MB)", "use %"};
private static String[] FILE_NR_STATS = {"fhalloc", "fhfree", "fhmax"};
private static String[] INODE_NR_STATS = {"inalloc", "infree"};
private static String[] DENTRIES_STATS = {"dentries", "unused", "agelimit", "wantpages"};
private static String[] LOADAVG_STATS = {"load avg (1 min)", "load avg (5 min)", "load avg (15 min)"};
private static String[] MEM_FILE_STATS =
{"MemTotal", "MemFree", "Buffers", "Cached", "SwapCached", "Active", "Inactive", "SwapTotal", "SwapFree",
"Dirty", "Writeback", "Mapped", "Slab", "CommitLimit", "Committed_AS"};
private static String[] MEM_STATS = {"total", "free", "buffers", "cached", "swap cached", "active", "inactive",
"swap total", "swap free", "dirty", "writeback", "mapped", "slab", "commit limit", "committed_as"};
private static String[] PAGE_SWAP_FILE_STATS = {"pgpgin", "pgpgout", "pswpin", "pswpout", "pgfault", "pgmajfault"};
private static String[] PAGE_SWAP_STATS = {"page in", "page out", "swap page in", "swap page out", "page fault",
"page major fault"};
private static String[] PROC_FILE_STATS = {"processes", "procs_running", "procs_blocked"};
private static String[] PROC_STATS = {"processes", "running", "blocked"};
private static String[] PROC_LOADAVG_STATS = {IDENTIFIER, IDENTIFIER, IDENTIFIER, "runqueue", "count"};
private static String[] SOCK_USED_STATS = {IDENTIFIER, IDENTIFIER, "used"};
private static String[] TCP_INUSE_STATS = {IDENTIFIER, IDENTIFIER, "tcp"};
private static String[] UDP_INUSE_STATS = {IDENTIFIER, IDENTIFIER, "udp"};
private static String[] RAW_INUSE_STATS = {IDENTIFIER, IDENTIFIER, "raw"};
private static String[] IPFRAG_STATS = {IDENTIFIER, IDENTIFIER, "ipfrag"};
protected static Map<String, List<Map<String, String>>> allMetricsFromConfig = new HashMap<String, List<Map<String, String>>>();

private static Logger logger = Logger.getLogger(Stats.class);;
private static Logger logger = Logger.getLogger(Stats.class);


public Stats(List<Map<String, List<Map<String, String>>>> metrics) {
Expand Down Expand Up @@ -291,12 +260,12 @@ boolean isCountRequired() {
}
};
parser.addParser(statParser);
/*

metrics = generateStatsMap(parser.getStats(),"iNodeNRStats");
if (metrics != null) {
statsMap.addAll(metrics);
statsMetrics.addAll(metrics);
}
*/


String[] dentriesStats = generateStatsArray("dentriesStats");

Expand Down Expand Up @@ -612,7 +581,7 @@ protected static Map<String, Object> getRowStats(BufferedReader reader, String s
String description, int keyIndex, int valIndex) {
Map<String, Object> statsMap = null;
if (reader == null) {
logger.error("Failed to read " + description + " stats");
logger.error("Failed to read " + description + " stats as reader is null");
} else {
statsMap = new HashMap<String, Object>();

Expand All @@ -636,7 +605,7 @@ protected static Map<String, Object> getRowStats(BufferedReader reader, String s
reader.close();
}
} catch (IOException e) {
logger.error("Failed to read " + description + " stats");
logger.error("Failed to read " + description + " stats: " + e.getStackTrace());
}
}

Expand Down Expand Up @@ -703,6 +672,8 @@ private void populateMetricsMap(List<Map<String, List<Map<String, String>>>> met

protected static String[] generateStatsArray(String metricName){

logger.debug("Generating Stats Array for metric: " + metricName);

String[] stats = new String[allMetricsFromConfig.get(metricName).size()+1];
int index = 0;
for(Map<String,String> metricsEntry: allMetricsFromConfig.get(metricName)){
Expand All @@ -715,33 +686,41 @@ protected static List<MetricData> generateStatsMap(Map<String, Object> statsMap,

List<MetricData> metricStats = new ArrayList<MetricData>();
if(statsMap!=null) {
logger.debug("Generating Stats Map for metric: " + metricName);

for (Map.Entry<String, Object> statsEntry : statsMap.entrySet()) {
for (Map<String, String> metrics : allMetricsFromConfig.get(metricName)) {
List<Map<String, String>> metricConfig = allMetricsFromConfig.get(metricName);
if(metricConfig!=null) {

if (metrics.get("name").equalsIgnoreCase(statsEntry.getKey()) ) {
for (Map<String, String> metrics : metricConfig) {

MetricData metricData = new MetricData();
metricData.setStats(statsEntry.getValue());
metricData.setName(metrics.get("name"));
metricData.setCollectDelta(Boolean.valueOf(metrics.get("collectDelta")));
metricData.setMetricType(metrics.get("metricType"));
if (metrics != null && metrics.get("name").equalsIgnoreCase(statsEntry.getKey())) {

metricStats.add(metricData);
}
logger.debug("Adding stats for the entry: " + metrics.get("name") + " with value: " + statsEntry.getValue());

if(metricName.equalsIgnoreCase("mountedNFSStatus") ){
MetricData metricData = new MetricData();
metricData.setStats(statsEntry.getValue());
metricData.setName(metrics.get("name"));
metricData.setCollectDelta(Boolean.valueOf(metrics.get("collectDelta")));
metricData.setMetricType(metrics.get("metricType"));

MetricData metricData = new MetricData();
metricData.setStats(statsEntry.getValue());
metricData.setName(statsEntry.getKey() + "|" + metrics.get("name"));
metricData.setCollectDelta(Boolean.valueOf(metrics.get("collectDelta")));
metricData.setMetricType(metrics.get("metricType"));
metricStats.add(metricData);
}

metricStats.add(metricData);
}
}
if (metricName.equalsIgnoreCase("mountedNFSStatus")) {

logger.debug("Adding stats for the entry: " + metrics.get("name") + " with value: " + statsEntry.getValue());

MetricData metricData = new MetricData();
metricData.setStats(statsEntry.getValue());
metricData.setName(statsEntry.getKey() + "|" + metrics.get("name"));
metricData.setCollectDelta(Boolean.valueOf(metrics.get("collectDelta")));
metricData.setMetricType(metrics.get("metricType"));

metricStats.add(metricData);
}
}
}
}
}else{
logger.error("No stats found for: " + metricName);
Expand Down
18 changes: 18 additions & 0 deletions src/main/resources/conf/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ metrics:
- name: "committed_AS"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "used"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "used %"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "swap used"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "swap used %"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "real free"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- name: "real free %"
metricType: "OBS.CUR.COL"
collectDelta: "false"
- procFileStats:
- name: "processes"
metricType: "OBS.CUR.COL"
Expand Down
73 changes: 73 additions & 0 deletions src/test/resources/CommandOutput
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
Command: cat /proc/stat
Output:
user nice system idle iowait irq
cpu 135213 3639 15904 1166375 934 220
cpu0 135213 3639 15904 1166375 934 220

processes 35198
procs_running 3
procs_blocked 0
softirq 917320 3 540218 2636 29695 60193 0 1796 0 0 282779

Command: cat /proc/net/dev
Output:
Interface| Receive | Transmit
|bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
enp0s3: 5681713 7113 0 0 0 0 0 0 1442904 4905 0 0 0 0 0 0
lo: 300266 3563 0 0 0 0 0 0 300266 3563 0 0 0 0 0 0
enp0s8: 1872 18 0 0 0 0 0 0 621568 3130 0 0 0 0 0 0


Command: cat /proc/diskstats
Output:

Device| Reads Comepleted| Reads | Sectors | Time Spent | Writes | Writes | Sectors | Time Spent | I/O Currently | Time During | Weighted Time
Succesfully | Merged| Read | Reading(ms)| Completed| Merged | Written | Writing(ms)| In Progress | I/O (ms) | Spent During I/O(ms)
sda | 46577 | 7135 | 1934418 34260 | 14327 | 20428 | 626400 | 12360 |0 | 26408 | 46556
sda1 | 46500 | 7135 | 1930298 34220 | 13984 | 20428 | 626400 | 12224 |0 | 26272 | 46380


Command: cat /proc/meminfo
Output:

MemTotal: 2045948 kB
MemFree: 280820 kB
MemAvailable: 898712 kB
Buffers: 142152 kB
Cached: 578344 kB
SwapCached: 0 kB
Active: 1199932 kB
Inactive: 368096 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 36 kB
Writeback: 0 kB
Mapped: 193252 kB
Slab: 131252 kB
CommitLimit: 1022972 kB
Committed_AS: 3910336 kB


Commad: cat /proc/net/sockstat
Output: sockets: used 741
TCP: inuse 8 orphan 0 tw 0 alloc 15 mem 0
UDP: inuse 13 mem 5
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

Command: cat /proc/vmstat
Output:
pgpgin 967209
pgpgout 314512
pswpin 0
pswpout 0
pgfault 4605513
pgmajfault 3873

Command: cat /proc/loadavg
Output:
load avg| load avg | load avg | Currently Running Process |
(1 min) | (5 min) | (15 min) | Total Num of Process |
0.29 | 0.18 | 0.16 | 5/429

0 comments on commit 05bdf24

Please sign in to comment.