0

I want to use pure java to get the stats of disk and network. Especially: In Java, how to get disk write and read bytes per seconds, network tx bytes and rx bytes per seconds?

Is that possible?

Zaid Malhis
  • 588
  • 4
  • 18
jamee
  • 553
  • 1
  • 5
  • 25

2 Answers2

0

The proc file system and sysfs give access to statistics like this.

You can read the network tx and rx from /proc/net/dev for example.

Disk statistics can be found in /proc/diskstats.

Joni
  • 108,737
  • 14
  • 143
  • 193
  • I read /proc/net/dev, there are total received bytes and total transmit bytes, but how to get the bytes/secs? total received bytes / uptime? – jamee Aug 17 '15 at 13:23
  • That gives you the average speed bytes/sec for the entire uptime, which is probably not interesting. If you want to know what the transmission speed is "now" it's either 0 or the speed of the interface, which is also not very interesting. Maybe you could read the file every N seconds, compute the difference and divide by N, giving you the average speed over the N-second period. – Joni Aug 17 '15 at 13:39
0

I believe you're asking something similar to the following: Detect CPU Speed/Memory/Internet Speed using Java?.

You may also have some success using the java.lang.management package. Some boilerplate is described here.

Community
  • 1
  • 1
Keith
  • 3,079
  • 2
  • 17
  • 26