I am trying to get a bandwidth usage using Java Client API of Softlayer. The result of the API below is the throughput of bandwidth. Is there any API getting a bandwidth usage
Try this code:
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import com.google.gson.Gson;
import com.softlayer.api.ApiClient;
import com.softlayer.api.RestApiClient;
import com.softlayer.api.service.virtual.Guest;
import com.softlayer.api.service.container.metric.data.Type;
import com.softlayer.api.service.metric.tracking.Object;;
public class GetBandwidth {
public static void main(String[] args) {
String user = "set me";
String apikey = "set me";
// the VSI id
Long vsiId = new Long(15003381);
// Declare the API client
ApiClient client = new RestApiClient().withCredentials(user, apikey);
Guest.Service vsiService = Guest.service(client, vsiId);
// Declaring the object mask to get information about the items
vsiService.setMask("mask[id,metricTrackingObjectId]");
try {
Long metrictId = vsiService.getObject().getMetricTrackingObjectId();
Object.Service objectService = Object.service(client, metrictId);
List validTypes = new ArrayList();
Type typeIn = new Type();
typeIn.setName("PUBLICin");
typeIn.setKeyName("PUBLICIN");
typeIn.setSummaryType("sum");
Type typeOut = new Type();
typeOut.setName("PUBLICout");
typeOut.setKeyName("PUBLICOUT");
typeOut.setSummaryType("sum");
validTypes.add(typeIn);
validTypes.add(typeOut);
GregorianCalendar startDateTime = new GregorianCalendar(2016, 02, 04, 0, 0, 0);
GregorianCalendar endDateTime = new GregorianCalendar(2016, 02, 18, 11, 59, 59);
Long summaryPeriod = new Long(1800);
Gson gson = new Gson();
System.out.println(gson.toJson(objectService.getSummaryData(startDateTime, endDateTime, validTypes, summaryPeriod)));
} catch (Exception e) {
System.out.println("Unable to retrieve the bandwidht. "
+ e.getMessage());
}
}
}