How to get user's utilization by Utilization API

Hugo Kuo -

 

1) If the account exists for the given cluster we get something like

{
"meta": {
    "account": "KEY_73fb6ab917e94356a7f1e06a1148c028",
    "limit": 1,
    "next": null,
    "offset": 0,
    "policy_idx": 0,
    "previous": null,
    "total_count": 1
},
"objects": [ {
    "bytes_used": 9297959701,
    "container_count": 2,
    "end": "2014-11-21 18:00:00Z",
    "object_count": 385,
    "pct_complete": 100.0,
    "start": "2014-11-21 17:00:00Z"
    } ]
}

where the percentage of completion could be 0, if stats aren't available yet.

2) If an account never exists for the given cluster we get this

{
"meta": {
    "limit": 1,
    "next": null,
    "offset": 0,
    "previous": null,
    "total_count": 0
    },
"objects": [ ]
}

 

 More details : https://platform.swiftstack.com/docs/admin/api/utilization.html

Have more questions? Submit a request

Comments

  • Avatar
    Hugo Kuo

    For the API endpoints that return lists, an empty list only means that there were zero records, given the search constraints.

    As an example, with my development controller, an query to the endpoint /api/v1/clusters/1/utilization/storage/0/AUTH_dev/detail/ may return

    { 
    "meta": { 
        "limit": 20, 
        "next": null, 
        "offset": 0, 
        "previous": null, 
        "total_count": 0 
        }, 
    "objects": [] 
    }
    

    or

    { 
    "meta": { 
        "account": "AUTH_dev", 
        "limit": 20, 
        "next": null, 
        "offset": 0, 
        "policy_idx": 0, 
        "previous": null, 
        "total_count": 3 
        }, 
    "objects": [ { 
        "bytes_used": 3730401, 
        "container_count": 1, 
        "end": "2014-11-24 22:00:00Z", 
        "object_count": 191, 
        "pct_complete": 100.0, 
        "start": "2014-11-24 21:00:00Z" 
        }, ] 
    }
    

    Depending on which start and end parameters I specify.

    If you want to know if a specific Swift Account name has any data for a time period, you can use the /api/v1/clusters/<ID>/utilization/storage/<POLICY_IDX>/<ACCOUNT>/ endpoint with start and end values which cover the time period over which you want to know if the Swift Account had utilization data reported for it.

    If you want to know the list of all Swift Accounts for which data was received, between a specific start and end time, you can use the /api/v1/clusters/<ID>/utilization/storage/<POLICY_IDX>/ endpoint and examine the returned list of accounts.

    Note that the /api/v1/clusters/<ID>/utilization/storage/<POLICY_IDX>/<ACCOUNT>/detail/ endpoint and the corresponding transfer endpoint are the least efficient methods of extracting utilization data. The primary endpoint we expect to be used for billing is the /api/v1/clusters/<ID>/utilization/storage/<POLICY_IDX>/ endpoint, called once per period-of-billing, with account names extracted from the resulting list.

    In rough pseudo-code, assuming an external system with a notion of billable accounts with a 1:1 defined mapping between those accounts and Swift Accounts, I would imagine a process like this to run once per period-of-billing:

    start = ... 
    end = ... # should be BEFORE "now - utilization_finalization_days" 
    known_accounts = get_accounts_from_external_system() 
    for one_account in account_usage_between(start, end, policy_idx=0): 
    if one_account['account'] in known_accounts: 
    # Handle billing for existing account... 
    known_accounts.pop(one_account['account']) 
    else: 
    # Ignore; system accounts appear in utilization data but won't be in your external system
    
    # Anything remaining is a "known account" in the external system which either had no 
    # Swift Account DB present in the cluster during the given start/end time, or a failure 
    # condition prevented reporting of utilization data for more than your Organization's 
    # configured utilization_finalization_days number of days (see 
    # https://platform.swiftstack.com/docs/admin/api/utilization.html#correctness specifically, 
    # the "we recommend you only request Utilization data via this API for time periods older 
    # than your Organization’s configured 'Utilization finalization days.' part)
    
    for missing_account in known_accounts: 
    # handle "no billing data for known account" situation; i.e. bill them zero (0).
    
Powered by Zendesk