Class: Conversant::V3::Services::OSS::Partner::Analytics

Inherits:
Object
  • Object
show all
Defined in:
lib/conversant/v3/services/oss/partner/analytics.rb

Overview

OSS (Object Storage Service) analytics for partner-level reporting

Provides partner-level analytics and reporting for Object Storage Service including storage usage metrics for S3-compatible storage across multiple customer accounts.

Since:

  • 1.0.12

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Analytics

Initialize partner OSS analytics service

Note: OSS analytics uses the CDN service endpoint for API calls.

Since:

  • 1.0.12



24
25
26
# File 'lib/conversant/v3/services/oss/partner/analytics.rb', line 24

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentConversant::V3::Services::OSS (readonly)

Returns the parent OSS service instance.

Since:

  • 1.0.12



17
18
19
# File 'lib/conversant/v3/services/oss/partner/analytics.rb', line 17

def parent
  @parent
end

Instance Method Details

#current_month_usage(payload = {}) ⇒ Integer?

Get storage usage for current month

Retrieves disk usage for the month containing the specified date (or current month). This is useful for getting current month's storage usage for billing purposes.

Examples:

Get current month's storage usage

usage = oss.partner.analytics.current_month_usage
puts "Current usage: #{usage / 1_073_741_824.0} GB"

Get specific month's storage usage

usage = oss.partner.analytics.current_month_usage(end: '2025-04-30')
puts "April 2025 usage: #{usage / 1_073_741_824.0} GB"

Options Hash (payload):

  • :end (Date, String, Time)

    End date for the query (defaults to current date)

Since:

  • 1.0.12



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/conversant/v3/services/oss/partner/analytics.rb', line 77

def current_month_usage(payload = {})
  require 'date'

  # Extract the end date from the payload, defaulting to the current date
  today = if payload.[](:end) || payload.[]('end')
            (payload[:end] || payload['end']).to_date
          else
            Date.today
          end

  # Fetch storage usage data for the year containing the end date
  yearly_data = usages(today.year.to_s)
  return 0 if yearly_data.nil? || yearly_data.empty?

  # Find the storage usage for the specific month
  today_month_format = today.strftime('%Y-%m')
  month_data = yearly_data.find { |item| item&.[]('month') == today_month_format }

  month_data&.[]('diskUsage') || 0
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#usages(year, params = {}) ⇒ Array<Hash>

Get storage usage metrics for OSS (full year data)

Retrieves Object Storage Service usage data including storage capacity, bandwidth usage, and request counts aggregated by month for billing and capacity planning purposes. Returns all months for the specified year.

Examples:

Get OSS storage usage for a year

usages = oss.partner.analytics.usages("2025")
usages.each do |month|
  puts "#{month['month']}: #{month['diskUsage']} bytes"
end

Options Hash (params):

  • :end (String)

    end date for the report

Since:

  • 1.0.8



47
48
49
50
51
52
53
54
55
56
# File 'lib/conversant/v3/services/oss/partner/analytics.rb', line 47

def usages(year, params = {})
  query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')
  uri = "/oss/storage_usages/#{year}"
  uri += "?#{query_string}" unless query_string.empty?
  response = @parent.send(:call, 'GET', uri)
  JSON.parse(response) || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end