From 67d12bf40c460918b718b1acc794a51923f99363 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Sat, 25 Jan 2014 17:11:40 +0100 Subject: [PATCH 1/3] batch refresh --- lib/usagewatch/linux.rb | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/usagewatch/linux.rb b/lib/usagewatch/linux.rb index f0a2b32..111ceb9 100644 --- a/lib/usagewatch/linux.rb +++ b/lib/usagewatch/linux.rb @@ -19,11 +19,23 @@ def self.uw_diskused_perc df.split(" ").last.to_f.round(2) end - # Show the percentage of CPU used - def self.uw_cpuused + def self.batch_refresh @proc0 = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ") + @bandrx_new0 = self.bandrx + @bandtx_new0 = self.bandtx + @diskio_new1 = self.diskio + sleep 1 + @proc1 = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ") + @bandrx_new1 = self.bandrx + @bandtx_new1 = self.bandtx + @diskio_new1 = self.diskio + end + + # Show the percentage of CPU used + def self.uw_cpuused(now = true) + long_operation if now @proc0usagesum = @proc0[1].to_i + @proc0[2].to_i + @proc0[3].to_i @proc1usagesum = @proc1[1].to_i + @proc1[2].to_i + @proc1[3].to_i @@ -184,13 +196,10 @@ def self.bandrx end # Current Bandwidth Received Calculation in Mbit/s - def self.uw_bandrx - - @new0 = self.bandrx - sleep 1 - @new1 = self.bandrx + def self.uw_bandrx(now = true) + long_operation if now - @bytesreceived = @new1[0].to_i - @new0[0].to_i + @bytesreceived = @bandrx_new1[0].to_i - @bandrx_new0[0].to_i @bitsreceived = (@bytesreceived * 8) @megabitsreceived = (@bitsreceived.to_f / 1024 / 1024).round(3) end @@ -239,13 +248,10 @@ def self.bandtx end # Current Bandwidth Transmitted in Mbit/s - def self.uw_bandtx - - @new0 = self.bandtx - sleep 1 - @new1 = self.bandtx + def self.uw_bandtx(now = true) + long_operation if now - @bytestransmitted = @new1[1].to_i - @new0[1].to_i + @bytestransmitted = @bandtx_new1[1].to_i - @bandtx_new0[1].to_i @bitstransmitted = (@bytestransmitted * 8) @megabitstransmitted = (@bitstransmitted.to_f / 1024 / 1024).round(3) end @@ -292,22 +298,16 @@ def self.diskio end # Current Disk Reads Completed - def self.uw_diskioreads + def self.uw_diskioreads(now = true) + long_operation if now - @new0 = self.diskio - sleep 1 - @new1 = self.diskio - - @diskreads = @new1[0].to_i - @new0[0].to_i + @diskreads = @diskio_new1[0].to_i - @diskio_new0[0].to_i end # Current Disk Writes Completed - def self.uw_diskiowrites - - @new0 = self.diskio - sleep 1 - @new1 = self.diskio + def self.uw_diskiowrites(now = true) + long_operation if now - @diskwrites = @new1[1].to_i - @new0[1].to_i + @diskwrites = @diskio_new1[1].to_i - @diskio_new0[1].to_i end end From 60df330c4a612add1c1e4e090a7fb20c4007f094 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Sat, 25 Jan 2014 17:15:48 +0100 Subject: [PATCH 2/3] batch refresh --- lib/usagewatch/linux.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/usagewatch/linux.rb b/lib/usagewatch/linux.rb index 111ceb9..670585b 100644 --- a/lib/usagewatch/linux.rb +++ b/lib/usagewatch/linux.rb @@ -35,7 +35,7 @@ def self.batch_refresh # Show the percentage of CPU used def self.uw_cpuused(now = true) - long_operation if now + batch_refresh if now @proc0usagesum = @proc0[1].to_i + @proc0[2].to_i + @proc0[3].to_i @proc1usagesum = @proc1[1].to_i + @proc1[2].to_i + @proc1[3].to_i @@ -197,7 +197,7 @@ def self.bandrx # Current Bandwidth Received Calculation in Mbit/s def self.uw_bandrx(now = true) - long_operation if now + batch_refresh if now @bytesreceived = @bandrx_new1[0].to_i - @bandrx_new0[0].to_i @bitsreceived = (@bytesreceived * 8) @@ -249,7 +249,7 @@ def self.bandtx # Current Bandwidth Transmitted in Mbit/s def self.uw_bandtx(now = true) - long_operation if now + batch_refresh if now @bytestransmitted = @bandtx_new1[1].to_i - @bandtx_new0[1].to_i @bitstransmitted = (@bytestransmitted * 8) @@ -299,14 +299,14 @@ def self.diskio # Current Disk Reads Completed def self.uw_diskioreads(now = true) - long_operation if now + batch_refresh if now @diskreads = @diskio_new1[0].to_i - @diskio_new0[0].to_i end # Current Disk Writes Completed def self.uw_diskiowrites(now = true) - long_operation if now + batch_refresh if now @diskwrites = @diskio_new1[1].to_i - @diskio_new0[1].to_i end From a1df22fed01959e39235cb9f13fa9ea338c04787 Mon Sep 17 00:00:00 2001 From: Aleksander Kwiatkowski Date: Sat, 25 Jan 2014 17:23:28 +0100 Subject: [PATCH 3/3] batch refresh, fix --- lib/usagewatch/linux.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/usagewatch/linux.rb b/lib/usagewatch/linux.rb index 670585b..8245e60 100644 --- a/lib/usagewatch/linux.rb +++ b/lib/usagewatch/linux.rb @@ -23,7 +23,7 @@ def self.batch_refresh @proc0 = File.readlines('/proc/stat').grep(/^cpu /).first.split(" ") @bandrx_new0 = self.bandrx @bandtx_new0 = self.bandtx - @diskio_new1 = self.diskio + @diskio_new0 = self.diskio sleep 1