Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce sleep time for multiple methods #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions lib/usagewatch/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_new0 = 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)
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
Expand Down Expand Up @@ -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)
batch_refresh 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
Expand Down Expand Up @@ -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)
batch_refresh 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
Expand Down Expand Up @@ -292,22 +298,16 @@ def self.diskio
end

# Current Disk Reads Completed
def self.uw_diskioreads
def self.uw_diskioreads(now = true)
batch_refresh 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)
batch_refresh if now

@diskwrites = @new1[1].to_i - @new0[1].to_i
@diskwrites = @diskio_new1[1].to_i - @diskio_new0[1].to_i
end
end