use of org.onosproject.net.statistic.StatisticService in project onos by opennetworkinglab.
the class GetStatisticsCommand method doExecute.
@Override
protected void doExecute() {
StatisticService service = get(StatisticService.class);
DeviceId ingressDeviceId = deviceId(getDeviceId(connectPoint));
PortNumber ingressPortNumber = portNumber(getPortNumber(connectPoint));
ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber);
Load load = service.load(cp);
print("Load on %s -> %s", cp, load);
}
use of org.onosproject.net.statistic.StatisticService in project onos by opennetworkinglab.
the class StatisticsWebResource method getLoads.
/**
* Gets load statistics for all links or for a specific link.
*
* @onos.rsModel StatisticsFlowsLink
* @param deviceId (optional) device ID for a specific link
* @param port (optional) port number for a specified link
* @return 200 OK with JSON encoded array of Load objects
*/
@GET
@Path("flows/link")
@Produces(MediaType.APPLICATION_JSON)
public Response getLoads(@QueryParam("device") String deviceId, @QueryParam("port") String port) {
Iterable<Link> links;
if (deviceId == null || port == null) {
links = get(LinkService.class).getLinks();
} else {
ConnectPoint connectPoint = new ConnectPoint(deviceId(deviceId), portNumber(port));
links = get(LinkService.class).getLinks(connectPoint);
}
ObjectNode result = mapper().createObjectNode();
ArrayNode loads = mapper().createArrayNode();
JsonCodec<Load> loadCodec = codec(Load.class);
StatisticService statsService = getService(StatisticService.class);
StreamSupport.stream(Spliterators.spliteratorUnknownSize(links.iterator(), Spliterator.ORDERED), false).forEach(link -> {
ObjectNode loadNode = loadCodec.encode(statsService.load(link), this);
UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("links").queryParam("device", link.src().deviceId().toString()).queryParam("port", link.src().port().toString());
loadNode.put("link", locationBuilder.build().toString());
loads.add(loadNode);
});
result.set("loads", loads);
return ok(result).build();
}
Aggregations