在 SL 中获取带宽数据

Getting bandWidth data in SL

我正在尝试使用 Softlayer 的 Java 客户端 API 获取带宽使用情况。 下面API的结果是带宽的吞吐量。是否有 API 使用 java 获取带宽使用数据?

List<Data> dataList = Guest.service(client, deviceID).getBandwidthDataByDate(startDate, endDate, "public"); // throuput

请教我为什么API的带宽吞吐量数据与control.softlayer.com的数据不同。获取精确数据有什么关键因素吗?

试试这个代码:

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<Type> validTypes = new ArrayList<Type>();
            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());
        }

    }

}