From 32f5a53122390e3e353218c105802207d52f544f Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Mon, 22 Nov 2010 22:39:00 +0200 Subject: [PATCH] add parse scripts --- parse/.gitignore | 2 ++ parse/parse_all | 19 +++++++++++++++++ parse/parse_cpu_process | 20 ++++++++++++++++++ parse/parse_cpu_system | 20 ++++++++++++++++++ parse/parse_io_process | 20 ++++++++++++++++++ parse/parse_io_system | 20 ++++++++++++++++++ parse/parse_memory_process | 20 ++++++++++++++++++ parse/parse_memory_system | 20 ++++++++++++++++++ parse/parse_packets_in | 20 ++++++++++++++++++ parse/parse_packets_out | 20 ++++++++++++++++++ parse/parse_udp_in | 42 ++++++++++++++++++++++++++++++++++++++ parse/parse_udp_out | 42 ++++++++++++++++++++++++++++++++++++++ parse/r_parse_all | 13 ++++++++++++ parse/r_parse_cp.R | 14 +++++++++++++ parse/r_parse_mp.R | 16 +++++++++++++++ parse/r_parse_udp.R | 17 +++++++++++++++ 16 files changed, 325 insertions(+) create mode 100644 parse/.gitignore create mode 100755 parse/parse_all create mode 100755 parse/parse_cpu_process create mode 100755 parse/parse_cpu_system create mode 100755 parse/parse_io_process create mode 100755 parse/parse_io_system create mode 100755 parse/parse_memory_process create mode 100755 parse/parse_memory_system create mode 100755 parse/parse_packets_in create mode 100755 parse/parse_packets_out create mode 100755 parse/parse_udp_in create mode 100755 parse/parse_udp_out create mode 100755 parse/r_parse_all create mode 100644 parse/r_parse_cp.R create mode 100644 parse/r_parse_mp.R create mode 100644 parse/r_parse_udp.R diff --git a/parse/.gitignore b/parse/.gitignore new file mode 100644 index 0000000..425cccf --- /dev/null +++ b/parse/.gitignore @@ -0,0 +1,2 @@ +/log/ +/out/ diff --git a/parse/parse_all b/parse/parse_all new file mode 100755 index 0000000..c2b9fbb --- /dev/null +++ b/parse/parse_all @@ -0,0 +1,19 @@ +#!/bin/bash + +if test $# -ne 1; then + echo "Usage: $0 input-log-file" 1>&2 + exit 1 +fi + +input_log_file=$1 + +./parse_memory_process < $input_log_file > mp_$input_log_file +./parse_memory_system < $input_log_file > ms_$input_log_file +./parse_cpu_process < $input_log_file > cp_$input_log_file +./parse_cpu_system < $input_log_file > cs_$input_log_file +./parse_io_process < $input_log_file > ip_$input_log_file +./parse_io_system < $input_log_file > is_$input_log_file +./parse_udp_in < $input_log_file > ui_$input_log_file +./parse_udp_out < $input_log_file > uo_$input_log_file +./parse_packets_in < $input_log_file > pi_$input_log_file +./parse_packets_out < $input_log_file > po_$input_log_file diff --git a/parse/parse_cpu_process b/parse/parse_cpu_process new file mode 100755 index 0000000..ecb8dbe --- /dev/null +++ b/parse/parse_cpu_process @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "user\tsystem\tCPU\n" +} + +/%CPU[ \t]+CPU[ \t]+Command/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\t%s\t%s\n", $4, $5, $6 +} +' diff --git a/parse/parse_cpu_system b/parse/parse_cpu_system new file mode 100755 index 0000000..74eaca2 --- /dev/null +++ b/parse/parse_cpu_system @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "user\tsystem\n" +} + +/^avg-cpu/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\t%s\n", $1, $3 +} +' diff --git a/parse/parse_io_process b/parse/parse_io_process new file mode 100755 index 0000000..4fb14d7 --- /dev/null +++ b/parse/parse_io_process @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "kB_rd/s\tkB_wr/s\n" +} + +/kB_rd\/s[ \t]+kB_wr\/s/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\t%s\n", $4, $5 +} +' diff --git a/parse/parse_io_system b/parse/parse_io_system new file mode 100755 index 0000000..801a85a --- /dev/null +++ b/parse/parse_io_system @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "Blk_read/s\tBlk_wrtn/s\n" +} + +/^Device:/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\t%s\n", $3, $4 +} +' diff --git a/parse/parse_memory_process b/parse/parse_memory_process new file mode 100755 index 0000000..74089f1 --- /dev/null +++ b/parse/parse_memory_process @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "VSZ\tRSS\tPERCENT\n" +} + +/VSZ[ \t]+RSS[ \t]+%MEM/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\t%s\t%s\n", $6, $7, $8 +} +' diff --git a/parse/parse_memory_system b/parse/parse_memory_system new file mode 100755 index 0000000..860a59b --- /dev/null +++ b/parse/parse_memory_system @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "memory\n" +} + +/^Mem:/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 2 && !init) + printf "%s\n", $3 +} +' diff --git a/parse/parse_packets_in b/parse/parse_packets_in new file mode 100755 index 0000000..8d5b59c --- /dev/null +++ b/parse/parse_packets_in @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "bytes_received\n" +} + +/^Chain udp_out/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 4 && !init) + printf "%s\n", $1 +} +' diff --git a/parse/parse_packets_out b/parse/parse_packets_out new file mode 100755 index 0000000..e547d94 --- /dev/null +++ b/parse/parse_packets_out @@ -0,0 +1,20 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "bytes_sent\n" +} + +/^Chain udp_out/ { + count = 0 + init = 0 +} + +{ + count++ + if (count == 5 && !init) + printf "%s\n", $1 +} +' diff --git a/parse/parse_udp_in b/parse/parse_udp_in new file mode 100755 index 0000000..1423559 --- /dev/null +++ b/parse/parse_udp_in @@ -0,0 +1,42 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "pkts\tbytes\n" +} + +/^Chain udp_in/ { + count = 0 + init = 0 +} + +{ + count++ + + pkts = $1 + 0 + bytes = $2 + 0 + + if (index($1, "K")) + pkts = pkts * 1024 + else + if (index($1, "M")) + pkts = pkts * 1024 * 1024; + else + if (index($1, "G")) + pkts = pkts * 1024 * 1024 * 1204 + + if (index($2, "K")) + bytes = bytes * 1024 + else + if (index($2, "M")) + bytes = bytes * 1024 * 1024; + else + if (index($2, "G")) + bytes = bytes * 1024 * 1024 * 1204 + + if (count == 3 && !init) + printf "%s\t%s\n", pkts, bytes +} +' diff --git a/parse/parse_udp_out b/parse/parse_udp_out new file mode 100755 index 0000000..2ebb99e --- /dev/null +++ b/parse/parse_udp_out @@ -0,0 +1,42 @@ +#!/bin/bash + +awk ' +BEGIN { + count = 0 + init = 1 + printf "pkts\tbytes\n" +} + +/^Chain udp_out/ { + count = 0 + init = 0 +} + +{ + count++ + + pkts = $1 + 0 + bytes = $2 + 0 + + if (index($1, "K")) + pkts = pkts * 1024 + else + if (index($1, "M")) + pkts = pkts * 1024 * 1024; + else + if (index($1, "G")) + pkts = pkts * 1024 * 1024 * 1204 + + if (index($2, "K")) + bytes = bytes * 1024 + else + if (index($2, "M")) + bytes = bytes * 1024 * 1024; + else + if (index($2, "G")) + bytes = bytes * 1024 * 1024 * 1204 + + if (count == 3 && !init) + printf "%s\t%s\n", pkts, bytes +} +' diff --git a/parse/r_parse_all b/parse/r_parse_all new file mode 100755 index 0000000..8757af2 --- /dev/null +++ b/parse/r_parse_all @@ -0,0 +1,13 @@ +#!/bin/bash + +if test $# -ne 1; then + echo "Usage: $0 base-log-file" 1>&2 + exit 1 +fi + +base_log_file=$1 + +Rscript r_parse_udp.R out/ui_$base_log_file out/ui_$(basename $base_log_file .log).pdf +Rscript r_parse_udp.R out/uo_$base_log_file out/uo_$(basename $base_log_file .log).pdf +Rscript r_parse_cp.R out/cp_$base_log_file out/cp_$(basename $base_log_file .log).pdf +Rscript r_parse_mp.R out/mp_$base_log_file out/mp_$(basename $base_log_file .log).pdf diff --git a/parse/r_parse_cp.R b/parse/r_parse_cp.R new file mode 100644 index 0000000..f22678e --- /dev/null +++ b/parse/r_parse_cp.R @@ -0,0 +1,14 @@ +args <- commandArgs(trailingOnly=TRUE) + +source_file <- args[1] +output_file <- args[2] + +cpu_table <- read.table(source_file, header=T) + +cpu_perc <- cpu_table$CPU + +cpu_perc + +pdf(file=output_file) +plot(cpu_perc, type="o", col="red", xlab="Time (s)", ylab="CPU Usage (%)"); +dev.off() diff --git a/parse/r_parse_mp.R b/parse/r_parse_mp.R new file mode 100644 index 0000000..5d0c8f4 --- /dev/null +++ b/parse/r_parse_mp.R @@ -0,0 +1,16 @@ +args <- commandArgs(trailingOnly=TRUE) + +source_file <- args[1] +output_file <- args[2] + +mem_table <- read.table(source_file, header=T) + +rss <- mem_table$RSS / 1024 +new_rss <- rss +new_rss[length(new_rss)+1] = 0 + +rss + +pdf(file=output_file) +plot(new_rss, type="o", col="red", xlab="Time (s)", ylab="RSS (MB)"); +dev.off() diff --git a/parse/r_parse_udp.R b/parse/r_parse_udp.R new file mode 100644 index 0000000..234316d --- /dev/null +++ b/parse/r_parse_udp.R @@ -0,0 +1,17 @@ +args <- commandArgs(trailingOnly=TRUE) + +source_file <- args[1] +output_file <- args[2] + +udp_table <- read.table(source_file, header=T) + +bytes_array <- udp_table$bytes +offset_bytes_array <- bytes_array[2:length(bytes_array)] + +speed <- (offset_bytes_array - bytes_array[1:length(bytes_array)-1]) / 1024 + +speed + +pdf(file=output_file) +plot(speed, type="o", col="red", xlab="Time (s)", ylab="Speed (KB/s)"); +dev.off() -- 2.20.1