diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-10-30 21:40:26 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-10-30 21:40:26 -0700 |
commit | 9ecee5c21d48ab8466977bd8971347eff1f04b2d (patch) | |
tree | e9c5f1f4a937b8d0b82db9ea7c971938249777a7 /src/main/java | |
parent | ab5e0709d0627637fa6b269dd73dc236274b41be (diff) | |
download | traccar-server-9ecee5c21d48ab8466977bd8971347eff1f04b2d.tar.gz traccar-server-9ecee5c21d48ab8466977bd8971347eff1f04b2d.tar.bz2 traccar-server-9ecee5c21d48ab8466977bd8971347eff1f04b2d.zip |
Server to return system info
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/model/Server.java | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/model/Server.java b/src/main/java/org/traccar/model/Server.java index 112bfab26..a1406c6ee 100644 --- a/src/main/java/org/traccar/model/Server.java +++ b/src/main/java/org/traccar/model/Server.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 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,15 +17,10 @@ package org.traccar.model; import org.traccar.database.QueryIgnore; -public class Server extends ExtendedModel { - - @QueryIgnore - public String getVersion() { - return getClass().getPackage().getImplementationVersion(); - } +import java.io.File; +import java.lang.management.ManagementFactory; - public void setVersion(String version) { - } +public class Server extends ExtendedModel { private boolean registration; @@ -176,4 +171,32 @@ public class Server extends ExtendedModel { public void setAnnouncement(String announcement) { this.announcement = announcement; } + + @QueryIgnore + public String getVersion() { + return getClass().getPackage().getImplementationVersion(); + } + + @QueryIgnore + public double getCpuUsage() { + return ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage(); + } + + @QueryIgnore + public double getDiskUsage() { + double total = 0; + double free = 0; + File[] drives = File.listRoots(); + if (drives != null && drives.length > 0) { + for (File drive : drives) { + total += drive.getTotalSpace(); + free += drive.getFreeSpace(); + } + } + if (total > 0) { + return 1 - free / total; + } else { + return 0; + } + } } |