Bandwidth summary per server

后端 未结 2 1954
一向
一向 2021-01-25 08:30

I am trying to get the bandwidth data for all the softlayer servers under my account.

Thanks to account_servers.rb I am able to get the server id for all th

2条回答
  •  感情败类
    2021-01-25 09:25

    Please, try the following Ruby examples:

    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
    

    References:

    SoftLayer_Metric_Tracking_Object::getSummaryData

    SoftLayer_Virtual_Guest::getMetricTrackingObjectId

    Second example using 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)
    

    References:

    SoftLayer_Virtual_Guest::getBandwidthDataByDate

提交回复
热议问题