If you are thinking of a more efficient and reliable solution, perhaps you can use the idea of SNMP (Simple Network Management Protocol). There are several APIs available for use, SNMP4J is the most famous and open source. Since SNMP is supported across several operating systems, and even switches and routers, it is probably a good idea to use it to get detailed network-level statistics. But if you want a simpler solution, use the Sigar API, which supports many operating systems, including windows and linux. One problem with Sigar is that it is licensed under the GPL, which prevents you from deploying it in a commercial project.
source share