SoftLayer_Virtual_Guest::getBillingCyclePublicBandwidthUsage 的 return 值的转换规则是什么?

What are the conversion rules in the SoftLayer_Virtual_Guest::getBillingCyclePublicBandwidthUsage’s return value?

我正在计算带宽的总使用量。我尝试了很多方法来获得带宽的总使用量。结果总是与门户网站相差无几。我不知道规则是否错误。因为 API SoftLayer_Virtual_Guest::getBillingCyclePublicBandwidthUsage(amountIn 和 amountOut) 的 return 值是十进制的。所以我做了如下:

result = bandwidth_mgt.sl_virtual_guest.getBillingCyclePublicBandwidthUsage(id=instance_id)
amountOut = Decimal(result['amountOut'])*1024   #GB to MB
amountIn = Decimal(result['amountIn'])*1024  #GB to MB
print 'amountOut=%s MB amountIn=%s MB' %(amountOut, amountIn)

结果是‘amountOut=31.75424 MB amountIn=30.6176 MB’。 但是门户网站的结果是 33.27 MB 和 32.1 MB。有1.5MB的不同。为什么?关注~

picture of portal site

这是预期的行为,值不完全相同,这是因为门户使用另一种方法来获取该值,如果您想获取相同的值,则需要使用相同的方法。

查看这些相关论坛。

您需要使用方法:http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getSummaryData

该方法返回的值用于在控制门户中创建图表。

我在 Python

中制作了这段代码
#!/usr/bin/env python3

import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'
vsId = 24340313

client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
vgService = client['SoftLayer_Virtual_Guest']
mtoService = client['SoftLayer_Metric_Tracking_Object']


try:
    idTrack = vgService.getMetricTrackingObjectId(id = vsId)
    object_template = [{
      'keyName': 'PUBLICIN',
      'summaryType': 'sum'
    }]

    counters = mtoService.getSummaryData('2016-09-04T00:00:00-05:00','2016-09-26T23:59:59-05:00',object_template,600, id = idTrack)

    totalIn = 0
    for counter in counters:
        totalIn = totalIn + counter["counter"]

    object_template = [{
      'keyName': 'PUBLICOUT',
      'summaryType': 'sum'
    }]

    counters = mtoService.getSummaryData('2016-09-04T00:00:00-05:00','2016-09-26T23:59:59-05:00',object_template,600, id = idTrack)

    totalOut = 0
    for counter in counters:
        totalOut = totalOut + counter["counter"]

    print( "The total INBOUND in GB: ")
    print(totalIn / 1000 / 1000 / 1000 )

    print( "The total OUTBOUND in MB: ")
    print(totalOut / 1000 / 1000 )

    print( "The total GB")
    print((totalOut + totalIn) / 1000 / 1000 / 1000 )

except SoftLayer.SoftLayerAPIError as e:    
    print("Unable get the bandwidth. "
          % (e.faultCode, e.faultString))

问候