diff options
author | Anton Tananaev <anton@traccar.org> | 2024-06-13 08:29:01 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-06-13 08:29:01 -0700 |
commit | c9d9a30375e9e4291b41580cb25719b9f5b9e23b (patch) | |
tree | 2d77ed1254f51783f706448d216f18559e0abc1d /src/main | |
parent | 5b2764ff7035376a0125547e294b0e33201d07bc (diff) | |
download | trackermap-server-c9d9a30375e9e4291b41580cb25719b9f5b9e23b.tar.gz trackermap-server-c9d9a30375e9e4291b41580cb25719b9f5b9e23b.tar.bz2 trackermap-server-c9d9a30375e9e4291b41580cb25719b9f5b9e23b.zip |
Report storage by mount point
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/helper/Log.java | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java index 9aaf1cfd3..37df6a537 100644 --- a/src/main/java/org/traccar/helper/Log.java +++ b/src/main/java/org/traccar/helper/Log.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2024 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.traccar.helper; import org.traccar.config.Config; import org.traccar.config.Keys; +import org.traccar.model.Pair; import java.io.BufferedWriter; import java.io.File; @@ -30,9 +31,9 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.FileStore; import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.logging.ConsoleHandler; import java.util.logging.Formatter; @@ -40,6 +41,7 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; +import java.util.stream.Stream; public final class Log { @@ -278,17 +280,22 @@ public final class Log { } public static long[] getStorageSpace() { - long usable = 0; - long total = 0; - for (Path root : FileSystems.getDefault().getRootDirectories()) { + var stores = new ArrayList<Pair<Long, Long>>(); + for (FileStore store : FileSystems.getDefault().getFileStores()) { try { - FileStore store = Files.getFileStore(root); - usable += store.getUsableSpace(); - total += store.getTotalSpace(); + long totalSpace = store.getTotalSpace(); + long usableSpace = store.getUsableSpace(); + if (totalSpace > 1_000_000_000) { + stores.add(new Pair<>(usableSpace, totalSpace)); + } } catch (IOException ignored) { } } - return new long[]{usable, total}; + return stores.stream() + .sorted(Comparator.comparingDouble(o -> 1 - o.getFirst() / (double) o.getSecond())) + .flatMap(p -> Stream.of(p.getFirst(), p.getSecond())) + .mapToLong(Long::longValue) + .toArray(); } } |