nethacker / usagewatch

A Ruby Gem with methods to find usage statistics on a Linux server such as CPU, Disk, TCP/UDP Connections, Load, Bandwidth, Disk I/O, and Memory
MIT License
79 stars 38 forks source link

On Ubuntu 14.04, usagewatch seems not to work properly #14

Open jpahullo opened 10 years ago

jpahullo commented 10 years ago

Hi all,

I have just upgraded to a Ubuntu 14.04 a server machine where we had a little script using your usagewatch gem, to return a json string just for monitoring. Before upgrading, the script showed a 20% of used hard disk. After upgrading, it always shows 0%.

After upgrading, as root, I run:

  1. gem install usagewatch
  2. gem install json

The script is as simple as this:

#/usr/bin/ruby

require 'usagewatch'
require 'json'

usw = Usagewatch

disk_io = usw.uw_diskioreads.to_i + usw.uw_diskiowrites.to_i
network = usw.uw_bandrx.to_i + usw.uw_bandtx.to_i
usage = {
  name: 'sredb',
  cpu: usw.uw_cpuused.to_s + ' %',
  memory: usw.uw_memused.to_s + ' %',
  disk_io: disk_io.to_s + ' op/s',
  disk_space: usw.uw_diskused_perc.to_s + ' %',
  network: network.to_s + ' Mbit/s'
}

puts usage.to_json

Do you know any issue related to this? Could you help me please? Can it be caused by some gem not installed yet?

Looking forward to hearing from you,

Saludos,

Jordi

geocom commented 10 years ago

Can you post what is returned when you do a "df --total" In the terminal.

Most likely to be an issue with usage watch picking up the wrong field from df --total

jpahullo commented 10 years ago

Hi,

Here you are:

/dev/sda5          95989516   1611420   89478976   2% /
none                      4         0          4   0% /sys/fs/cgroup
udev                8190112         4    8190108   1% /dev
tmpfs               1640180       504    1639676   1% /run
none                   5120         0       5120   0% /run/lock
none                8200880         0    8200880   0% /run/shm
none                 102400         0     102400   0% /run/user
/dev/sdd1         961301832 358728024  553719384  40% /backup
/dev/sdb5         480588496 104435124  351717764  23% /sre
/dev/sda7         861333320    197604  817359412   1% /home
/dev/sdc5         961301832 225215088  687232320  25% /var
total            3378653692 690187768 2517646044  22% -

Let me know.

Thanks in advance!

Jordi

jpahullo commented 10 years ago

I think it is possible that other fields are getting wrong, like the cpu usage, disk io or network usage (from what we use in our script), since they are always zero from the Ubuntu upgrade and on.

Thanks!

Jordi

geocom commented 10 years ago

The code does a split(" ") and picks the last field. In your case this is going to be - so that is why it is 0.

You could do a fork and change df.split(" ").last.to_f.round(2) To df.split("\n").last.split(" ")[4].to_f.round(2)

As you can guess from the pooling pull requests this is unlikely to be merged.

geocom commented 10 years ago

FYI it is Line 19 in usagewatch / lib / usagewatch / linux.rb

jpahullo commented 10 years ago

ok

jpahullo commented 10 years ago

Done.

See PR.

However, I cannot make behave correctly the diskio.

What should it be expected to show for read and write on the folloing content of cat /proc/diskstats of the Ubuntu 14.04? The content is similar to that of an Ubuntu 12.

   1       0 ram0 0 0 0 0 0 0 0 0 0 0 0
   1       1 ram1 0 0 0 0 0 0 0 0 0 0 0
   1       2 ram2 0 0 0 0 0 0 0 0 0 0 0
   1       3 ram3 0 0 0 0 0 0 0 0 0 0 0
   1       4 ram4 0 0 0 0 0 0 0 0 0 0 0
   1       5 ram5 0 0 0 0 0 0 0 0 0 0 0
   1       6 ram6 0 0 0 0 0 0 0 0 0 0 0
   1       7 ram7 0 0 0 0 0 0 0 0 0 0 0
   1       8 ram8 0 0 0 0 0 0 0 0 0 0 0
   1       9 ram9 0 0 0 0 0 0 0 0 0 0 0
   1      10 ram10 0 0 0 0 0 0 0 0 0 0 0
   1      11 ram11 0 0 0 0 0 0 0 0 0 0 0
   1      12 ram12 0 0 0 0 0 0 0 0 0 0 0
   1      13 ram13 0 0 0 0 0 0 0 0 0 0 0
   1      14 ram14 0 0 0 0 0 0 0 0 0 0 0
   1      15 ram15 0 0 0 0 0 0 0 0 0 0 0
   7       0 loop0 0 0 0 0 0 0 0 0 0 0 0
   7       1 loop1 0 0 0 0 0 0 0 0 0 0 0
   7       2 loop2 0 0 0 0 0 0 0 0 0 0 0
   7       3 loop3 0 0 0 0 0 0 0 0 0 0 0
   7       4 loop4 0 0 0 0 0 0 0 0 0 0 0
   7       5 loop5 0 0 0 0 0 0 0 0 0 0 0
   7       6 loop6 0 0 0 0 0 0 0 0 0 0 0
   7       7 loop7 0 0 0 0 0 0 0 0 0 0 0
   8       0 sda 16855 885 404808 87512 1369 5004 197520 49692 0 21484 137204
   8       1 sda1 2 0 4 16 0 0 0 0 0 16 16
   8       5 sda5 16184 765 398498 78988 1320 4977 196944 48544 0 19868 127532
   8       6 sda6 161 31 1536 1652 0 0 0 0 0 1652 1652
   8       7 sda7 321 89 3274 3624 43 27 576 496 0 3448 4120
   8      16 sdb 554 87 5110 832 5 0 24 24 0 660 852
   8      17 sdb1 2 0 4 60 0 0 0 0 0 60 60
   8      21 sdb5 368 87 3634 564 3 0 24 0 0 560 564
   8      32 sdc 54465 13215 2360446 226840 1576 1626 191520 31556 0 202032 258360
   8      33 sdc1 2 0 4 0 0 0 0 0 0 0 0
   8      37 sdc5 54277 13215 2358954 226348 1569 1626 191520 31184 0 201220 257496
   8      48 sdd 577 87 5306 684 5 0 24 40 0 720 724
   8      49 sdd1 397 87 3866 236 3 0 24 0 0 232 236
  11       0 sr0 0 0 0 0 0 0 0 0 0 0 0

Let me know if I could do something else ;-)

Jordi

geocom commented 10 years ago

What are you getting that you think is incorrect?

nethacker commented 10 years ago

I intend to release a version that will detect if you are using Ubuntu or CentOS and each version etc and parse the /proc data properly (Apparently proc data does change even between minor versions of the same distro in regard to position and fields). I have been a bit busy and will do this in the next couple of weeks.

jpahullo commented 10 years ago

Hi all,

@geocom, maybe the post is correct and gets the sum of readings and writings to zero. However, the server holds a database engine, which we were using while I did tests of the diskio, and I always got zero for the sum of readings and writings to disk. Quite strange, doesn't it?

@nethacker, thanks for your comments. I didn't know that about /proc structure. Thanks in advance. If you need some feedback for some command testing, go ahead :+1:

Thanks!

Jordi