From 9ecee5c21d48ab8466977bd8971347eff1f04b2d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 30 Oct 2020 21:40:26 -0700 Subject: Server to return system info --- src/main/java/org/traccar/model/Server.java | 41 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'src/main') 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; + } + } } -- cgit v1.2.3