Search in sources :

Example 1 with StatisticService

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);
}
Also used : Load(org.onosproject.net.statistic.Load) DeviceId(org.onosproject.net.DeviceId) StatisticService(org.onosproject.net.statistic.StatisticService) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with StatisticService

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();
}
Also used : Load(org.onosproject.net.statistic.Load) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StatisticService(org.onosproject.net.statistic.StatisticService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UriBuilder(javax.ws.rs.core.UriBuilder) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)2 Load (org.onosproject.net.statistic.Load)2 StatisticService (org.onosproject.net.statistic.StatisticService)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 DeviceId (org.onosproject.net.DeviceId)1 Link (org.onosproject.net.Link)1 PortNumber (org.onosproject.net.PortNumber)1