JNA-based operating system and hardware information library for Java providing cross-platform access to system metrics
npx @tessl/cli install tessl/maven-com-github-oshi--oshi-core@6.8.00
# OSHI (Operating System & Hardware Information)
1
2
OSHI is a comprehensive Java library that provides cross-platform access to operating system and hardware information without requiring additional native library installations. Built on JNA (Java Native Access), it enables developers to retrieve detailed system metrics including OS version, process information, memory and CPU usage, disk and partition data, hardware devices, and sensor readings across Windows, macOS, and Linux platforms.
3
4
## Package Information
5
6
- **Package Name**: oshi-core
7
- **Package Type**: Maven
8
- **Language**: Java
9
- **Group ID**: com.github.oshi
10
- **Artifact ID**: oshi-core
11
- **Installation**: `<dependency><groupId>com.github.oshi</groupId><artifactId>oshi-core</artifactId><version>6.8.0</version></dependency>`
12
13
## Core Imports
14
15
```java
16
import oshi.SystemInfo;
17
import oshi.hardware.HardwareAbstractionLayer;
18
import oshi.software.os.OperatingSystem;
19
```
20
21
For specific components:
22
23
```java
24
import oshi.hardware.CentralProcessor;
25
import oshi.hardware.GlobalMemory;
26
import oshi.software.os.OSProcess;
27
import oshi.software.os.FileSystem;
28
```
29
30
## Basic Usage
31
32
```java
33
import oshi.SystemInfo;
34
import oshi.hardware.HardwareAbstractionLayer;
35
import oshi.software.os.OperatingSystem;
36
37
// Create SystemInfo instance - main entry point
38
SystemInfo si = new SystemInfo();
39
40
// Get hardware information
41
HardwareAbstractionLayer hal = si.getHardware();
42
long totalMemory = hal.getMemory().getTotal();
43
String cpuName = hal.getProcessor().getProcessorIdentifier().getName();
44
45
// Get operating system information
46
OperatingSystem os = si.getOperatingSystem();
47
String osFamily = os.getFamily();
48
int processCount = os.getProcessCount();
49
50
System.out.println("OS: " + osFamily);
51
System.out.println("CPU: " + cpuName);
52
System.out.println("Memory: " + totalMemory / 1024 / 1024 + " MB");
53
System.out.println("Processes: " + processCount);
54
```
55
56
## Architecture
57
58
OSHI is built around several key components:
59
60
- **SystemInfo**: Main entry point providing access to hardware and operating system abstractions
61
- **Hardware Abstraction Layer**: Unified interface to hardware components (CPU, memory, disks, network, sensors)
62
- **Operating System Interface**: Access to OS-specific information (processes, file systems, network configuration)
63
- **Platform Detection**: Automatic detection and instantiation of platform-specific implementations
64
- **Cross-Platform Compatibility**: Single API works across Windows, macOS, Linux, FreeBSD, Solaris, and AIX
65
66
## Capabilities
67
68
### System Information
69
70
Core entry point and platform detection for accessing system information across different operating systems.
71
72
```java { .api }
73
class SystemInfo {
74
SystemInfo();
75
OperatingSystem getOperatingSystem();
76
HardwareAbstractionLayer getHardware();
77
static PlatformEnum getCurrentPlatform();
78
}
79
80
enum PlatformEnum {
81
MACOS, LINUX, WINDOWS, SOLARIS, FREEBSD, OPENBSD, WINDOWSCE, AIX, ANDROID, GNU, KFREEBSD, NETBSD, UNKNOWN;
82
String getName();
83
static PlatformEnum getValue(int osType);
84
}
85
```
86
87
[System Information](./system-info.md)
88
89
### Hardware Information
90
91
Comprehensive hardware component access including CPU, memory, storage, network interfaces, and sensors with detailed performance metrics.
92
93
```java { .api }
94
interface HardwareAbstractionLayer {
95
CentralProcessor getProcessor();
96
GlobalMemory getMemory();
97
List<HWDiskStore> getDiskStores();
98
List<NetworkIF> getNetworkIFs();
99
List<PowerSource> getPowerSources();
100
ComputerSystem getComputerSystem();
101
List<Display> getDisplays();
102
Sensors getSensors();
103
List<UsbDevice> getUsbDevices(boolean tree);
104
List<SoundCard> getSoundCards();
105
List<GraphicsCard> getGraphicsCards();
106
}
107
```
108
109
[Hardware Information](./hardware.md)
110
111
### Operating System Information
112
113
Operating system details, process management, file system access, and network configuration with comprehensive process monitoring capabilities.
114
115
```java { .api }
116
interface OperatingSystem {
117
String getFamily();
118
String getManufacturer();
119
OSVersionInfo getVersionInfo();
120
FileSystem getFileSystem();
121
List<OSProcess> getProcesses();
122
OSProcess getProcess(int pid);
123
int getProcessCount();
124
int getBitness();
125
long getSystemUptime();
126
NetworkParams getNetworkParams();
127
List<OSSession> getSessions();
128
List<OSService> getServices();
129
}
130
```
131
132
[Operating System Information](./operating-system.md)
133
134
### Process Management
135
136
Detailed process and thread information including CPU usage, memory consumption, and process relationships with filtering and sorting capabilities.
137
138
```java { .api }
139
interface OSProcess {
140
String getName();
141
String getPath();
142
String getCommandLine();
143
int getProcessID();
144
int getParentProcessID();
145
long getVirtualSize();
146
long getResidentSetSize();
147
double getProcessCpuLoadCumulative();
148
List<OSThread> getThreadDetails();
149
State getState();
150
}
151
```
152
153
[Process Management](./process-management.md)
154
155
### File System Access
156
157
File system information, mount points, disk usage statistics, and file store details with comprehensive storage metrics.
158
159
```java { .api }
160
interface FileSystem {
161
List<OSFileStore> getFileStores();
162
long getOpenFileDescriptors();
163
long getMaxFileDescriptors();
164
}
165
166
interface OSFileStore {
167
String getName();
168
String getType();
169
long getTotalSpace();
170
long getFreeSpace();
171
long getUsableSpace();
172
String getMount();
173
}
174
```
175
176
[File System Access](./file-system.md)
177
178
### Network Information
179
180
Network interface details, IP configuration, and network statistics including bandwidth usage and connection information.
181
182
```java { .api }
183
interface NetworkIF {
184
String getName();
185
String getDisplayName();
186
String getMacaddr();
187
String[] getIPv4addr();
188
String[] getIPv6addr();
189
long getBytesRecv();
190
long getBytesSent();
191
long getSpeed();
192
}
193
```
194
195
[Network Information](./network.md)
196
197
## Types
198
199
### Core Types
200
201
```java { .api }
202
class SystemInfo {
203
// Main entry point - no-arg constructor
204
}
205
206
enum PlatformEnum {
207
MACOS("macOS"),
208
LINUX("Linux"),
209
WINDOWS("Windows"),
210
SOLARIS("Solaris"),
211
FREEBSD("FreeBSD"),
212
OPENBSD("OpenBSD"),
213
AIX("AIX"),
214
ANDROID("Android"),
215
UNKNOWN("Unknown");
216
}
217
```
218
219
### Hardware Types
220
221
```java { .api }
222
interface HardwareAbstractionLayer {
223
// Hardware component access methods
224
}
225
226
interface CentralProcessor {
227
ProcessorIdentifier getProcessorIdentifier();
228
long getMaxFreq();
229
long[] getCurrentFreq();
230
List<LogicalProcessor> getLogicalProcessors();
231
int getLogicalProcessorCount();
232
int getPhysicalProcessorCount();
233
}
234
235
interface GlobalMemory {
236
long getTotal();
237
long getAvailable();
238
long getPageSize();
239
VirtualMemory getVirtualMemory();
240
List<PhysicalMemory> getPhysicalMemory();
241
}
242
243
interface ComputerSystem {
244
String getManufacturer();
245
String getModel();
246
String getSerialNumber();
247
String getHardwareUUID();
248
Firmware getFirmware();
249
Baseboard getBaseboard();
250
}
251
```
252
253
### Operating System Types
254
255
```java { .api }
256
interface OperatingSystem {
257
// OS information and process management methods
258
}
259
260
class OSVersionInfo {
261
String getVersion();
262
String getCodeName();
263
String getBuildNumber();
264
}
265
266
interface OSProcess {
267
enum State {
268
NEW, RUNNING, SLEEPING, WAITING, ZOMBIE, STOPPED, OTHER, INVALID, SUSPENDED
269
}
270
}
271
272
interface OSThread {
273
String getName();
274
int getThreadId();
275
OSProcess.State getState();
276
long getStartTime();
277
int getPriority();
278
}
279
```
280
281
### Process Filtering and Sorting
282
283
```java { .api }
284
class ProcessFiltering {
285
static final Predicate<OSProcess> ALL_PROCESSES;
286
static final Predicate<OSProcess> VALID_PROCESS;
287
static final Predicate<OSProcess> NO_PARENT;
288
static final Predicate<OSProcess> BITNESS_64;
289
static final Predicate<OSProcess> BITNESS_32;
290
}
291
292
class ProcessSorting {
293
static final Comparator<OSProcess> NO_SORTING;
294
static final Comparator<OSProcess> CPU_DESC;
295
static final Comparator<OSProcess> RSS_DESC;
296
static final Comparator<OSProcess> UPTIME_ASC;
297
static final Comparator<OSProcess> UPTIME_DESC;
298
static final Comparator<OSProcess> PID_ASC;
299
static final Comparator<OSProcess> PARENTPID_ASC;
300
static final Comparator<OSProcess> NAME_ASC;
301
}
302
```