SoftLayer\u Virtual\u Guest::getBillingCyclePublicBandwidthUsage的返回值中的转换规则是什么?

2024-04-19 22:07:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发带宽的总使用量。我尝试了很多方法来获得带宽的总使用率。结果总是不同于门户网站,而他们几乎是。我不知道规则是不是错了。因为API SoftLayer\u Virtual\u Guest::getBillingCyclePublicBandwidthUsage的返回值(amountIn和amountOut)是十进制的。所以我做了如下工作:

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


Tags: to方法apiid规则mbresult使用量
1条回答
网友
1楼 · 发布于 2024-04-19 22:07:59

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

看看这些相关的论坛。你知道吗

您需要使用以下方法: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))

敬礼

相关问题 更多 >