Search in sources :

Example 1 with TimingStatistics

use of org.onosproject.drivers.server.stats.TimingStatistics in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getMonitoringStatistics.

/**
 * Query a server to retrieve monitoring statistics for a
 * specific resource (i.e., traffic class).
 *
 * @param deviceId the device ID to be queried
 * @param tcId the ID of the traffic class to be monitored
 * @return resource-specific monitoring statistics
 */
private MonitoringStatistics getMonitoringStatistics(DeviceId deviceId, URI tcId) {
    // Monitoring statistics to return
    MonitoringStatistics monStats = null;
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        return monStats;
    }
    if (device == null) {
        return monStats;
    }
    // Create a resource-specific URL
    String scUrl = URL_SERVICE_CHAINS_STATS + SLASH + tcId.toString();
    // Hit the path that provides the server's specific resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, scUrl, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    if (jsonMap == null) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Get the ID of the traffic class
    String id = get(jsonNode, PARAM_ID);
    // And verify that this is the traffic class we want to monitor
    if (!id.equals(tcId.toString())) {
        throw new IllegalStateException("Failed to retrieve monitoring data for traffic class " + tcId + ". Traffic class ID does not agree.");
    }
    // Get a list of CPU statistics per core
    Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
    // Get main memory statistics
    MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
    // Get a list of port statistics
    Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
    // Get timing statistics
    TimingStatistics timinsgStats = parseTimingStatistics(objNode);
    // Construct a global monitoring statistics object out of smaller ones
    monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
    // When a device reports monitoring data, it means it is alive
    raiseDeviceReconnect(device);
    log.debug("Monitoring statistics: {}", monStats.toString());
    return monStats;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with TimingStatistics

use of org.onosproject.drivers.server.stats.TimingStatistics in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getGlobalMonitoringStatistics.

/**
 * Query a server to retrieve its global monitoring statistics.
 *
 * @param deviceId the device ID to be queried
 * @return global monitoring statistics
 */
public MonitoringStatistics getGlobalMonitoringStatistics(DeviceId deviceId) {
    // Monitoring statistics to return
    MonitoringStatistics monStats = null;
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        return monStats;
    }
    if ((device == null) || (!device.isActive())) {
        return monStats;
    }
    // Hit the path that provides the server's global resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_GLOBAL_STATS, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    if (jsonMap == null) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Get high-level CPU statistics
    int busyCpus = objNode.path(PARAM_MON_BUSY_CPUS).asInt();
    int freeCpus = objNode.path(PARAM_MON_FREE_CPUS).asInt();
    // Get a list of CPU statistics per core
    Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
    // Get main memory statistics
    MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
    // Get a list of port statistics
    Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
    // Get zero timing statistics
    TimingStatistics timinsgStats = getZeroTimingStatistics();
    // Construct a global monitoring statistics object out of smaller ones
    monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
    // When a device reports monitoring data, it means it is alive
    raiseDeviceReconnect(device);
    log.debug("Global monitoring statistics: {}", monStats.toString());
    return monStats;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 3 with TimingStatistics

use of org.onosproject.drivers.server.stats.TimingStatistics in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method parseTimingStatistics.

/**
 * Parse the input JSON object, looking for timing-related statistics.
 * Upon success, return a timing statistics object with the advertized values.
 * Upon failure, return a timing statistics object with zero-initialized values.
 *
 * @param objNode input JSON node with timing statistics information
 * @return TimingStatistics object or null
 */
private TimingStatistics parseTimingStatistics(JsonNode objNode) {
    TimingStatistics timinsgStats = null;
    if (objNode == null) {
        return timinsgStats;
    }
    // Get timing statistics
    JsonNode timingNode = objNode.path(PARAM_TIMING_STATS);
    if (timingNode.isMissingNode()) {
        // If no timing statistics are present, then send zeros
        return getZeroTimingStatistics();
    }
    ObjectNode timingObjNode = (ObjectNode) timingNode;
    DefaultTimingStatistics.Builder timingBuilder = DefaultTimingStatistics.builder();
    // The unit of timing statistics
    String timingStatsUnit = get(timingNode, PARAM_MON_UNIT);
    if (!Strings.isNullOrEmpty(timingStatsUnit)) {
        timingBuilder.setUnit(timingStatsUnit);
    }
    // Time (ns) to parse the controller's deployment instruction
    long parsingTime = 0;
    if (timingObjNode.get(PARAM_TIMING_PARSE) != null) {
        parsingTime = timingObjNode.path(PARAM_TIMING_PARSE).asLong();
    }
    // Time (ns) to do the deployment
    long launchingTime = 0;
    if (timingObjNode.get(PARAM_TIMING_LAUNCH) != null) {
        launchingTime = timingObjNode.path(PARAM_TIMING_LAUNCH).asLong();
    }
    // Deployment time (ns) equals to time to parse + time to launch
    long deployTime = 0;
    if (timingObjNode.get(PARAM_TIMING_DEPLOY) != null) {
        deployTime = timingObjNode.path(PARAM_TIMING_DEPLOY).asLong();
    }
    checkArgument(deployTime == parsingTime + launchingTime, MSG_STATS_TIMING_DEPLOY_INCONSISTENT);
    timingBuilder.setParsingTime(parsingTime).setLaunchingTime(launchingTime);
    // Get autoscale timing statistics
    JsonNode autoscaleTimingNode = objNode.path(PARAM_TIMING_STATS_AUTOSCALE);
    if (autoscaleTimingNode == null) {
        return timingBuilder.build();
    }
    ObjectNode autoScaleTimingObjNode = (ObjectNode) autoscaleTimingNode;
    // Time (ns) to autoscale a server's load
    long autoScaleTime = 0;
    if (autoScaleTimingObjNode.get(PARAM_TIMING_AUTOSCALE) != null) {
        autoScaleTime = autoScaleTimingObjNode.path(PARAM_TIMING_AUTOSCALE).asLong();
    }
    timingBuilder.setAutoScaleTime(autoScaleTime);
    return timingBuilder.build();
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 DefaultTimingStatistics (org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics)3 TimingStatistics (org.onosproject.drivers.server.stats.TimingStatistics)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 ProcessingException (javax.ws.rs.ProcessingException)2 RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)2 DefaultRestServerSBDevice (org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice)2 DefaultCpuStatistics (org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics)2 DefaultMemoryStatistics (org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics)2 DefaultMonitoringStatistics (org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics)2 CpuStatistics (org.onosproject.drivers.server.stats.CpuStatistics)2 MemoryStatistics (org.onosproject.drivers.server.stats.MemoryStatistics)2 MonitoringStatistics (org.onosproject.drivers.server.stats.MonitoringStatistics)2 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)2 PortStatistics (org.onosproject.net.device.PortStatistics)2