use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.
the class ControlMetricsWebResource method controlMessageMetrics.
/**
* Returns control message metrics of a given device.
*
* @param deviceId device identification
* @return control message metrics of a given device
* @onos.rsModel ControlMessageMetric
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("messages/{deviceId}")
public Response controlMessageMetrics(@PathParam("deviceId") String deviceId) {
ObjectNode root = mapper().createObjectNode();
ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
ClusterService clusterService = get(ClusterService.class);
NodeId localNodeId = clusterService.getLocalNode().id();
metricsStats(monitorService, localNodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(deviceId), root);
return ok(root).build();
}
use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.
the class SystemMetricsCollectorWebResource method networkMetrics.
/**
* Collects network metrics.
*
* @param stream JSON stream
* @return 200 OK
* @onos.rsModel NetworkMetricsPost
*/
@POST
@Path("network_metrics")
@Consumes(MediaType.APPLICATION_JSON)
public Response networkMetrics(InputStream stream) {
ObjectNode root = mapper().createObjectNode();
ControlPlaneMonitorService monitorService = get(ControlPlaneMonitorService.class);
MetricsService metricsService = get(MetricsService.class);
ControlMetric cm;
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
ArrayNode networkRes = jsonTree.get("networks") == null ? mapper().createArrayNode() : (ArrayNode) jsonTree.get("networks");
for (JsonNode node : networkRes) {
JsonNode resourceName = node.get("resourceName");
nullIsIllegal(resourceName, INVALID_RESOURCE_NAME);
aggregator.setMetricsService(metricsService);
aggregator.addMetrics(Optional.of(resourceName.asText()), NETWORK_TYPE);
long inBytes = nullIsIllegal(node.get("incomingBytes").asLong(), INVALID_REQUEST);
long outBytes = nullIsIllegal(node.get("outgoingBytes").asLong(), INVALID_REQUEST);
long inPackets = nullIsIllegal(node.get("incomingPackets").asLong(), INVALID_REQUEST);
long outPackets = nullIsIllegal(node.get("outgoingPackets").asLong(), INVALID_REQUEST);
cm = new ControlMetric(ControlMetricType.NW_INCOMING_BYTES, new MetricValue.Builder().load(inBytes).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_INCOMING_BYTES, inBytes);
cm = new ControlMetric(ControlMetricType.NW_OUTGOING_BYTES, new MetricValue.Builder().load(outBytes).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_OUTGOING_BYTES, outBytes);
cm = new ControlMetric(ControlMetricType.NW_INCOMING_PACKETS, new MetricValue.Builder().load(inPackets).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_INCOMING_PACKETS, inPackets);
cm = new ControlMetric(ControlMetricType.NW_OUTGOING_PACKETS, new MetricValue.Builder().load(outPackets).add());
monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
aggregator.increment(resourceName.asText(), NETWORK_TYPE, ControlMetricType.NW_OUTGOING_PACKETS, outPackets);
}
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return ok(root).build();
}
use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.
the class ControlMetricsStatsListCommand method printMetricsStats.
/**
* Prints control plane metric statistic information.
*
* @param service monitor service
* @param nodeId node identifier
* @param typeSet control metric type
* @param resName resource name
* @param did device identifier
*/
private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, Set<ControlMetricType> typeSet, String resName, DeviceId did) {
if (resName == null && did == null) {
typeSet.forEach(s -> {
ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, Optional.empty());
printControlLoadSnapshot(s, cls);
});
} else if (resName == null) {
typeSet.forEach(s -> {
ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, Optional.of(did));
printControlLoadSnapshot(s, cls);
});
} else if (did == null) {
typeSet.forEach(s -> {
ControlLoadSnapshot cls = service.getLoadSync(nodeId, s, resName);
printControlLoadSnapshot(s, cls);
});
}
}
use of org.onosproject.cpman.ControlPlaneMonitorService in project onos by opennetworkinglab.
the class ResourceNameCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Resource type is the second argument.
String nodeId = commandLine.getArguments()[1];
String type = commandLine.getArguments()[2];
if (resourceTypes.contains(type)) {
ControlPlaneMonitorService monitorService = AbstractShellCommand.get(ControlPlaneMonitorService.class);
Set<String> set = Sets.newHashSet();
switch(type) {
case NETWORK:
set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.NETWORK);
break;
case DISK:
set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.DISK);
break;
case CONTROL_MESSAGE:
set = monitorService.availableResourcesSync(NodeId.nodeId(nodeId), ControlResource.Type.CONTROL_MESSAGE);
break;
default:
log.warn(INVALID_MSG);
break;
}
SortedSet<String> strings = delegate.getStrings();
if (!set.isEmpty()) {
set.forEach(strings::add);
}
}
return delegate.complete(session, commandLine, candidates);
}
Aggregations