* Update InfoService.java

* Update UsageService.java

* Update InfoService.java

* Update InfoService.java

* Update pom.xml

* rework storage
This commit is contained in:
Antony Leons 2024-03-17 01:02:21 +00:00 committed by GitHub
parent baf14d46f6
commit 7833aaecd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -86,16 +86,20 @@ public class UsageService
private int getStorage() {
FileSystem fileSystem = systemInfo.getOperatingSystem().getFileSystem();
// Calculate total storage and free storage
long totalStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getTotalSpace).sum();
long freeStorage = fileSystem.getFileStores().stream().mapToLong(OSFileStore::getFreeSpace).sum();
// Calculate total storage and free storage for all drives
long totalStorage = 0;
long freeStorage = 0;
for (OSFileStore fileStore : fileSystem.getFileStores()) {
totalStorage += fileStore.getTotalSpace();
freeStorage += fileStore.getFreeSpace();
}
// Handle possible division by zero
if (totalStorage == 0) {
return 0; // or handle in a way suitable for your application
}
// Calculate storage usage percentage
// Calculate total storage usage percentage for all drives
return (int) Math.round(((double) (totalStorage - freeStorage) / totalStorage) * 100);
}