November 23, 2017
Retrieve a list of switch port statistics for a server's network interfaces.

This script makes a single call to the getPortStatistics() method in the
SoftLayer_Network_Component API service
for each of a server's network components to query port statistics for that
interface from SoftLayer's switches. Port statistics are modeled by the
SoftLayer__Container_Network_Port_Statistic data type
See below for more details.

Important manual pages:

Author: SoftLayer Technologies, Inc. <>
import SoftLayer.API
from pprint import pprint as pp

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

Your server's id. Call the getHardware() method in the SoftLayer_Account API
service (
to get a list of your account's hardware records.
serverId = 87165

# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
hardwareServerService = client['SoftLayer_Hardware_Server']
networkComponentService = client['SoftLayer_Network_Component']

Switching port statistics are measured off the server's network components. Use
an object mask to network component records along with our server record.
objectMask = "mask[networkComponents]"

    Making the call to retrieve our hardware record. Once we have that we can query
    the server's network components.
    server = hardwareServerService.getObject(mask=objectMask, id=serverId)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to retrieve server record. "
          % (e.faultCode, e.faultString))

# Separating our network components for easier processing later.
networkComponents = server['networkComponents']
# Print out a simple report header.
pp("Switchport statistics for " + server['fullyQualifiedDomainName'])

Loop through our server's network components. For each NIC make a call to the
SoftLayer_Network_Component API service method getPortStatics() to get a list
of switchport statistics retrieved from the switch on the other side of your
NIC. Print a simple report per NIC.
for networkComponent in networkComponents:
    # Skip the management network component.
    if networkComponent['name'] != 'mgmt':
            # Retrieve switchport statistics for the NIC.
            stats = networkComponentService.getPortStatistics(id=networkComponent['id'])
        except SoftLayer.SoftLayerAPIError as e:
            print("Unable to retrieve switchport statics for . " + networkComponent['name'] + networkComponent['port'] % (e.faultCode, e.faultString))


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue