-1

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

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?

Mike Oh
  • 151
  • 5
  • Did you try the method I told you in your last question? http://stackoverflow.com/questions/35987800/resource-data-in-softlayer the main reason that you got different values is because the methods you used return average values and the portal return the sum values. – Nelson Raul Cabero Mendoza Mar 17 '16 at 13:11
  • Yes I found API for cpu and memory usage was working find, but I can't find JAVA API to get a usage of bandwidth. "getBandwidthDataByDate()" seems to return "throughput" data and this data is not matched to the data of softlayer control.com. – Mike Oh Mar 18 '16 at 01:58
  • the code I sent you should return the usage, for throughput data you just need to change the sumarytype value from sum to timeaverage. I will try to do an example in java and I will submit it here. – Nelson Raul Cabero Mendoza Mar 18 '16 at 13:29
  • Thanks. When I change the summaryType value from sum to timeaverage, it returns {"error":"All metrics in a single request must use the same summary type.","code":"SoftLayer_Exception"}. What is the size of data unit in Usage data? bytes? Usage graph is the sum of this bunch of data in specific period. right? – Mike Oh Mar 21 '16 at 06:35
  • The error is werid for me it is working fine, the dataq unit is bytes and it should be the sum of data in the specific period – Nelson Raul Cabero Mendoza Mar 21 '16 at 13:32
  • I've added what i have tested below.. – Mike Oh Mar 22 '16 at 08:13

1 Answers1

0

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

    }

}
  • How can I know what kind of types and summary types as parameter I can choose ? I can't find the info in SL API. – Mike Oh Mar 21 '16 at 06:40
  • That is tricky this method should return the valid data types http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getMetricDataTypes , but it seems it has some issues because it do not return neither the timeaverage nor the sum. – Nelson Raul Cabero Mendoza Mar 21 '16 at 13:34