SOFTLAYER - 让每个数据中心的带宽使用 [英] softlayer - getting bandwidth usage per datacenter

查看:315
本文介绍了SOFTLAYER - 让每个数据中心的带宽使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Python API SOFTLAYER,我希望得到的带宽,每个数据中心消耗的(如果不可能的,那么对每一台机器)当前结算周期。

I'm using softlayer API for python and i wish to get the bandwidth consumed by each datacenter (if not possible then for each machine) for the current billing cycle.

我试过成功认证后,使用呼叫的方法,但调用中无法找出正确的参数。

I tried to use the call method after authenticating successfully but couldn't figure out the correct parameters within the call.

感谢。

推荐答案

您可以使用

<一个href=\"http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getBandwidthData\" rel=\"nofollow\">http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getBandwidthData

<一个href=\"http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getBandwidthGraph\" rel=\"nofollow\">http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getBandwidthGraph

刚刚设置的stardDate和结束日期,以配合您的结算周期

just set the stardDate and endDate to match your billing cycle

下面的例子

"""
Retrieve a bandwidth graph for a single server.

Retrieve a bandwidth graph for a single server for an arbitrary start and
end date, specifying graph size and other graphing options. We can do this
with two calls to the SoftLayer API.

Counter data such as bandwidth counters and VSI resource use are stored in
a server's metric tracking object. Our first call retrieves that server's
tracking object record. The second call is to the tracking object service
which will generate a PNG image of our bandwidth graph.

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/getObject
http://sldn.softlayer.com/reference/services/SoftLayer_Metric_Tracking_Object/getBandwidthGraph
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Bandwidth_GraphOutputs

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer.API

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

"""
The id number of the server whose graph you wish to retrieve. Call the
getHardware() method in the SoftLayer_Account API service to retrieve a list
of the servers on your account.
"""
serverID = 87165
# The date at which you wish to start graphing bandwidth.
startDate = '2015-3-1'
# The date at which you wish to end graphing bandwidth.
endDate = '2015-4-11'
# Whether to get a graph for 'public' or 'private' bandwidth usage.
graphType = 'public'
# The height of the text in the bandwidth graph in pixels.
fontSize = 8
# The width of the graph to retrieve in pixels.
graphWidth = 827
graphHeight = 273
hideTimeZone = True

# Declaring the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
hardawareService = client['SoftLayer_Hardware_Server']
metricTrackingObject = client['SoftLayer_Metric_Tracking_Object']

try:
    trackingObject = hardawareService.getMetricTrackingObject(id=serverID)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to retrieve the metric tracking object:"
          % (e.faultCode, e.faultString))

try:
    """
    getBandwidthGraph() returns a SoftLayer_Container_Bandwidth_GraphOutputs
    object. The contents of the bandwidth image is in $image->graphImage.
    From here you can write it to the file system, display it to a web
    browser, or run other functions on it.
    """
    image = metricTrackingObject.getBandwidthGraph(startDate, endDate, graphType, fontSize, graphWidth, graphHeight, hideTimeZone, id=trackingObject['id'])
    print("Image retrieved!")
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to retrieve bandwidth image"
          % (e.faultCode, e.faultString))

这篇关于SOFTLAYER - 让每个数据中心的带宽使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆