JPDH exposes Windows performance data helper (PDH) in the Java programming language, and provides some additional features that should have been in PDH but are not, such as the possibility to refer to processes by PID instead of process instance name (process instance name can change while PID can't).
JPDH is orders of magnitude faster than WMI and is a good alternative to the latter when performance is critical.
JPDH has been integrated as an alternative to WMI in the JRDS performance collector, where it provides much faster response times.
Here's JPDH in action.
import com.arkanosis.jpdh.Counter;
import com.arkanosis.jpdh.JPDH;
import com.arkanosis.jpdh.Query;
try (Query query = JPDH.openQuery()) {
Counter diskCounter = query.addCounter("\\PhysicalDisk(_Total)\\Disk Read Bytes/sec");
Counter cpuCounter = query.addCounter("\\PID(8584)\\% User Time");
query.collectData();
System.out.println(diskCounter.getDoubleValue());
System.out.println(cpuCounter.getIntegerValue());
query.removeCounter(diskCounter);
}
With Maven:
<dependency>
<groupId>com.arkanosis</groupId>
<artifactId>jpdh</artifactId>
<version>1.1.4</version>
</dependency>
With Gradle:
compile("com.arkanosis:jpdh:1.1.4")
JPDH is Copyright (c) 2016-2019, Jérémie Roquet. JPDH is provided under the terms of the BSD 2-clause license.