Forum Discussion

Mickelukas_3582's avatar
Mickelukas_3582
Icon for Nimbostratus rankNimbostratus
May 07, 2018

CPU, memory, disk usage and http profile using the BIG-IP Python SDK

I've been busy with the Python SDK for a couple of weeks now. While I managed to get a lot of information out of it, I'm struggling with a couple of API endpoints. Does anyone have an idea where I can find the statistics for CPU, Memory, Disk as well as the http profile? REST endpoints: mgmt/tm/sys/hostInfo (for CPU and memory) mgmt/tm/sys/disk/logical-disk (for disks) mgmt/tm/ltm/profile/http/stats (for http profile)

 

Thanks! Mike

 

  • A sample code:

     

    from f5.bigip import ManagementRoot
    mgmt = ManagementRoot('192.168.184.30', 'admin', 'admin')
    
    logicalDisk = mgmt.tm.sys.disk.logical_disks.get_collection()
    diskKeys = ['mode', 'size', 'vgFree', 'vgInUse', 'vgReserved']
    for ld in logicalDisk:
        print('--- list sys disk logical-disk {} all-properties ---'.format(ld.__dict__['name']))
        for k in diskKeys:
            print('{:<15} {}'.format(k, ld.__dict__[k]))
    

     

  • As shown in the Github Issue 1436, the feature became available from SDK version 3.0.15.

     

    To check the current version on your box, run

     

     pip show f5-sdk

    To upgrade to the latest, run

     

     pip install --upgrade f5-sdk

    A sample code for host_info:

     

    from f5.bigip import ManagementRoot
    mgmt = ManagementRoot('xx.xx.xx.xx', 'admin', 'passwd')
    
    host = mgmt.tm.sys.host_info.load()
    
    def recurse(dictionary, level):
        for key, value in dictionary.iteritems():
            if isinstance(value, dict):
                print('{}{}:'.format(' '*level, key))
                recurse(value, level+1)
            else:
                print('{} {} : {}'.format(' '*level, key, value))
    
    recurse(host.raw, 0)