在SL中获取bandWidth数据 [英] Getting bandWidth data in SL

查看:47
本文介绍了在SL中获取bandWidth数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 data with java ?

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

请问我为什么使用此API的带宽吞吐量数据与control.softlayer.com的数据不同.获取精确数据是否有任何关键因素?

Pls advice me why the bandwidth throughput data with this API are different from the data of control.softlayer.com. Is there any critical factor to get precise data?

推荐答案

尝试以下代码:

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());
        }

    }

}

这篇关于在SL中获取bandWidth数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆