usagewatch 0.0.6.beta2 → 0.0.6.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/usagewatch/linux.rb +131 -128
- data/lib/usagewatch/version.rb +1 -1
- metadata +1 -1
data/lib/usagewatch/linux.rb
CHANGED
@@ -133,50 +133,51 @@ module Usagewatch
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
def self.
|
137
|
-
|
138
|
-
def bandrx
|
136
|
+
def self.bandrx
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
138
|
+
if File.exists?("/proc/net/dev")
|
139
|
+
File.open("/proc/net/dev", "r") do |file|
|
140
|
+
@result = file.read
|
144
141
|
end
|
142
|
+
end
|
145
143
|
|
146
|
-
|
144
|
+
@arrRows = @result.split("\n")
|
147
145
|
|
148
|
-
|
146
|
+
@arrEthLoRows = @arrRows.grep(/eth|lo/)
|
149
147
|
|
150
|
-
|
148
|
+
rowcount = (@arrEthLoRows.count - 1)
|
151
149
|
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
for i in (0..rowcount)
|
151
|
+
@arrEthLoRows[i] = @arrEthLoRows[i].gsub(/\s+/m, ' ').strip.split(" ")
|
152
|
+
end
|
155
153
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
154
|
+
@arrColumns = Array.new
|
155
|
+
for l in (0..rowcount)
|
156
|
+
@temp = Array.new
|
157
|
+
@temp[0] = @arrEthLoRows[l][1]
|
158
|
+
@temp[1] = @arrEthLoRows[l][9]
|
159
|
+
@arrColumns << @temp
|
160
|
+
end
|
163
161
|
|
164
|
-
|
162
|
+
columncount = (@arrColumns[0].count - 1)
|
165
163
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
164
|
+
@arrTotal = Array.new
|
165
|
+
for p in (0..columncount)
|
166
|
+
@arrTotal[p] = 0
|
167
|
+
end
|
170
168
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
end
|
169
|
+
for j in (0..columncount)
|
170
|
+
for k in (0..rowcount)
|
171
|
+
@arrTotal[j] = @arrColumns[k][j].to_i + @arrTotal[j]
|
175
172
|
end
|
176
|
-
|
177
|
-
@bandrxtx= @arrTotal
|
178
173
|
end
|
179
174
|
|
175
|
+
@bandrxtx = @arrTotal
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
def self.uw_bandrx
|
180
|
+
|
180
181
|
@new0 = bandrx
|
181
182
|
sleep 1
|
182
183
|
@new1 = bandrx
|
@@ -186,153 +187,155 @@ module Usagewatch
|
|
186
187
|
@megabitsreceived = (@bitsreceived.to_f / 1024 / 1024).round(3)
|
187
188
|
end
|
188
189
|
|
189
|
-
def self.
|
190
|
-
|
191
|
-
def bandtx
|
190
|
+
def self.bandtx
|
192
191
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
end
|
192
|
+
if File.exists?("/proc/net/dev")
|
193
|
+
File.open("/proc/net/dev", "r") do |file|
|
194
|
+
@result = file.read
|
197
195
|
end
|
196
|
+
end
|
198
197
|
|
199
|
-
|
198
|
+
@arrRows = @result.split("\n")
|
200
199
|
|
201
|
-
|
200
|
+
@arrEthLoRows = @arrRows.grep(/eth|lo/)
|
202
201
|
|
203
|
-
|
202
|
+
rowcount = (@arrEthLoRows.count - 1)
|
204
203
|
|
205
|
-
|
206
|
-
|
207
|
-
|
204
|
+
for i in (0..rowcount)
|
205
|
+
@arrEthLoRows[i] = @arrEthLoRows[i].gsub(/\s+/m, ' ').strip.split(" ")
|
206
|
+
end
|
208
207
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
208
|
+
@arrColumns = Array.new
|
209
|
+
for l in (0..rowcount)
|
210
|
+
@temp = Array.new
|
211
|
+
@temp[0] = @arrEthLoRows[l][1]
|
212
|
+
@temp[1] = @arrEthLoRows[l][9]
|
213
|
+
@arrColumns << @temp
|
214
|
+
end
|
216
215
|
|
217
|
-
|
216
|
+
columncount = (@arrColumns[0].count - 1)
|
218
217
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
218
|
+
@arrTotal = Array.new
|
219
|
+
for p in (0..columncount)
|
220
|
+
@arrTotal[p] = 0
|
221
|
+
end
|
223
222
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
end
|
223
|
+
for j in (0..columncount)
|
224
|
+
for k in (0..rowcount)
|
225
|
+
@arrTotal[j] = @arrColumns[k][j].to_i + @arrTotal[j]
|
228
226
|
end
|
229
|
-
|
230
|
-
@bandrxtx = @arrTotal
|
231
227
|
end
|
232
228
|
|
233
|
-
@
|
229
|
+
@bandrxtx = @arrTotal
|
230
|
+
end
|
231
|
+
|
232
|
+
def self.uw_bandtx
|
233
|
+
|
234
|
+
@new0 = Usagewatch.bandtx
|
234
235
|
sleep 1
|
235
|
-
@new1 = bandtx
|
236
|
+
@new1 = Usagewatch.bandtx
|
236
237
|
|
237
238
|
@bytestransmitted = @new1[1].to_i - @new0[1].to_i
|
238
239
|
@bitstransmitted = (@bytestransmitted * 8)
|
239
240
|
@megabitstransmitted = (@bitstransmitted.to_f / 1024 / 1024).round(3)
|
240
241
|
end
|
241
242
|
|
242
|
-
def self.
|
243
|
+
def self.diskio
|
243
244
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
File.open("/proc/diskstats", "r") do |file|
|
248
|
-
@result = file.read
|
249
|
-
end
|
245
|
+
if File.exists?("/proc/diskstats")
|
246
|
+
File.open("/proc/diskstats", "r") do |file|
|
247
|
+
@result = file.read
|
250
248
|
end
|
249
|
+
end
|
251
250
|
|
252
|
-
|
251
|
+
@arrRows = @result.split("\n")
|
253
252
|
|
254
|
-
|
253
|
+
rowcount = (@arrRows.count - 1)
|
255
254
|
|
256
|
-
|
257
|
-
|
258
|
-
|
255
|
+
for i in (0..rowcount)
|
256
|
+
@arrRows[i] = @arrRows[i].gsub(/\s+/m, ' ').strip.split(" ")
|
257
|
+
end
|
259
258
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
259
|
+
@arrColumns = Array.new
|
260
|
+
for l in (0..rowcount)
|
261
|
+
@temp = Array.new
|
262
|
+
@temp[0] = @arrRows[l][3]
|
263
|
+
@temp[1] = @arrRows[l][7]
|
264
|
+
@arrColumns << @temp
|
265
|
+
end
|
267
266
|
|
268
|
-
|
267
|
+
columncount = (@arrColumns[0].count - 1)
|
269
268
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
269
|
+
@arrTotal = Array.new
|
270
|
+
for p in (0..columncount)
|
271
|
+
@arrTotal[p] = 0
|
272
|
+
end
|
274
273
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
end
|
274
|
+
for j in (0..columncount)
|
275
|
+
for k in (0..rowcount)
|
276
|
+
@arrTotal[j] = @arrColumns[k][j].to_i + @arrTotal[j]
|
279
277
|
end
|
280
|
-
|
281
|
-
@diskiorw= @arrTotal
|
282
278
|
end
|
283
279
|
|
284
|
-
@
|
280
|
+
@diskiorw= @arrTotal
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
def self.uw_diskioreads
|
285
|
+
|
286
|
+
@new0 = Usagewatch.diskio
|
285
287
|
sleep 1
|
286
|
-
@new1 = diskio
|
288
|
+
@new1 = Usagewatch.diskio
|
287
289
|
|
288
290
|
@diskreads = @new1[0].to_i - @new0[0].to_i
|
289
291
|
end
|
290
292
|
|
291
|
-
def self.
|
293
|
+
def self.diskio
|
292
294
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
File.open("/proc/diskstats", "r") do |file|
|
297
|
-
@result = file.read
|
298
|
-
end
|
295
|
+
if File.exists?("/proc/diskstats")
|
296
|
+
File.open("/proc/diskstats", "r") do |file|
|
297
|
+
@result = file.read
|
299
298
|
end
|
299
|
+
end
|
300
300
|
|
301
|
-
|
301
|
+
@arrRows = @result.split("\n")
|
302
302
|
|
303
|
-
|
303
|
+
rowcount = (@arrRows.count - 1)
|
304
304
|
|
305
|
-
|
306
|
-
|
307
|
-
|
305
|
+
for i in (0..rowcount)
|
306
|
+
@arrRows[i] = @arrRows[i].gsub(/\s+/m, ' ').strip.split(" ")
|
307
|
+
end
|
308
308
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
309
|
+
@arrColumns = Array.new
|
310
|
+
for l in (0..rowcount)
|
311
|
+
@temp = Array.new
|
312
|
+
@temp[0] = @arrRows[l][3]
|
313
|
+
@temp[1] = @arrRows[l][7]
|
314
|
+
@arrColumns << @temp
|
315
|
+
end
|
316
316
|
|
317
|
-
|
317
|
+
columncount = (@arrColumns[0].count - 1)
|
318
318
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
319
|
+
@arrTotal = Array.new
|
320
|
+
for p in (0..columncount)
|
321
|
+
@arrTotal[p] = 0
|
322
|
+
end
|
323
323
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
end
|
324
|
+
for j in (0..columncount)
|
325
|
+
for k in (0..rowcount)
|
326
|
+
@arrTotal[j] = @arrColumns[k][j].to_i + @arrTotal[j]
|
328
327
|
end
|
329
|
-
|
330
|
-
@diskiorw= @arrTotal
|
331
328
|
end
|
332
329
|
|
333
|
-
@
|
330
|
+
@diskiorw= @arrTotal
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
def self.uw_diskiowrites
|
335
|
+
|
336
|
+
@new0 = Usagewatch.diskio
|
334
337
|
sleep 1
|
335
|
-
@new1 = diskio
|
338
|
+
@new1 = Usagewatch.diskio
|
336
339
|
|
337
340
|
@diskwrites = @new1[1].to_i - @new0[1].to_i
|
338
341
|
end
|
data/lib/usagewatch/version.rb
CHANGED