Class: Conversant::V3::Services::CDN::Partner::Analytics

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

Overview

CDN analytics service for partner-level reporting

Provides partner-level analytics and reporting for CDN services including bandwidth, volume, traffic usage, storage, and viewer metrics across multiple customer accounts.

Examples:

Usage

cdn = Conversant::V3.cdn(customer_id)
analytics = cdn.partner.analytics

# Get bandwidth metrics
bandwidth_data = analytics.bandwidth({
  startTime: '2024-01-01T00:00:00Z',
  endTime: '2024-01-31T23:59:59Z',
  interval: 'day'
})

Since:

  • 1.0.12

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Analytics

Initialize partner CDN analytics service

Parameters:

Since:

  • 1.0.12



33
34
35
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 33

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

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

Returns the parent CDN service instance.

Returns:

Since:

  • 1.0.12



28
29
30
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 28

def parent
  @parent
end

Instance Method Details

#bandwidth(payload) ⇒ Hash

Get partner-level bandwidth metrics

Retrieves aggregated bandwidth usage across all customer accounts for the partner within the specified time range.

Examples:

Get daily bandwidth for January 2024

analytics.bandwidth({
  startTime: '2024-01-01T00:00:00Z',
  endTime: '2024-01-31T23:59:59Z',
  interval: 'day'
})

Parameters:

  • payload (Hash)

    bandwidth query parameters

Options Hash (payload):

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval (e.g., "hour", "day", "month")

Returns:

  • (Hash)

    bandwidth data with timestamps and values, or nil on error

Since:

  • 1.0.8



56
57
58
59
60
61
62
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 56

def bandwidth(payload)
  response = @parent.send(:call, 'POST', '/api/report/bandwidth/partner', payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#domain_http_codes(customer_id, payload) ⇒ Hash

Get HTTP status codes for specific domains

Retrieves HTTP status code distribution for specified domains, useful for monitoring error rates and response codes.

Examples:

Get HTTP codes for specific domains

analytics.domain_http_codes(123, {
  domains: ['cdn.example.com', 'static.example.com'],
  startTime: '2024-01-01T00:00:00Z',
  endTime: '2024-01-02T00:00:00Z',
  interval: 'hour'
})

Parameters:

  • customer_id (String, Integer)

    customer ID

  • payload (Hash)

    HTTP codes query parameters

Options Hash (payload):

  • :domains (Array<String>)

    array of domain names

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval (e.g., "hour", "day")

  • :daHostName (String)

    specific hostname filter (optional)

Returns:

  • (Hash)

    HTTP codes data grouped by status code, or nil on error

Since:

  • 1.0.8



206
207
208
209
210
211
212
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 206

def domain_http_codes(customer_id, payload)
  response = @parent.send(:call, 'POST', "/api/report/customers/#{customer_id}/http_codes", payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#domain_rps(params) ⇒ Hash

Get request per second for specific domain

Parameters:

  • params (Hash)

    query parameters

Returns:

  • (Hash)

    RPS data for domain, or nil on error

Since:

  • 1.0.8



220
221
222
223
224
225
226
227
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 220

def domain_rps(params)
  query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')
  response = @parent.send(:call, 'GET', "/api/rps_chart_data?#{query_string}")
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#domain_traffic_usage(payload) ⇒ Hash

Get domain traffic usage for billing purposes

Parameters:

  • payload (Hash)

    usage query parameters

Options Hash (payload):

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :pageSize (Integer)

    number of results per page

  • :pageNumber (Integer)

    page number (0-based)

Returns:

  • (Hash)

    traffic usage data, or nil on error

Since:

  • 1.0.8



106
107
108
109
110
111
112
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 106

def domain_traffic_usage(payload)
  response = @parent.send(:call, 'POST', '/api/domain_traffic_usage', payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#domain_volume(payload) ⇒ Hash

Get volume metrics for a specific domain

Parameters:

  • payload (Hash)

    volume query parameters

Options Hash (payload):

  • :domain (String)

    domain name

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval (e.g., "day")

  • :fillFixedTime (Boolean)

    fill missing time slots

Returns:

  • (Hash)

    volume data for domain, or nil on error

Since:

  • 1.0.8



175
176
177
178
179
180
181
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 175

def domain_volume(payload)
  response = @parent.send(:call, 'POST', '/api/report/volume', payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#request_per_second(params) ⇒ Hash

Get partner-level request per second metrics

Parameters:

  • params (Hash)

    query parameters

Returns:

  • (Hash)

    RPS data, or nil on error

Since:

  • 1.0.8



87
88
89
90
91
92
93
94
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 87

def request_per_second(params)
  query_string = params.map { |k, v| "#{k}=#{v}" }.join('&')
  response = @parent.send(:call, 'GET', "/api/rps_chart_data/partner?#{query_string}")
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#usages(payload) ⇒ Integer

Get storage usage for a customer

Retrieves the disk usage for the current month or specified month. If no end date is provided in the payload, it defaults to the current date.

Examples:

Get current month's storage usage

analytics.usages(nil)
# => 1024000

Get specific month's storage usage

analytics.usages({ end: '2024-03-15' })
# => 2048000

Parameters:

  • payload (Hash, nil)

    query parameters (optional)

Options Hash (payload):

  • :end (String, Date)

    end date to determine year/month (defaults to current date)

Returns:

  • (Integer)

    disk usage in bytes for the specified month, or 0 on error

Since:

  • 1.0.8



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 149

def usages(payload)
  payload = payload&.as_json
  today = (payload&.[]('end') || Date.current).to_date

  # puts @parent.inspect

  response = @parent.send(:call, 'GET', "/api/customers/#{@parent.customer_id}/storage_usages/#{today.year}")
  JSON.parse(response)&.find do |item|
    item&.[]('month') == today.month
  end&.[]('diskUsage') || 0
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  0
end

#viewers(payload) ⇒ Hash

Get partner-level viewer metrics

Parameters:

  • payload (Hash)

    viewer query parameters

Options Hash (payload):

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

Returns:

  • (Hash)

    viewer data, or nil on error

Since:

  • 1.0.8



123
124
125
126
127
128
129
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 123

def viewers(payload)
  response = @parent.send(:call, 'POST', '/api/report/viewers/partner', payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#volume(payload) ⇒ Hash

Get partner-level volume metrics

Parameters:

  • payload (Hash)

    volume query parameters

Options Hash (payload):

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

Returns:

  • (Hash)

    volume data, or nil on error

Since:

  • 1.0.8



73
74
75
76
77
78
79
# File 'lib/conversant/v3/services/cdn/partner/analytics.rb', line 73

def volume(payload)
  response = @parent.send(:call, 'POST', '/api/report/volume/partner', payload)
  JSON.parse(response)
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end