use of org.onosproject.drivers.server.stats.CpuStatistics 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;
}
use of org.onosproject.drivers.server.stats.CpuStatistics in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method parseCpuStatistics.
/**
* Parse the input JSON object, looking for CPU-related
* statistics. Upon success, construct and return a list
* of CPU statistics objects.
*
* @param deviceId the device ID that sent the JSON object
* @param objNode input JSON node with CPU statistics information
* @return list of (per core) CpuStatistics
*/
private Collection<CpuStatistics> parseCpuStatistics(DeviceId deviceId, JsonNode objNode) {
if ((deviceId == null) || (objNode == null)) {
return Collections.EMPTY_LIST;
}
Collection<CpuStatistics> cpuStats = Lists.newArrayList();
JsonNode cpuNode = objNode.path(PARAM_CPUS);
if (cpuNode.isMissingNode()) {
return cpuStats;
}
for (JsonNode cn : cpuNode) {
ObjectNode cpuObjNode = (ObjectNode) cn;
// CPU statistics builder
DefaultCpuStatistics.Builder cpuStatsBuilder = DefaultCpuStatistics.builder();
// Throughput statistics are optional
JsonNode throughputNode = cpuObjNode.get(PARAM_CPU_THROUGHPUT);
if (throughputNode != null) {
String throughputUnit = get(throughputNode, PARAM_MON_UNIT);
if (!Strings.isNullOrEmpty(throughputUnit)) {
cpuStatsBuilder.setThroughputUnit(throughputUnit);
}
float averageThroughput = (float) 0;
if (throughputNode.get(PARAM_MON_AVERAGE) != null) {
averageThroughput = throughputNode.path(PARAM_MON_AVERAGE).floatValue();
}
cpuStatsBuilder.setAverageThroughput(averageThroughput);
}
// Latency statistics are optional
JsonNode latencyNode = cpuObjNode.get(PARAM_CPU_LATENCY);
if (latencyNode != null) {
String latencyUnit = get(latencyNode, PARAM_MON_UNIT);
if (!Strings.isNullOrEmpty(latencyUnit)) {
cpuStatsBuilder.setLatencyUnit(latencyUnit);
}
float minLatency = (float) 0;
if (latencyNode.get(PARAM_MON_MIN) != null) {
minLatency = latencyNode.path(PARAM_MON_MIN).floatValue();
}
float averageLatency = (float) 0;
if (latencyNode.get(PARAM_MON_AVERAGE) != null) {
averageLatency = latencyNode.path(PARAM_MON_AVERAGE).floatValue();
}
float maxLatency = (float) 0;
if (latencyNode.get(PARAM_MON_MAX) != null) {
maxLatency = latencyNode.path(PARAM_MON_MAX).floatValue();
}
cpuStatsBuilder.setMinLatency(minLatency).setAverageLatency(averageLatency).setMaxLatency(maxLatency);
}
// CPU ID with its load and status
int cpuId = cpuObjNode.path(PARAM_ID).asInt();
float cpuLoad = cpuObjNode.path(PARAM_CPU_LOAD).floatValue();
int queueId = cpuObjNode.path(PARAM_CPU_QUEUE).asInt();
int busySince = cpuObjNode.path(PARAM_CPU_STATUS).asInt();
// We have all the statistics for this CPU core
cpuStats.add(cpuStatsBuilder.setDeviceId(deviceId).setId(cpuId).setLoad(cpuLoad).setQueue(queueId).setBusySince(busySince).build());
}
return cpuStats;
}
use of org.onosproject.drivers.server.stats.CpuStatistics 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;
}
use of org.onosproject.drivers.server.stats.CpuStatistics in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method getCpuStatistics.
/**
* Query a server to retrieve its CPU statistics.
*
* @param deviceId the device ID to be queried
* @return list of (per core) CpuStatistics
*/
public Collection<CpuStatistics> getCpuStatistics(DeviceId deviceId) {
// Get global monitoring statistics
MonitoringStatistics monStats = getGlobalMonitoringStatistics(deviceId);
if (monStats == null) {
return Collections.EMPTY_LIST;
}
// Filter out the CPU statistics
Collection<CpuStatistics> cpuStats = monStats.cpuStatisticsAll();
if (cpuStats == null) {
return Collections.EMPTY_LIST;
}
log.debug("CPU statistics: {}", cpuStats.toString());
return cpuStats;
}
Aggregations