-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1115 from senid231/improve-calls-monitoring
Improve calls monitoring
- Loading branch information
Showing
15 changed files
with
566 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/services/active_calls/create_origination_gateway_stats.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveCalls | ||
class CreateOriginationGatewayStats < ApplicationService | ||
parameter :calls, required: true | ||
parameter :current_time, required: true | ||
|
||
def call | ||
attrs_list = build_calls_attrs_list | ||
missing_gateway_ids = Gateway.where.not(id: calls.keys).pluck(:id) | ||
attrs_list.concat build_empty_attrs_list(missing_gateway_ids) | ||
return if attrs_list.empty? | ||
|
||
Stats::ActiveCallOrigGateway.insert_all!(attrs_list) | ||
end | ||
|
||
private | ||
|
||
def build_calls_attrs_list | ||
calls.map do |gateway_id, sub_calls| | ||
{ | ||
count: sub_calls.count, | ||
created_at: current_time, | ||
gateway_id: gateway_id | ||
} | ||
end | ||
end | ||
|
||
def build_empty_attrs_list(gateway_ids) | ||
gateway_ids.map do |gateway_id| | ||
{ | ||
count: 0, | ||
created_at: current_time, | ||
gateway_id: gateway_id | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveCalls | ||
class CreateStats < ApplicationService | ||
parameter :calls, required: true | ||
parameter :current_time, required: true | ||
|
||
def call | ||
attrs_list = build_calls_attrs_list | ||
missing_node_ids = Node.where.not(id: calls.keys).pluck(:id) | ||
attrs_list.concat build_empty_attrs_list(missing_node_ids) | ||
return if attrs_list.empty? | ||
|
||
Stats::ActiveCall.insert_all!(attrs_list) | ||
end | ||
|
||
private | ||
|
||
def build_calls_attrs_list | ||
calls.map do |node_id, sub_calls| | ||
{ | ||
count: sub_calls.count, | ||
created_at: current_time, | ||
node_id: node_id | ||
} | ||
end | ||
end | ||
|
||
def build_empty_attrs_list(node_ids) | ||
node_ids.map do |node_id| | ||
{ | ||
count: 0, | ||
created_at: current_time, | ||
node_id: node_id | ||
} | ||
end | ||
end | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
app/services/active_calls/create_termination_gateway_stats.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveCalls | ||
class CreateTerminationGatewayStats < ApplicationService | ||
parameter :calls, required: true | ||
parameter :current_time, required: true | ||
|
||
def call | ||
attrs_list = build_calls_attrs_list | ||
missing_gateway_ids = Gateway.where.not(id: calls.keys).pluck(:id) | ||
attrs_list.concat build_empty_attrs_list(missing_gateway_ids) | ||
return if attrs_list.empty? | ||
|
||
Stats::ActiveCallTermGateway.insert_all!(attrs_list) | ||
end | ||
|
||
private | ||
|
||
def build_calls_attrs_list | ||
calls.map do |gateway_id, sub_calls| | ||
{ | ||
count: sub_calls.count, | ||
created_at: current_time, | ||
gateway_id: gateway_id | ||
} | ||
end | ||
end | ||
|
||
def build_empty_attrs_list(gateway_ids) | ||
gateway_ids.map do |gateway_id| | ||
{ | ||
count: 0, | ||
created_at: current_time, | ||
gateway_id: gateway_id | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.