-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Que monitoring implemented * Que monitoring added to admin page * Changed Gemfile.lock * Got rid of global variable
- Loading branch information
DevTomii
committed
Jun 27, 2023
1 parent
fd72b53
commit d0d1f0a
Showing
10 changed files
with
107 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Environment | ||
extend self | ||
|
||
def stats_reporter | ||
@stats_reporter ||= StatsReporter.new( | ||
aws_cloudwatch_client, | ||
Rails.env | ||
) | ||
end | ||
|
||
# INFRASTRUCTURE AWS OBJECTS | ||
def aws_cloudwatch_client | ||
@aws_cloudwatch_client ||= build_aws_cloudwatch_client | ||
end | ||
|
||
def aws_credentials | ||
@aws_credentials ||= Aws::Credentials.new( | ||
ENV.fetch('AWS_ACCESS_KEY_ID'), | ||
ENV.fetch('AWS_SECRET_ACCESS_KEY') | ||
) | ||
end | ||
|
||
def aws_region | ||
@aws_region ||= ENV.fetch('AWS_REGION') | ||
end | ||
|
||
private | ||
def build_aws_cloudwatch_client | ||
Aws::CloudWatch::Client.new( | ||
credentials: aws_credentials, | ||
region: aws_region | ||
) | ||
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,27 @@ | ||
class StatsReporter | ||
def initialize(cloudwatch_client, environment) | ||
@client = cloudwatch_client | ||
@environment = environment | ||
end | ||
|
||
def report_quarter_hourly | ||
report_metric('JobsCount', Que::ActiveRecord::Model.count) | ||
report_metric('FailedJobsCount', Que::ActiveRecord::Model.errored.count) | ||
report_metric('StuckJobsCount', Que::ActiveRecord::Model.where('run_at < ?', 1.hour.ago).count) | ||
end | ||
|
||
private | ||
def report_metric(name, value) | ||
@client.put_metric_data( | ||
namespace: 'NavodyDigital', | ||
metric_data: [ | ||
{ | ||
metric_name: name, | ||
dimensions: [{ name: 'Environment', value: @environment }], | ||
timestamp: Time.current.utc, | ||
value: value, | ||
} | ||
] | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# This file is used by Rack-based servers to start the application. | ||
|
||
require_relative 'config/environment' | ||
# Added que-web gem for showing job tracking | ||
require 'que/web' | ||
|
||
map '/admin/que' do | ||
run Que::Web | ||
end | ||
|
||
require_relative 'config/environment' | ||
run Rails.application |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Authentication allowing only admin to view the que status | ||
Que::Web.use(Rack::Auth::Basic) do |user, password| | ||
[user, password] == [Rails.application.config_for(:app).dig(:admin, :username), | ||
Rails.application.config_for(:app).dig(:admin, :password)] | ||
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