aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src/main/java/me
diff options
context:
space:
mode:
authorPaint_Ninja <PaintNinja@users.noreply.github.com>2022-08-07 19:04:33 +0100
committerGitHub <noreply@github.com>2022-08-07 19:04:33 +0100
commit0d3b71f3163d34a35506668066f94fcad8d5c6f8 (patch)
tree21662cd5a86f983436b816a75ac1acabdf2ca190 /spark-common/src/main/java/me
parentf9c898caf921c47f9c6d94f9c1e7d19905b55c07 (diff)
downloadspark-0d3b71f3163d34a35506668066f94fcad8d5c6f8.tar.gz
spark-0d3b71f3163d34a35506668066f94fcad8d5c6f8.tar.bz2
spark-0d3b71f3163d34a35506668066f94fcad8d5c6f8.zip
Improve operating system info (#238)
Diffstat (limited to 'spark-common/src/main/java/me')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/monitor/os/OperatingSystemInfo.java78
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/platform/PlatformStatisticsProvider.java5
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/util/LinuxProc.java7
3 files changed, 87 insertions, 3 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/os/OperatingSystemInfo.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/os/OperatingSystemInfo.java
new file mode 100644
index 0000000..4eeebd1
--- /dev/null
+++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/os/OperatingSystemInfo.java
@@ -0,0 +1,78 @@
+/*
+ * This file is part of spark.
+ *
+ * Copyright (c) lucko (Luck) <luck@lucko.me>
+ * Copyright (c) contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package me.lucko.spark.common.monitor.os;
+
+import me.lucko.spark.common.util.LinuxProc;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public enum OperatingSystemInfo {
+ ;
+
+ private static String name = null;
+ private static String version = null;
+
+ static {
+ final String osNameJavaProp = System.getProperty("os.name");
+
+ if (osNameJavaProp.startsWith("Windows")) {
+ final String[] args = { "wmic", "os", "get", "caption,version", "/FORMAT:list" };
+ try (final BufferedReader buf = new BufferedReader(new InputStreamReader(new ProcessBuilder(args).redirectErrorStream(true).start().getInputStream()))) {
+ String line;
+ while ((line = buf.readLine()) != null) {
+ if (line.startsWith("Caption")) {
+ name = line.substring(18).trim();
+ } else if (line.startsWith("Version")) {
+ version = line.substring(8).trim();
+ }
+ }
+ } catch (final IOException | IndexOutOfBoundsException e) {
+ // ignore
+ }
+ } else {
+ for (final String line : LinuxProc.OSINFO.read()) {
+ if (line.startsWith("PRETTY_NAME")) {
+ try {
+ name = line.substring(13).replace('"', ' ').trim();
+ } catch (final IndexOutOfBoundsException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ if (name == null)
+ name = osNameJavaProp;
+
+ if (version == null)
+ version = System.getProperty("os.version");
+ }
+
+ public static String getName() {
+ return name;
+ }
+
+ public static String getVersion() {
+ return version;
+ }
+}
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformStatisticsProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformStatisticsProvider.java
index 49cfed5..e5be647 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformStatisticsProvider.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/platform/PlatformStatisticsProvider.java
@@ -28,6 +28,7 @@ import me.lucko.spark.common.monitor.memory.GarbageCollectorStatistics;
import me.lucko.spark.common.monitor.memory.MemoryInfo;
import me.lucko.spark.common.monitor.net.NetworkInterfaceAverages;
import me.lucko.spark.common.monitor.net.NetworkMonitor;
+import me.lucko.spark.common.monitor.os.OperatingSystemInfo;
import me.lucko.spark.common.monitor.ping.PingStatistics;
import me.lucko.spark.common.monitor.tick.TickStatistics;
import me.lucko.spark.common.platform.world.WorldInfoProvider;
@@ -87,8 +88,8 @@ public class PlatformStatisticsProvider {
)
.setOs(SystemStatistics.Os.newBuilder()
.setArch(System.getProperty("os.arch"))
- .setName(System.getProperty("os.name"))
- .setVersion(System.getProperty("os.version"))
+ .setName(OperatingSystemInfo.getName())
+ .setVersion(OperatingSystemInfo.getVersion())
.build()
)
.setJava(SystemStatistics.Java.newBuilder()
diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/LinuxProc.java b/spark-common/src/main/java/me/lucko/spark/common/util/LinuxProc.java
index 7d688d7..44fd3f9 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/util/LinuxProc.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/util/LinuxProc.java
@@ -49,7 +49,12 @@ public enum LinuxProc {
/**
* Information about the system network usage.
*/
- NET_DEV("/proc/net/dev");
+ NET_DEV("/proc/net/dev"),
+
+ /**
+ * Information about the operating system distro.
+ */
+ OSINFO("/etc/os-release");
private final Path path;