Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.server; |
| 18 | |
| 19 | import org.onosproject.drivers.server.behavior.CpuStatisticsDiscovery; |
| 20 | import org.onosproject.drivers.server.behavior.MonitoringStatisticsDiscovery; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 21 | import org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice; |
| 22 | import org.onosproject.drivers.server.devices.cpu.CpuDevice; |
| 23 | import org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice; |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 24 | import org.onosproject.drivers.server.devices.nic.NicDevice; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 25 | import org.onosproject.drivers.server.devices.ServerDeviceDescription; |
| 26 | import org.onosproject.drivers.server.devices.RestServerSBDevice; |
| 27 | import org.onosproject.drivers.server.stats.CpuStatistics; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 28 | import org.onosproject.drivers.server.stats.MemoryStatistics; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 29 | import org.onosproject.drivers.server.stats.MonitoringStatistics; |
| 30 | import org.onosproject.drivers.server.stats.TimingStatistics; |
| 31 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 32 | import org.onosproject.drivers.server.impl.devices.DefaultBasicCpuCacheDevice; |
| 33 | import org.onosproject.drivers.server.impl.devices.DefaultCpuCacheHierarchyDevice; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 34 | import org.onosproject.drivers.server.impl.devices.DefaultCpuDevice; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 35 | import org.onosproject.drivers.server.impl.devices.DefaultMemoryHierarchyDevice; |
| 36 | import org.onosproject.drivers.server.impl.devices.DefaultMemoryModuleDevice; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 37 | import org.onosproject.drivers.server.impl.devices.DefaultNicDevice; |
| 38 | import org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice; |
| 39 | import org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription; |
| 40 | import org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 41 | import org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 42 | import org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics; |
| 43 | import org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics; |
| 44 | |
| 45 | import org.onlab.packet.ChassisId; |
| 46 | import org.onosproject.net.AnnotationKeys; |
| 47 | import org.onosproject.net.Device; |
| 48 | import org.onosproject.net.DeviceId; |
| 49 | import org.onosproject.net.DefaultAnnotations; |
| 50 | import org.onosproject.net.behaviour.DevicesDiscovery; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 51 | import org.onosproject.net.behaviour.DeviceCpuStats; |
| 52 | import org.onosproject.net.behaviour.DeviceMemoryStats; |
| 53 | import org.onosproject.net.behaviour.DeviceSystemStatisticsQuery; |
| 54 | import org.onosproject.net.behaviour.DeviceSystemStats; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 55 | import org.onosproject.net.device.DeviceDescription; |
| 56 | import org.onosproject.net.device.DeviceDescriptionDiscovery; |
| 57 | import org.onosproject.net.device.DefaultPortStatistics; |
| 58 | import org.onosproject.net.device.DefaultPortDescription; |
| 59 | import org.onosproject.net.device.PortDescription; |
| 60 | import org.onosproject.net.device.PortStatistics; |
| 61 | import org.onosproject.net.device.PortStatisticsDiscovery; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 62 | import org.onosproject.net.PortNumber; |
| 63 | import org.onosproject.protocol.rest.RestSBDevice; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 64 | |
| 65 | import org.slf4j.Logger; |
| 66 | |
| 67 | import com.fasterxml.jackson.core.type.TypeReference; |
| 68 | import com.fasterxml.jackson.databind.JsonNode; |
| 69 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 70 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 71 | |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 72 | import com.google.common.base.Strings; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 73 | import com.google.common.collect.Lists; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 74 | import com.google.common.collect.Sets; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 75 | import com.google.common.collect.ImmutableList; |
| 76 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 77 | import java.io.InputStream; |
| 78 | import java.io.IOException; |
| 79 | import java.net.URI; |
| 80 | import java.net.URISyntaxException; |
| 81 | import java.util.ArrayList; |
| 82 | import java.util.Collection; |
| 83 | import java.util.Collections; |
| 84 | import java.util.HashSet; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 85 | import java.util.List; |
| 86 | import java.util.Map; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 87 | import java.util.Optional; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 88 | import java.util.Set; |
| 89 | import java.util.TreeSet; |
Georgios Katsikas | c699e87 | 2019-05-01 23:26:40 +0200 | [diff] [blame] | 90 | import javax.ws.rs.ProcessingException; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 91 | |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 92 | import static com.google.common.base.Preconditions.checkArgument; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 93 | import static com.google.common.base.Preconditions.checkNotNull; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 94 | import static org.onosproject.drivers.server.Constants.JSON; |
| 95 | import static org.onosproject.drivers.server.Constants.MSG_DEVICE_NULL; |
| 96 | import static org.onosproject.drivers.server.Constants.MSG_DEVICE_ID_NULL; |
| 97 | import static org.onosproject.drivers.server.Constants.MSG_NIC_NAME_NULL; |
| 98 | import static org.onosproject.drivers.server.Constants.MSG_NIC_PORT_NUMBER_NEGATIVE; |
| 99 | import static org.onosproject.drivers.server.Constants.MSG_STATS_TIMING_DEPLOY_INCONSISTENT; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 100 | import static org.onosproject.drivers.server.Constants.PARAM_CAPACITY; |
| 101 | import static org.onosproject.drivers.server.Constants.PARAM_CHASSIS_ID; |
| 102 | import static org.onosproject.drivers.server.Constants.PARAM_CPUS; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 103 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LEVEL; |
| 104 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LEVELS; |
| 105 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_LINE_LEN; |
| 106 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_POLICY; |
| 107 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_SETS; |
| 108 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_SHARED; |
| 109 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_TYPE; |
| 110 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_WAYS; |
| 111 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHES; |
| 112 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CACHE_HIERARCHY; |
| 113 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_CORES; |
| 114 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_FREQUENCY; |
| 115 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_ID_LOG; |
| 116 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_ID_PHY; |
| 117 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_LOAD; |
| 118 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_LATENCY; |
| 119 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_QUEUE; |
| 120 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_SOCKET; |
| 121 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_SOCKETS; |
| 122 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_STATUS; |
| 123 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_THROUGHPUT; |
| 124 | import static org.onosproject.drivers.server.Constants.PARAM_CPU_VENDOR; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 125 | import static org.onosproject.drivers.server.Constants.PARAM_HW_VENDOR; |
| 126 | import static org.onosproject.drivers.server.Constants.PARAM_ID; |
| 127 | import static org.onosproject.drivers.server.Constants.PARAM_MANUFACTURER; |
| 128 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY; |
| 129 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_HIERARCHY; |
| 130 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_MODULES; |
| 131 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_FREE; |
| 132 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_TOTAL; |
| 133 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_STATS_USED; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 134 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_WIDTH_DATA; |
| 135 | import static org.onosproject.drivers.server.Constants.PARAM_MEMORY_WIDTH_TOTAL; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 136 | import static org.onosproject.drivers.server.Constants.PARAM_NAME; |
| 137 | import static org.onosproject.drivers.server.Constants.PARAM_NICS; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 138 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_HW_ADDR; |
| 139 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_PORT_TYPE; |
| 140 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_RX_FILTER; |
| 141 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_RX_COUNT; |
| 142 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_RX_BYTES; |
| 143 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_RX_DROPS; |
| 144 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_RX_ERRORS; |
| 145 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_TX_COUNT; |
| 146 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_TX_BYTES; |
| 147 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_TX_DROPS; |
| 148 | import static org.onosproject.drivers.server.Constants.PARAM_NIC_STATS_TX_ERRORS; |
| 149 | import static org.onosproject.drivers.server.Constants.PARAM_MON_AVERAGE; |
| 150 | import static org.onosproject.drivers.server.Constants.PARAM_MON_BUSY_CPUS; |
| 151 | import static org.onosproject.drivers.server.Constants.PARAM_MON_FREE_CPUS; |
| 152 | import static org.onosproject.drivers.server.Constants.PARAM_MON_MAX; |
| 153 | import static org.onosproject.drivers.server.Constants.PARAM_MON_MIN; |
| 154 | import static org.onosproject.drivers.server.Constants.PARAM_MON_UNIT; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 155 | import static org.onosproject.drivers.server.Constants.PARAM_SERIAL; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 156 | import static org.onosproject.drivers.server.Constants.PARAM_SPEED; |
| 157 | import static org.onosproject.drivers.server.Constants.PARAM_SPEED_CONF; |
| 158 | import static org.onosproject.drivers.server.Constants.PARAM_STATUS; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 159 | import static org.onosproject.drivers.server.Constants.PARAM_SW_VENDOR; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 160 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_AUTOSCALE; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 161 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_DEPLOY; |
| 162 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_LAUNCH; |
| 163 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_PARSE; |
| 164 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS; |
| 165 | import static org.onosproject.drivers.server.Constants.PARAM_TIMING_STATS_AUTOSCALE; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 166 | import static org.onosproject.drivers.server.Constants.PARAM_TYPE; |
| 167 | import static org.onosproject.drivers.server.Constants.SLASH; |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 168 | import static org.onosproject.drivers.server.Constants.URL_SERVICE_CHAINS_STATS; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 169 | import static org.onosproject.drivers.server.Constants.URL_SRV_GLOBAL_STATS; |
| 170 | import static org.onosproject.drivers.server.Constants.URL_SRV_RESOURCE_DISCOVERY; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 171 | import static org.slf4j.LoggerFactory.getLogger; |
| 172 | |
| 173 | /** |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 174 | * Discovers the device details of server devices. |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 175 | */ |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 176 | public class ServerDevicesDiscovery |
| 177 | extends BasicServerDriver |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 178 | implements DevicesDiscovery, DeviceDescriptionDiscovery, |
| 179 | PortStatisticsDiscovery, CpuStatisticsDiscovery, |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 180 | MonitoringStatisticsDiscovery, DeviceSystemStatisticsQuery { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 181 | |
| 182 | private final Logger log = getLogger(getClass()); |
| 183 | |
| 184 | /** |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 185 | * Auxiliary constants. |
| 186 | */ |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 187 | private static final short DISCOVERY_RETRIES = 3; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 188 | |
| 189 | /** |
| 190 | * Constructs server device discovery. |
| 191 | */ |
| 192 | public ServerDevicesDiscovery() { |
| 193 | super(); |
| 194 | log.debug("Started"); |
| 195 | } |
| 196 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 197 | /** |
| 198 | * Implements DevicesDiscovery behaviour. |
| 199 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 200 | @Override |
| 201 | public Set<DeviceId> deviceIds() { |
| 202 | // Set of devices to return |
| 203 | Set<DeviceId> devices = new HashSet<DeviceId>(); |
| 204 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 205 | DeviceId deviceId = getDeviceId(); |
| 206 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 207 | devices.add(deviceId); |
| 208 | |
| 209 | return devices; |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public DeviceDescription deviceDetails(DeviceId deviceId) { |
| 214 | return getDeviceDetails(deviceId); |
| 215 | } |
| 216 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 217 | /** |
| 218 | * Implements DeviceDescriptionDiscovery behaviour. |
| 219 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 220 | @Override |
| 221 | public DeviceDescription discoverDeviceDetails() { |
| 222 | return getDeviceDetails(null); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Query a server to retrieve its features. |
| 227 | * |
| 228 | * @param deviceId the device ID to be queried |
| 229 | * @return a DeviceDescription with the device's features |
| 230 | */ |
| 231 | private DeviceDescription getDeviceDetails(DeviceId deviceId) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 232 | // Retrieve the device ID, if null given |
| 233 | if (deviceId == null) { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 234 | deviceId = getDeviceId(); |
| 235 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // Get the device |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 239 | RestSBDevice device = getDevice(deviceId); |
| 240 | checkNotNull(device, MSG_DEVICE_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 241 | |
| 242 | // Hit the path that provides the server's resources |
| 243 | InputStream response = null; |
| 244 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 245 | response = getController().get(deviceId, URL_SRV_RESOURCE_DISCOVERY, JSON); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 246 | } catch (ProcessingException pEx) { |
| 247 | log.error("Failed to discover the device details of: {}", deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 248 | return null; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | // Load the JSON into objects |
| 252 | ObjectMapper mapper = new ObjectMapper(); |
| 253 | Map<String, Object> jsonMap = null; |
| 254 | JsonNode jsonNode = null; |
| 255 | ObjectNode objNode = null; |
| 256 | try { |
| 257 | jsonMap = mapper.readValue(response, Map.class); |
| 258 | jsonNode = mapper.convertValue(jsonMap, JsonNode.class); |
| 259 | objNode = (ObjectNode) jsonNode; |
| 260 | } catch (IOException ioEx) { |
| 261 | log.error("Failed to discover the device details of: {}", deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 262 | return null; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | if (jsonMap == null) { |
| 266 | log.error("Failed to discover the device details of: {}", deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 267 | return null; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // Get all the attributes |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 271 | String id = get(jsonNode, PARAM_ID); |
| 272 | String vendor = get(jsonNode, PARAM_MANUFACTURER); |
| 273 | String hw = get(jsonNode, PARAM_HW_VENDOR); |
| 274 | String sw = get(jsonNode, PARAM_SW_VENDOR); |
| 275 | String serial = get(jsonNode, PARAM_SERIAL); |
| 276 | long chassisId = objNode.path(PARAM_CHASSIS_ID).asLong(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 277 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 278 | // Pass the southbound protocol as an annotation |
| 279 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder(); |
| 280 | annotations.set(AnnotationKeys.PROTOCOL, "REST"); |
| 281 | |
| 282 | // Parse CPU devices |
| 283 | Collection<CpuDevice> cpuSet = parseCpuDevices(objNode); |
| 284 | |
| 285 | // Parse memory hierarchy device |
| 286 | MemoryHierarchyDevice memHierarchyDev = parseMemoryHierarchyDevice(objNode); |
| 287 | |
| 288 | // Parse CPU cache hierachy device |
| 289 | CpuCacheHierarchyDevice cacheHierarchyDev = parseCpuCacheHierarchyDevice(objNode); |
| 290 | |
| 291 | // NICs are composite attributes too |
| 292 | Collection<NicDevice> nicSet = parseNicDevices(mapper, objNode, annotations); |
| 293 | |
| 294 | // Construct a server device, |
| 295 | // i.e., a RestSBDevice extended with CPU, cache, memory, and NIC information |
| 296 | RestServerSBDevice dev = new DefaultRestServerSBDevice( |
| 297 | device.ip(), device.port(), device.username(), |
| 298 | device.password(), device.protocol(), device.url(), |
| 299 | device.isActive(), device.testUrl().orElse(""), |
| 300 | vendor, hw, sw, cpuSet, cacheHierarchyDev, |
| 301 | memHierarchyDev, nicSet); |
| 302 | checkNotNull(dev, MSG_DEVICE_NULL); |
| 303 | |
| 304 | // Set alive |
| 305 | raiseDeviceReconnect(dev); |
| 306 | |
| 307 | // Updates the controller with the complete device information |
| 308 | getController().removeDevice(deviceId); |
| 309 | getController().addDevice((RestSBDevice) dev); |
| 310 | |
| 311 | // Create a description for this server device |
| 312 | ServerDeviceDescription desc = null; |
| 313 | try { |
| 314 | desc = new DefaultServerDeviceDescription( |
| 315 | new URI(id), Device.Type.SERVER, vendor, |
| 316 | hw, sw, serial, new ChassisId(chassisId), |
| 317 | cpuSet, cacheHierarchyDev, memHierarchyDev, |
| 318 | nicSet, annotations.build()); |
| 319 | } catch (URISyntaxException uEx) { |
| 320 | log.error("Failed to create a server device description for: {}", |
| 321 | deviceId); |
| 322 | return null; |
| 323 | } |
| 324 | |
| 325 | log.info("Device's {} details sent to the controller", deviceId); |
| 326 | |
| 327 | return desc; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Parse the input JSON object, looking for CPU-related |
| 332 | * information. Upon success, construct and return a list |
| 333 | * of CPU devices. |
| 334 | * |
| 335 | * @param objNode input JSON node with CPU device information |
| 336 | * @return list of CPU devices |
| 337 | */ |
| 338 | private Collection<CpuDevice> parseCpuDevices(ObjectNode objNode) { |
| 339 | Collection<CpuDevice> cpuSet = Sets.newHashSet(); |
| 340 | JsonNode cpuNode = objNode.path(PARAM_CPUS); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 341 | |
| 342 | // Construct CPU objects |
| 343 | for (JsonNode cn : cpuNode) { |
| 344 | ObjectNode cpuObjNode = (ObjectNode) cn; |
| 345 | |
| 346 | // All the CPU attributes |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 347 | int physicalCpuId = cpuObjNode.path(PARAM_CPU_ID_PHY).asInt(); |
| 348 | int logicalCpuId = cpuObjNode.path(PARAM_CPU_ID_LOG).asInt(); |
| 349 | int cpuSocket = cpuObjNode.path(PARAM_CPU_SOCKET).asInt(); |
| 350 | String cpuVendorStr = get(cn, PARAM_CPU_VENDOR); |
| 351 | long cpuFrequency = cpuObjNode.path(PARAM_CPU_FREQUENCY).asLong(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 352 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 353 | // Construct a CPU device and add it to the set |
| 354 | cpuSet.add( |
| 355 | DefaultCpuDevice.builder() |
| 356 | .setCoreId(logicalCpuId, physicalCpuId) |
| 357 | .setVendor(cpuVendorStr) |
| 358 | .setSocket(cpuSocket) |
| 359 | .setFrequency(cpuFrequency) |
| 360 | .build()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 363 | return cpuSet; |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Parse the input JSON object, looking for CPU cache-related |
| 368 | * information. Upon success, construct and return a CPU cache |
| 369 | * hierarchy device. |
| 370 | * |
| 371 | * @param objNode input JSON node with CPU cache device information |
| 372 | * @return a CPU cache hierarchy devices |
| 373 | */ |
| 374 | private CpuCacheHierarchyDevice parseCpuCacheHierarchyDevice(ObjectNode objNode) { |
| 375 | JsonNode cacheHierarchyNode = objNode.path(PARAM_CPU_CACHE_HIERARCHY); |
| 376 | ObjectNode cacheHierarchyObjNode = (ObjectNode) cacheHierarchyNode; |
| 377 | if (cacheHierarchyObjNode == null) { |
| 378 | return null; |
| 379 | } |
| 380 | |
| 381 | int socketsNb = cacheHierarchyObjNode.path(PARAM_CPU_SOCKETS).asInt(); |
| 382 | int coresNb = cacheHierarchyObjNode.path(PARAM_CPU_CORES).asInt(); |
| 383 | int levels = cacheHierarchyObjNode.path(PARAM_CPU_CACHE_LEVELS).asInt(); |
| 384 | |
| 385 | JsonNode cacheNode = cacheHierarchyObjNode.path(PARAM_CPU_CACHES); |
| 386 | |
| 387 | DefaultCpuCacheHierarchyDevice.Builder cacheBuilder = |
| 388 | DefaultCpuCacheHierarchyDevice.builder() |
| 389 | .setSocketsNumber(socketsNb) |
| 390 | .setCoresNumber(coresNb) |
| 391 | .setLevels(levels); |
| 392 | |
| 393 | // Construct CPU cache objects |
| 394 | for (JsonNode cn : cacheNode) { |
| 395 | ObjectNode cacheObjNode = (ObjectNode) cn; |
| 396 | |
| 397 | // CPU cache attributes |
| 398 | String cpuVendorStr = get(cn, PARAM_CPU_VENDOR); |
| 399 | String levelStr = get(cn, PARAM_CPU_CACHE_LEVEL); |
| 400 | String typeStr = get(cn, PARAM_CPU_CACHE_TYPE); |
| 401 | String policyStr = get(cn, PARAM_CPU_CACHE_POLICY); |
| 402 | long capacity = cacheObjNode.path(PARAM_CAPACITY).asLong(); |
| 403 | int sets = cacheObjNode.path(PARAM_CPU_CACHE_SETS).asInt(); |
| 404 | int ways = cacheObjNode.path(PARAM_CPU_CACHE_WAYS).asInt(); |
| 405 | int lineLen = cacheObjNode.path(PARAM_CPU_CACHE_LINE_LEN).asInt(); |
| 406 | boolean shared = cacheObjNode.path(PARAM_CPU_CACHE_SHARED).asInt() > 0; |
| 407 | |
| 408 | // Construct a basic CPU cache device and add it to the hierarchy |
| 409 | cacheBuilder.addBasicCpuCacheDevice( |
| 410 | DefaultBasicCpuCacheDevice.builder() |
| 411 | .setVendor(cpuVendorStr) |
| 412 | .setCacheId(levelStr, typeStr) |
| 413 | .setPolicy(policyStr) |
| 414 | .setCapacity(capacity) |
| 415 | .setNumberOfSets(sets) |
| 416 | .setNumberOfWays(ways) |
| 417 | .setLineLength(lineLen) |
| 418 | .isShared(shared) |
| 419 | .build()); |
| 420 | } |
| 421 | |
| 422 | return cacheBuilder.build(); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Parse the input JSON object, looking for memory-related |
| 427 | * information. Upon success, construct and return a memory |
| 428 | * hierarchy device. |
| 429 | * |
| 430 | * @param objNode input JSON node with memory device information |
| 431 | * @return a memory hierarchy device |
| 432 | */ |
| 433 | private MemoryHierarchyDevice parseMemoryHierarchyDevice(ObjectNode objNode) { |
| 434 | JsonNode memHierarchyNode = objNode.path(PARAM_MEMORY_HIERARCHY); |
| 435 | ObjectNode memoryHierarchyObjNode = (ObjectNode) memHierarchyNode; |
| 436 | if (memoryHierarchyObjNode == null) { |
| 437 | return null; |
| 438 | } |
| 439 | |
| 440 | JsonNode memoryNode = memoryHierarchyObjNode.path(PARAM_MEMORY_MODULES); |
| 441 | |
| 442 | DefaultMemoryHierarchyDevice.Builder memoryBuilder = |
| 443 | DefaultMemoryHierarchyDevice.builder(); |
| 444 | |
| 445 | // Construct memory modules |
| 446 | for (JsonNode mn : memoryNode) { |
| 447 | ObjectNode memoryObjNode = (ObjectNode) mn; |
| 448 | |
| 449 | String typeStr = get(mn, PARAM_TYPE); |
| 450 | String manufacturerStr = get(mn, PARAM_MANUFACTURER); |
| 451 | String serialStr = get(mn, PARAM_SERIAL); |
| 452 | int dataWidth = memoryObjNode.path(PARAM_MEMORY_WIDTH_DATA).asInt(); |
| 453 | int totalWidth = memoryObjNode.path(PARAM_MEMORY_WIDTH_TOTAL).asInt(); |
| 454 | long capacity = memoryObjNode.path(PARAM_CAPACITY).asLong(); |
| 455 | long speed = memoryObjNode.path(PARAM_SPEED).asLong(); |
| 456 | long configuredSpeed = memoryObjNode.path(PARAM_SPEED_CONF).asLong(); |
| 457 | |
| 458 | // Construct a memory module and add it to the hierarchy |
| 459 | memoryBuilder.addMemoryModule( |
| 460 | DefaultMemoryModuleDevice.builder() |
| 461 | .setType(typeStr) |
| 462 | .setManufacturer(manufacturerStr) |
| 463 | .setSerialNumber(serialStr) |
| 464 | .setDataWidth(dataWidth) |
| 465 | .setTotalWidth(totalWidth) |
| 466 | .setCapacity(capacity) |
| 467 | .setSpeed(speed) |
| 468 | .setConfiguredSpeed(configuredSpeed) |
| 469 | .build()); |
| 470 | } |
| 471 | |
| 472 | return memoryBuilder.build(); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Parse the input JSON object, looking for NIC-related |
| 477 | * information. Upon success, construct and return a list |
| 478 | * of NIC devices. |
| 479 | * |
| 480 | * @param mapper input JSON object mapper |
| 481 | * @param objNode input JSON node with NIC device information |
| 482 | * @param annotations device annotations |
| 483 | * @return list of CPU devices |
| 484 | */ |
| 485 | private Collection<NicDevice> parseNicDevices( |
| 486 | ObjectMapper mapper, ObjectNode objNode, DefaultAnnotations.Builder annotations) { |
| 487 | Collection<NicDevice> nicSet = Sets.newHashSet(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 488 | JsonNode nicNode = objNode.path(PARAM_NICS); |
| 489 | |
| 490 | // Construct NIC objects |
| 491 | for (JsonNode nn : nicNode) { |
| 492 | ObjectNode nicObjNode = (ObjectNode) nn; |
| 493 | |
| 494 | // All the NIC attributes |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 495 | String nicName = get(nn, PARAM_NAME); |
| 496 | long nicIndex = nicObjNode.path(PARAM_ID).asLong(); |
| 497 | long speed = nicObjNode.path(PARAM_SPEED).asLong(); |
| 498 | String portTypeStr = get(nn, PARAM_NIC_PORT_TYPE); |
| 499 | boolean status = nicObjNode.path(PARAM_STATUS).asInt() > 0; |
| 500 | String hwAddr = get(nn, PARAM_NIC_HW_ADDR); |
| 501 | JsonNode tagNode = nicObjNode.path(PARAM_NIC_RX_FILTER); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 502 | if (tagNode == null) { |
Ray Milkey | 067c44b | 2018-02-26 12:48:23 -0800 | [diff] [blame] | 503 | throw new IllegalArgumentException( |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 504 | "The Rx filters of NIC " + nicName + " are not reported"); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // Convert the JSON list into an array of strings |
| 508 | List<String> rxFilters = null; |
| 509 | try { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 510 | rxFilters = mapper.readValue(tagNode.traverse(), |
| 511 | new TypeReference<ArrayList<String>>() { }); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 512 | } catch (IOException ioEx) { |
| 513 | continue; |
| 514 | } |
| 515 | |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 516 | // Store NIC name to number mapping as an annotation |
| 517 | annotations.set(nicName, Long.toString(nicIndex)); |
| 518 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 519 | // Construct a NIC device and add it to the set |
| 520 | nicSet.add( |
| 521 | DefaultNicDevice.builder() |
| 522 | .setName(nicName) |
| 523 | .setPortNumber(nicIndex) |
| 524 | .setPortNumber(nicIndex) |
| 525 | .setPortType(portTypeStr) |
| 526 | .setSpeed(speed) |
| 527 | .setStatus(status) |
| 528 | .setMacAddress(hwAddr) |
| 529 | .setRxFilters(rxFilters) |
| 530 | .build()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 531 | } |
| 532 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 533 | return nicSet; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public List<PortDescription> discoverPortDetails() { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 538 | // Retrieve the device ID |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 539 | DeviceId deviceId = getDeviceId(); |
| 540 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 541 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 542 | // .. and object |
| 543 | RestServerSBDevice device = null; |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 544 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 545 | device = (RestServerSBDevice) getDevice(deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 546 | } catch (ClassCastException ccEx) { |
| 547 | log.error("Failed to discover ports for device {}", deviceId); |
| 548 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 549 | } |
| 550 | |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 551 | if (device == null) { |
| 552 | log.error("No device with ID {} is available for port discovery", deviceId); |
| 553 | return Collections.EMPTY_LIST; |
| 554 | } |
| 555 | if ((device.nics() == null) || (device.nics().size() == 0)) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 556 | log.error("No ports available on {}", deviceId); |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 557 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 558 | } |
| 559 | |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 560 | // List of port descriptions to return |
| 561 | List<PortDescription> portDescriptions = Lists.newArrayList(); |
| 562 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 563 | // Sorted list of NIC ports |
| 564 | Set<NicDevice> nics = new TreeSet(device.nics()); |
| 565 | |
| 566 | // Iterate through the NICs of this device to populate the list |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 567 | for (NicDevice nic : nics) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 568 | // Include the name of this device as an annotation |
| 569 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 570 | .set(AnnotationKeys.PORT_NAME, nic.name()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 571 | |
| 572 | // Create a port description and add it to the list |
| 573 | portDescriptions.add( |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 574 | DefaultPortDescription.builder() |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 575 | // CHECK: .withPortNumber(PortNumber.portNumber(nic.portNumber(), nic.name())) |
| 576 | .withPortNumber(PortNumber.portNumber(nic.portNumber())) |
Yuta HIGUCHI | 53e4796 | 2018-03-01 23:50:48 -0800 | [diff] [blame] | 577 | .isEnabled(nic.status()) |
| 578 | .type(nic.portType()) |
| 579 | .portSpeed(nic.speed()) |
| 580 | .annotations(annotations.build()) |
| 581 | .build()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 582 | |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 583 | log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 584 | deviceId, nic.portNumber(), nic.status() ? "up" : "down", |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 585 | nic.speed()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | return ImmutableList.copyOf(portDescriptions); |
| 589 | } |
| 590 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 591 | /** |
| 592 | * Implements PortStatisticsDiscovery behaviour. |
| 593 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 594 | @Override |
| 595 | public Collection<PortStatistics> discoverPortStatistics() { |
| 596 | // Retrieve the device ID |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 597 | DeviceId deviceId = getDeviceId(); |
| 598 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 599 | |
| 600 | // Get port statistics for this device |
| 601 | return getPortStatistics(deviceId); |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * Query a server to retrieve its port statistics. |
| 606 | * |
| 607 | * @param deviceId the device ID to be queried |
| 608 | * @return list of (per port) PortStatistics |
| 609 | */ |
| 610 | private Collection<PortStatistics> getPortStatistics(DeviceId deviceId) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 611 | // Get global monitoring statistics |
| 612 | MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId); |
| 613 | if (monStats == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 614 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | // Filter out the NIC statistics |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 618 | Collection<PortStatistics> portStats = monStats.nicStatisticsAll(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 619 | if (portStats == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 620 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | log.debug("Port statistics: {}", portStats.toString()); |
| 624 | |
| 625 | return portStats; |
| 626 | } |
| 627 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 628 | /** |
| 629 | * Implements CpuStatisticsDiscovery behaviour. |
| 630 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 631 | @Override |
| 632 | public Collection<CpuStatistics> discoverCpuStatistics() { |
| 633 | // Retrieve the device ID |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 634 | DeviceId deviceId = getDeviceId(); |
| 635 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 636 | |
| 637 | // Get CPU statistics for this device |
| 638 | return getCpuStatistics(deviceId); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Query a server to retrieve its CPU statistics. |
| 643 | * |
| 644 | * @param deviceId the device ID to be queried |
| 645 | * @return list of (per core) CpuStatistics |
| 646 | */ |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 647 | public Collection<CpuStatistics> getCpuStatistics(DeviceId deviceId) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 648 | // Get global monitoring statistics |
| 649 | MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId); |
| 650 | if (monStats == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 651 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | // Filter out the CPU statistics |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 655 | Collection<CpuStatistics> cpuStats = monStats.cpuStatisticsAll(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 656 | if (cpuStats == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 657 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | log.debug("CPU statistics: {}", cpuStats.toString()); |
| 661 | |
| 662 | return cpuStats; |
| 663 | } |
| 664 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 665 | /** |
| 666 | * Implements MonitoringStatisticsDiscovery behaviour. |
| 667 | */ |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 668 | @Override |
| 669 | public MonitoringStatistics discoverGlobalMonitoringStatistics() { |
| 670 | // Retrieve the device ID |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 671 | DeviceId deviceId = getDeviceId(); |
| 672 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 673 | |
| 674 | // Get global monitoring statistics for this device |
| 675 | return getGlobalMonitoringStatistics(deviceId); |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Query a server to retrieve its global monitoring statistics. |
| 680 | * |
| 681 | * @param deviceId the device ID to be queried |
| 682 | * @return global monitoring statistics |
| 683 | */ |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 684 | public MonitoringStatistics getGlobalMonitoringStatistics(DeviceId deviceId) { |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 685 | // Monitoring statistics to return |
| 686 | MonitoringStatistics monStats = null; |
| 687 | |
| 688 | RestServerSBDevice device = null; |
| 689 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 690 | device = (RestServerSBDevice) getDevice(deviceId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 691 | } catch (ClassCastException ccEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 692 | log.error("Failed to retrieve global monitoring statistics from device {}", |
| 693 | deviceId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 694 | return monStats; |
| 695 | } |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 696 | if ((device == null) || (!device.isActive())) { |
| 697 | return monStats; |
| 698 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 699 | |
| 700 | // Hit the path that provides the server's global resources |
| 701 | InputStream response = null; |
| 702 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 703 | response = getController().get(deviceId, URL_SRV_GLOBAL_STATS, JSON); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 704 | } catch (ProcessingException pEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 705 | log.error("Failed to retrieve global monitoring statistics from device {}", |
| 706 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 707 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 708 | return monStats; |
| 709 | } |
| 710 | |
| 711 | // Load the JSON into objects |
| 712 | ObjectMapper mapper = new ObjectMapper(); |
| 713 | Map<String, Object> jsonMap = null; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 714 | ObjectNode objNode = null; |
| 715 | try { |
| 716 | jsonMap = mapper.readValue(response, Map.class); |
Georgios Katsikas | 2ebd8a0 | 2018-06-27 18:32:50 +0200 | [diff] [blame] | 717 | JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 718 | objNode = (ObjectNode) jsonNode; |
| 719 | } catch (IOException ioEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 720 | log.error("Failed to retrieve global monitoring statistics from device {}", |
| 721 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 722 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 723 | return monStats; |
| 724 | } |
| 725 | |
| 726 | if (jsonMap == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 727 | log.error("Failed to retrieve global monitoring statistics from device {}", |
| 728 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 729 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 730 | return monStats; |
| 731 | } |
| 732 | |
| 733 | // Get high-level CPU statistics |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 734 | int busyCpus = objNode.path(PARAM_MON_BUSY_CPUS).asInt(); |
| 735 | int freeCpus = objNode.path(PARAM_MON_FREE_CPUS).asInt(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 736 | |
| 737 | // Get a list of CPU statistics per core |
| 738 | Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode); |
| 739 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 740 | // Get main memory statistics |
| 741 | MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode); |
| 742 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 743 | // Get a list of port statistics |
| 744 | Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode); |
| 745 | |
| 746 | // Get zero timing statistics |
| 747 | TimingStatistics timinsgStats = getZeroTimingStatistics(); |
| 748 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 749 | // Construct a global monitoring statistics object out of smaller ones |
| 750 | monStats = DefaultMonitoringStatistics.builder() |
| 751 | .setDeviceId(deviceId) |
| 752 | .setTimingStatistics(timinsgStats) |
| 753 | .setCpuStatistics(cpuStats) |
| 754 | .setMemoryStatistics(memStats) |
| 755 | .setNicStatistics(nicStats) |
| 756 | .build(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 757 | |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 758 | // When a device reports monitoring data, it means it is alive |
| 759 | raiseDeviceReconnect(device); |
| 760 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 761 | log.debug("Global monitoring statistics: {}", monStats.toString()); |
| 762 | |
| 763 | return monStats; |
| 764 | } |
| 765 | |
| 766 | @Override |
| 767 | public MonitoringStatistics discoverMonitoringStatistics(URI tcId) { |
| 768 | // Retrieve the device ID |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 769 | DeviceId deviceId = getDeviceId(); |
| 770 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 771 | |
| 772 | // Get resource-specific monitoring statistics for this device |
| 773 | return getMonitoringStatistics(deviceId, tcId); |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Query a server to retrieve monitoring statistics for a |
| 778 | * specific resource (i.e., traffic class). |
| 779 | * |
| 780 | * @param deviceId the device ID to be queried |
| 781 | * @param tcId the ID of the traffic class to be monitored |
| 782 | * @return resource-specific monitoring statistics |
| 783 | */ |
| 784 | private MonitoringStatistics getMonitoringStatistics(DeviceId deviceId, URI tcId) { |
| 785 | // Monitoring statistics to return |
| 786 | MonitoringStatistics monStats = null; |
| 787 | |
| 788 | RestServerSBDevice device = null; |
| 789 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 790 | device = (RestServerSBDevice) getDevice(deviceId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 791 | } catch (ClassCastException ccEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 792 | log.error("Failed to retrieve monitoring statistics from device {}", |
| 793 | deviceId); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 794 | return monStats; |
| 795 | } |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 796 | if (device == null) { |
| 797 | return monStats; |
| 798 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 799 | |
| 800 | // Create a resource-specific URL |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 801 | String scUrl = URL_SERVICE_CHAINS_STATS + SLASH + tcId.toString(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 802 | |
| 803 | // Hit the path that provides the server's specific resources |
| 804 | InputStream response = null; |
| 805 | try { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 806 | response = getController().get(deviceId, scUrl, JSON); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 807 | } catch (ProcessingException pEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 808 | log.error("Failed to retrieve monitoring statistics from device {}", |
| 809 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 810 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 811 | return monStats; |
| 812 | } |
| 813 | |
| 814 | // Load the JSON into objects |
| 815 | ObjectMapper mapper = new ObjectMapper(); |
| 816 | Map<String, Object> jsonMap = null; |
| 817 | JsonNode jsonNode = null; |
| 818 | ObjectNode objNode = null; |
| 819 | try { |
| 820 | jsonMap = mapper.readValue(response, Map.class); |
| 821 | jsonNode = mapper.convertValue(jsonMap, JsonNode.class); |
| 822 | objNode = (ObjectNode) jsonNode; |
| 823 | } catch (IOException ioEx) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 824 | log.error("Failed to retrieve monitoring statistics from device {}", |
| 825 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 826 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 827 | return monStats; |
| 828 | } |
| 829 | |
| 830 | if (jsonMap == null) { |
Georgios Katsikas | d472a32 | 2018-07-08 19:58:25 +0200 | [diff] [blame] | 831 | log.error("Failed to retrieve monitoring statistics from device {}", |
| 832 | deviceId); |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 833 | raiseDeviceDisconnect(device); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 834 | return monStats; |
| 835 | } |
| 836 | |
| 837 | // Get the ID of the traffic class |
| 838 | String id = get(jsonNode, PARAM_ID); |
| 839 | |
| 840 | // And verify that this is the traffic class we want to monitor |
| 841 | if (!id.equals(tcId.toString())) { |
Ray Milkey | 067c44b | 2018-02-26 12:48:23 -0800 | [diff] [blame] | 842 | throw new IllegalStateException( |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 843 | "Failed to retrieve monitoring data for traffic class " + tcId + |
| 844 | ". Traffic class ID does not agree." |
| 845 | ); |
| 846 | } |
| 847 | |
| 848 | // Get a list of CPU statistics per core |
| 849 | Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode); |
| 850 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 851 | // Get main memory statistics |
| 852 | MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode); |
| 853 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 854 | // Get a list of port statistics |
| 855 | Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode); |
| 856 | |
| 857 | // Get timing statistics |
| 858 | TimingStatistics timinsgStats = parseTimingStatistics(objNode); |
| 859 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 860 | // Construct a global monitoring statistics object out of smaller ones |
| 861 | monStats = DefaultMonitoringStatistics.builder() |
| 862 | .setDeviceId(deviceId) |
| 863 | .setTimingStatistics(timinsgStats) |
| 864 | .setCpuStatistics(cpuStats) |
| 865 | .setMemoryStatistics(memStats) |
| 866 | .setNicStatistics(nicStats) |
| 867 | .build(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 868 | |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 869 | // When a device reports monitoring data, it means it is alive |
| 870 | raiseDeviceReconnect(device); |
| 871 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 872 | log.debug("Monitoring statistics: {}", monStats.toString()); |
| 873 | |
| 874 | return monStats; |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * Parse the input JSON object, looking for CPU-related |
| 879 | * statistics. Upon success, construct and return a list |
| 880 | * of CPU statistics objects. |
| 881 | * |
| 882 | * @param deviceId the device ID that sent the JSON object |
| 883 | * @param objNode input JSON node with CPU statistics information |
| 884 | * @return list of (per core) CpuStatistics |
| 885 | */ |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 886 | private Collection<CpuStatistics> parseCpuStatistics(DeviceId deviceId, JsonNode objNode) { |
| 887 | if ((deviceId == null) || (objNode == null)) { |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 888 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 889 | } |
| 890 | |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 891 | Collection<CpuStatistics> cpuStats = Lists.newArrayList(); |
| 892 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 893 | JsonNode cpuNode = objNode.path(PARAM_CPUS); |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 894 | if (cpuNode.isMissingNode()) { |
| 895 | return cpuStats; |
| 896 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 897 | |
| 898 | for (JsonNode cn : cpuNode) { |
| 899 | ObjectNode cpuObjNode = (ObjectNode) cn; |
| 900 | |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 901 | // CPU statistics builder |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 902 | DefaultCpuStatistics.Builder cpuStatsBuilder = DefaultCpuStatistics.builder(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 903 | |
| 904 | // Throughput statistics are optional |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 905 | JsonNode throughputNode = cpuObjNode.get(PARAM_CPU_THROUGHPUT); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 906 | if (throughputNode != null) { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 907 | String throughputUnit = get(throughputNode, PARAM_MON_UNIT); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 908 | if (!Strings.isNullOrEmpty(throughputUnit)) { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 909 | cpuStatsBuilder.setThroughputUnit(throughputUnit); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 910 | } |
| 911 | float averageThroughput = (float) 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 912 | if (throughputNode.get(PARAM_MON_AVERAGE) != null) { |
| 913 | averageThroughput = throughputNode.path(PARAM_MON_AVERAGE).floatValue(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 914 | } |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 915 | cpuStatsBuilder.setAverageThroughput(averageThroughput); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | // Latency statistics are optional |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 919 | JsonNode latencyNode = cpuObjNode.get(PARAM_CPU_LATENCY); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 920 | if (latencyNode != null) { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 921 | String latencyUnit = get(latencyNode, PARAM_MON_UNIT); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 922 | if (!Strings.isNullOrEmpty(latencyUnit)) { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 923 | cpuStatsBuilder.setLatencyUnit(latencyUnit); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 924 | } |
| 925 | float minLatency = (float) 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 926 | if (latencyNode.get(PARAM_MON_MIN) != null) { |
| 927 | minLatency = latencyNode.path(PARAM_MON_MIN).floatValue(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 928 | } |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 929 | float averageLatency = (float) 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 930 | if (latencyNode.get(PARAM_MON_AVERAGE) != null) { |
| 931 | averageLatency = latencyNode.path(PARAM_MON_AVERAGE).floatValue(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 932 | } |
| 933 | float maxLatency = (float) 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 934 | if (latencyNode.get(PARAM_MON_MAX) != null) { |
| 935 | maxLatency = latencyNode.path(PARAM_MON_MAX).floatValue(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 936 | } |
| 937 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 938 | cpuStatsBuilder.setMinLatency(minLatency) |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 939 | .setAverageLatency(averageLatency) |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 940 | .setMaxLatency(maxLatency); |
| 941 | } |
| 942 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 943 | // CPU ID with its load and status |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 944 | int cpuId = cpuObjNode.path(PARAM_ID).asInt(); |
| 945 | float cpuLoad = cpuObjNode.path(PARAM_CPU_LOAD).floatValue(); |
| 946 | int queueId = cpuObjNode.path(PARAM_CPU_QUEUE).asInt(); |
| 947 | int busySince = cpuObjNode.path(PARAM_CPU_STATUS).asInt(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 948 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 949 | // We have all the statistics for this CPU core |
| 950 | cpuStats.add( |
| 951 | cpuStatsBuilder |
| 952 | .setDeviceId(deviceId) |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 953 | .setId(cpuId) |
| 954 | .setLoad(cpuLoad) |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 955 | .setQueue(queueId) |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 956 | .setBusySince(busySince) |
| 957 | .build()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | return cpuStats; |
| 961 | } |
| 962 | |
| 963 | /** |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 964 | * Parse the input JSON object, looking for memory-related |
| 965 | * statistics. Upon success, construct and return a memory |
| 966 | * statistics objects. |
| 967 | * |
| 968 | * @param deviceId the device ID that sent the JSON object |
| 969 | * @param objNode input JSON node with memory statistics information |
| 970 | * @return memory statistics object |
| 971 | */ |
| 972 | private MemoryStatistics parseMemoryStatistics(DeviceId deviceId, JsonNode objNode) { |
| 973 | if ((deviceId == null) || (objNode == null)) { |
| 974 | return null; |
| 975 | } |
| 976 | |
| 977 | JsonNode memoryNode = objNode.path(PARAM_MEMORY); |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 978 | if (memoryNode.isMissingNode()) { |
| 979 | return getZeroMemoryStatistics(deviceId); |
| 980 | } |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 981 | ObjectNode memoryObjNode = (ObjectNode) memoryNode; |
| 982 | |
| 983 | // Fetch memory statistics |
| 984 | String unit = get(memoryNode, PARAM_MON_UNIT); |
| 985 | long used = memoryObjNode.path(PARAM_MEMORY_STATS_USED).asLong(); |
| 986 | long free = memoryObjNode.path(PARAM_MEMORY_STATS_FREE).asLong(); |
| 987 | long total = memoryObjNode.path(PARAM_MEMORY_STATS_TOTAL).asLong(); |
| 988 | |
| 989 | // Memory statistics builder |
| 990 | return DefaultMemoryStatistics.builder() |
| 991 | .setDeviceId(deviceId) |
| 992 | .setMemoryUsed(used) |
| 993 | .setMemoryFree(free) |
| 994 | .setMemoryTotal(total) |
| 995 | .build(); |
| 996 | } |
| 997 | |
| 998 | /** |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 999 | * Parse the input JSON object, looking for NIC-related |
| 1000 | * statistics. Upon success, construct and return a list |
| 1001 | * of NIC statistics objects. |
| 1002 | * |
| 1003 | * @param deviceId the device ID that sent the JSON object |
| 1004 | * @param objNode input JSON node with NIC statistics information |
| 1005 | * @return list of (per port) PortStatistics |
| 1006 | */ |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 1007 | private Collection<PortStatistics> parseNicStatistics(DeviceId deviceId, JsonNode objNode) { |
| 1008 | if ((deviceId == null) || (objNode == null)) { |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 1009 | return Collections.EMPTY_LIST; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 1012 | RestServerSBDevice device = null; |
| 1013 | try { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1014 | device = (RestServerSBDevice) getDevice(deviceId); |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 1015 | } catch (ClassCastException ccEx) { |
| 1016 | return Collections.EMPTY_LIST; |
| 1017 | } |
Georgios Katsikas | 30bede5 | 2018-07-28 14:46:07 +0200 | [diff] [blame] | 1018 | if (device == null) { |
| 1019 | return Collections.EMPTY_LIST; |
| 1020 | } |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 1021 | |
| 1022 | Collection<PortStatistics> nicStats = Lists.newArrayList(); |
| 1023 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1024 | JsonNode nicNode = objNode.path(PARAM_NICS); |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 1025 | if (nicNode.isMissingNode()) { |
| 1026 | return nicStats; |
| 1027 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1028 | |
| 1029 | for (JsonNode nn : nicNode) { |
| 1030 | ObjectNode nicObjNode = (ObjectNode) nn; |
| 1031 | |
| 1032 | // All the NIC attributes |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1033 | String nicName = get(nn, PARAM_NAME); |
| 1034 | checkArgument(!Strings.isNullOrEmpty(nicName), MSG_NIC_NAME_NULL); |
Georgios Katsikas | 80e0b9f | 2018-07-21 20:29:18 +0200 | [diff] [blame] | 1035 | |
| 1036 | long portNumber = device.portNumberFromName(nicName); |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1037 | checkArgument(portNumber >= 0, MSG_NIC_PORT_NUMBER_NEGATIVE); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1038 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1039 | long rxCount = nicObjNode.path(PARAM_NIC_STATS_RX_COUNT).asLong(); |
| 1040 | long rxBytes = nicObjNode.path(PARAM_NIC_STATS_RX_BYTES).asLong(); |
| 1041 | long rxDropped = nicObjNode.path(PARAM_NIC_STATS_RX_DROPS).asLong(); |
| 1042 | long rxErrors = nicObjNode.path(PARAM_NIC_STATS_RX_ERRORS).asLong(); |
| 1043 | long txCount = nicObjNode.path(PARAM_NIC_STATS_TX_COUNT).asLong(); |
| 1044 | long txBytes = nicObjNode.path(PARAM_NIC_STATS_TX_BYTES).asLong(); |
| 1045 | long txDropped = nicObjNode.path(PARAM_NIC_STATS_TX_DROPS).asLong(); |
| 1046 | long txErrors = nicObjNode.path(PARAM_NIC_STATS_TX_ERRORS).asLong(); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1047 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1048 | // Construct a NIC statistics object and add it to the set |
| 1049 | nicStats.add( |
| 1050 | DefaultPortStatistics.builder() |
| 1051 | .setDeviceId(deviceId) |
Ray Milkey | 5ec4208 | 2019-02-13 09:56:07 -0800 | [diff] [blame] | 1052 | .setPort(PortNumber.portNumber(portNumber)) |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1053 | .setPacketsReceived(rxCount) |
| 1054 | .setPacketsSent(txCount) |
| 1055 | .setBytesReceived(rxBytes) |
| 1056 | .setBytesSent(txBytes) |
| 1057 | .setPacketsRxDropped(rxDropped) |
| 1058 | .setPacketsRxErrors(rxErrors) |
| 1059 | .setPacketsTxDropped(txDropped) |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1060 | .setPacketsTxErrors(txErrors) |
| 1061 | .build()); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | return nicStats; |
| 1065 | } |
| 1066 | |
| 1067 | /** |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1068 | * Parse the input JSON object, looking for timing-related statistics. |
| 1069 | * Upon success, return a timing statistics object with the advertized values. |
| 1070 | * Upon failure, return a timing statistics object with zero-initialized values. |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1071 | * |
| 1072 | * @param objNode input JSON node with timing statistics information |
| 1073 | * @return TimingStatistics object or null |
| 1074 | */ |
| 1075 | private TimingStatistics parseTimingStatistics(JsonNode objNode) { |
| 1076 | TimingStatistics timinsgStats = null; |
| 1077 | |
| 1078 | if (objNode == null) { |
| 1079 | return timinsgStats; |
| 1080 | } |
| 1081 | |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 1082 | // Get timing statistics |
| 1083 | JsonNode timingNode = objNode.path(PARAM_TIMING_STATS); |
| 1084 | if (timingNode.isMissingNode()) { |
| 1085 | // If no timing statistics are present, then send zeros |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1086 | return getZeroTimingStatistics(); |
| 1087 | } |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 1088 | ObjectNode timingObjNode = (ObjectNode) timingNode; |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1089 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1090 | DefaultTimingStatistics.Builder timingBuilder = |
| 1091 | DefaultTimingStatistics.builder(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1092 | |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1093 | // The unit of timing statistics |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1094 | String timingStatsUnit = get(timingNode, PARAM_MON_UNIT); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1095 | if (!Strings.isNullOrEmpty(timingStatsUnit)) { |
| 1096 | timingBuilder.setUnit(timingStatsUnit); |
| 1097 | } |
| 1098 | |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1099 | // Time (ns) to parse the controller's deployment instruction |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1100 | long parsingTime = 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1101 | if (timingObjNode.get(PARAM_TIMING_PARSE) != null) { |
| 1102 | parsingTime = timingObjNode.path(PARAM_TIMING_PARSE).asLong(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1103 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1104 | // Time (ns) to do the deployment |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1105 | long launchingTime = 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1106 | if (timingObjNode.get(PARAM_TIMING_LAUNCH) != null) { |
| 1107 | launchingTime = timingObjNode.path(PARAM_TIMING_LAUNCH).asLong(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1108 | } |
| 1109 | // Deployment time (ns) equals to time to parse + time to launch |
| 1110 | long deployTime = 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1111 | if (timingObjNode.get(PARAM_TIMING_DEPLOY) != null) { |
| 1112 | deployTime = timingObjNode.path(PARAM_TIMING_DEPLOY).asLong(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1113 | } |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1114 | checkArgument(deployTime == parsingTime + launchingTime, |
| 1115 | MSG_STATS_TIMING_DEPLOY_INCONSISTENT); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1116 | |
| 1117 | timingBuilder.setParsingTime(parsingTime) |
| 1118 | .setLaunchingTime(launchingTime); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1119 | |
| 1120 | // Get autoscale timing statistics |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1121 | JsonNode autoscaleTimingNode = objNode.path(PARAM_TIMING_STATS_AUTOSCALE); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1122 | if (autoscaleTimingNode == null) { |
| 1123 | return timingBuilder.build(); |
| 1124 | } |
| 1125 | |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 1126 | ObjectNode autoScaleTimingObjNode = (ObjectNode) autoscaleTimingNode; |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1127 | // Time (ns) to autoscale a server's load |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 1128 | long autoScaleTime = 0; |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1129 | if (autoScaleTimingObjNode.get(PARAM_TIMING_AUTOSCALE) != null) { |
| 1130 | autoScaleTime = autoScaleTimingObjNode.path(PARAM_TIMING_AUTOSCALE).asLong(); |
Georgios Katsikas | fda6674 | 2018-07-31 20:18:14 +0200 | [diff] [blame] | 1131 | } |
Georgios Katsikas | 973a265 | 2018-06-28 08:45:47 +0200 | [diff] [blame] | 1132 | timingBuilder.setAutoScaleTime(autoScaleTime); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1133 | |
| 1134 | return timingBuilder.build(); |
| 1135 | } |
| 1136 | |
| 1137 | /** |
Georgios Katsikas | 1a64c3a | 2020-06-03 17:30:43 +0200 | [diff] [blame^] | 1138 | * Return a memory statistics object with zero counters. |
| 1139 | * This is useful when constructing MonitoringStatistics |
| 1140 | * objects that do not require memory statistics. |
| 1141 | * |
| 1142 | * @param deviceId a device ID |
| 1143 | * @return MemoryStatistics object |
| 1144 | */ |
| 1145 | private MemoryStatistics getZeroMemoryStatistics(DeviceId deviceId) { |
| 1146 | return DefaultMemoryStatistics.builder() |
| 1147 | .setDeviceId(deviceId) |
| 1148 | .setMemoryUsed(0) |
| 1149 | .setMemoryFree(0) |
| 1150 | .setMemoryTotal(0) |
| 1151 | .build(); |
| 1152 | } |
| 1153 | |
| 1154 | /** |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1155 | * Return a timing statistics object with zero counters. |
| 1156 | * This is useful when constructing MonitoringStatistics |
| 1157 | * objects that do not require timers. |
| 1158 | * |
| 1159 | * @return TimingStatistics object |
| 1160 | */ |
| 1161 | private TimingStatistics getZeroTimingStatistics() { |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1162 | return DefaultTimingStatistics.builder() |
| 1163 | .setParsingTime(0) |
| 1164 | .setLaunchingTime(0) |
| 1165 | .setAutoScaleTime(0) |
| 1166 | .build(); |
| 1167 | } |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1168 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1169 | /** |
| 1170 | * Implements DeviceSystemStatisticsQuery behaviour. |
| 1171 | */ |
| 1172 | @Override |
| 1173 | public Optional<DeviceSystemStats> getDeviceSystemStats() { |
| 1174 | // Retrieve the device ID from the handler |
| 1175 | DeviceId deviceId = getDeviceId(); |
| 1176 | checkNotNull(deviceId, MSG_DEVICE_ID_NULL); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1177 | |
Georgios Katsikas | 13ccba6 | 2020-03-18 12:05:03 +0100 | [diff] [blame] | 1178 | // ....to retrieve monitoring statistics |
| 1179 | MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId); |
| 1180 | |
| 1181 | Optional<DeviceCpuStats> cpuStats = getOverallCpuUsage(monStats); |
| 1182 | Optional<DeviceMemoryStats> memoryStats = getOverallMemoryUsage(monStats); |
| 1183 | |
| 1184 | if (cpuStats.isPresent() && memoryStats.isPresent()) { |
| 1185 | return Optional.of(new DeviceSystemStats(memoryStats.get(), cpuStats.get())); |
| 1186 | } else { |
| 1187 | return Optional.empty(); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * Get CPU usage of server device. |
| 1193 | * |
| 1194 | * @param monStats global monitoring statistics which contain CPU statistics |
| 1195 | * @return cpuStats, device CPU usage stats if available |
| 1196 | */ |
| 1197 | private Optional<DeviceCpuStats> getOverallCpuUsage(MonitoringStatistics monStats) { |
| 1198 | if (monStats == null) { |
| 1199 | return Optional.empty(); |
| 1200 | } |
| 1201 | |
| 1202 | if (monStats.numberOfCpus() == 0) { |
| 1203 | return Optional.of(new DeviceCpuStats()); |
| 1204 | } |
| 1205 | |
| 1206 | float usedCpu = 0.0f; |
| 1207 | for (CpuStatistics cpuCoreStats : monStats.cpuStatisticsAll()) { |
| 1208 | if (cpuCoreStats.busy()) { |
| 1209 | usedCpu += cpuCoreStats.load(); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | return Optional.of(new DeviceCpuStats(usedCpu / (float) monStats.numberOfCpus())); |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Get memory usage of server device in KB. |
| 1218 | * |
| 1219 | * @param monStats global monitoring statistics which contain memory statistics |
| 1220 | * @return memoryStats, device memory usage stats if available |
| 1221 | */ |
| 1222 | private Optional<DeviceMemoryStats> getOverallMemoryUsage(MonitoringStatistics monStats) { |
| 1223 | if (monStats == null) { |
| 1224 | return Optional.empty(); |
| 1225 | } |
| 1226 | |
| 1227 | MemoryStatistics memStats = monStats.memoryStatistics(); |
| 1228 | |
| 1229 | return Optional.of( |
| 1230 | new DeviceMemoryStats(memStats.free(), memStats.used(), memStats.total())); |
Georgios Katsikas | 8360098 | 2017-05-28 20:41:45 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | } |