What are the conversion rules in the SoftLayer_Virtual_Guest::getBillingCyclePublicBandwidthUsageâs return value?
<p>Iâm developing total usage for bandwidth. And I tried a lot of method to get total usage for bandwidth. The result always different from portal site while they are nearly. I donât know whether the rules is wrong or not. Because the return value of API SoftLayer_Virtual_Guest::getBillingCyclePublicBandwidthUsage(amountIn and amountOut) are decimal. So I did as following:</p>

<pre><code>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)
</code></pre>

<p>The result is âamountOut=31.75424 MB amountIn=30.6176 MBâ.
But the portal siteâs result is 33.27 MB and 32.1 MB. There is 1.5MB different. why? regard~</p>

<p><a href="http://i.stack.imgur.com/Gf9z1.png" rel="nofollow">picture of portal site</a></p>

<p>That is the expected behavior the values are not exactly the same, this is because the portal uses another method to get that value, if you want to get the same value you need to use the same method.</p>

<p>check out these related forums.</p>

<ul>
<li><a href="http://stackoverflow.com/questions/36308040/bandwidth-summary-per-server">Bandwidth summary per server</a></li>
</ul>

<p>you need to use the method: <a href="http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getSummaryData" rel="nofollow">http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getSummaryData</a> </p>

<p>The values returned by the method are the used to create the chart in control portal.</p>

<p>I made this code in Python</p>

<pre><code>#!/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))
</code></pre>

<p>regards</p>

python api bandwidth result softlayer