2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mikrotik.internal.model;
15 import java.time.LocalDateTime;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.mikrotik.internal.util.Converter;
23 * The {@link RouterosSystemResources} is a model class for RouterOS system info having casting accessors for
24 * data that is available through bridge thing channels.
26 * @author Oleg Vivtash - Initial contribution
29 public class RouterosSystemResources extends RouterosBaseData {
31 public RouterosSystemResources(Map<String, String> props) {
35 public @Nullable Integer getFreeSpace() {
36 return getIntProp("free-hdd-space");
39 public @Nullable Integer getTotalSpace() {
40 return getIntProp("total-hdd-space");
43 public @Nullable Integer getSpaceUse() {
44 Integer freeSpace = getFreeSpace(), totalSpace = getTotalSpace();
45 if (freeSpace == null || totalSpace == null) {
48 return 100 - Math.round(100F * freeSpace / totalSpace);
51 public @Nullable Integer getFreeMem() {
52 return getIntProp("free-memory");
55 public @Nullable Integer getTotalMem() {
56 return getIntProp("total-memory");
59 public @Nullable Integer getMemUse() {
60 Integer freeMem = getFreeMem(), totalMem = getTotalMem();
61 if (freeMem == null || totalMem == null) {
64 return 100 - Math.round(100F * freeMem / totalMem);
67 public @Nullable Integer getCpuLoad() {
68 return getIntProp("cpu-load");
71 public @Nullable String getUptime() {
72 return getProp("uptime");
75 public @Nullable LocalDateTime getUptimeStart() {
76 return Converter.routerosPeriodBack(getUptime());