我正在尝试获取我帐户下所有软层服务器的带宽数据.
I am trying to get the bandwidth data for all the softlayer servers under my account.
由于account_servers.rb,我能够获取所有服务器的服务器ID.现在,我想获取服务器在特定时间范围内使用的带宽.我感兴趣的数据是
Thanks to account_servers.rb I am able to get the server id for all the servers. Now I would like to get the Bandwidth used by the servers for a particular time frame. The data that I am interested is
sldn.softlayer/reference/datatypes/SoftLayer_Metric_Tracking_Object_Bandwidth_Summary
我尝试使用softlayer_client.service_named("Metric_Tracking_Object_Bandwidth_Summary")获取信息.不幸的是,我无法获得详细信息.
I tried to get information using softlayer_client.service_named("Metric_Tracking_Object_Bandwidth_Summary"). Unfortunately I am not able to get the details.
我确实找到了Java代码,但是我对ruby代码感兴趣.有人可以指导我获取服务器摘要摘要吗?
I did find a java code, but I am interested in ruby code. Can someone please guide me to get the server bandwith summary?
在SL中获取带宽数据
推荐答案请尝试以下Ruby示例:
require 'rubygems' require 'softlayer_api' server_id = 11498369 # Your SoftLayer API username. SL_API_USERNAME = 'set me' # Your SoftLayer API key. SL_API_KEY = 'set me' softlayer_client = SoftLayer::Client.new(:username => SL_API_USERNAME, :api_key => SL_API_KEY) vsi_service = softlayer_client.service_named('SoftLayer_Virtual_Guest') metric_tracking_object_id = vsi_service.object_with_id(server_id).getMetricTrackingObjectId metric_service = softlayer_client.service_named('SoftLayer_Metric_Tracking_Object') service_ref = metric_service.object_with_id(metric_tracking_object_id) begin object_template = [{ 'keyName' => 'PUBLICOUT', 'summaryType' => 'sum' }] result = service_ref.getSummaryData('2016-03-29T00:00:00','2016-03-30T00:00:00',object_template,600) puts result.inspect rescue => e puts 'Error when executing the script...' $stdout.print(e.inspect) end参考:
SoftLayer_Metric_Tracking_Object :: getSummaryData
SoftLayer_Virtual_Guest :: getMetricTrackingObjectId
使用SoftLayer_Virtual_Gues::getBandwidthDataByDate的第二个示例:
require 'rubygems' require 'softlayer_api' require 'pp' require 'date' # Set the server id that you wish to get Bandwidth information. server_id = 11498369 softlayer_client = SoftLayer::Client.new(:username => 'set me', :api_key => 'set me') server = SoftLayer::VirtualServer.server_with_id(server_id, :client => softlayer_client) get_bandwidth_data_by_date = server.service.getBandwidthDataByDate('2016-03-29T00:00:00','2016-03-30T00:00:00','public') pp('getBandwidthDataByDate: ', get_bandwidth_data_by_date)参考:
SoftLayer_Virtual_Guest :: getBandwidthDataByDate
更多推荐
每台服务器的带宽摘要
发布评论