Skip to content

Commit

Permalink
Merge pull request #75 from RodrigoMNardi/feature/puma/monitoring
Browse files Browse the repository at this point in the history
Puma Telemetry
  • Loading branch information
RodrigoMNardi authored Jun 13, 2024
2 parents 30e2330 + 7693354 commit 4de789d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/github_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def sinatra_logger_level
attr_writer :sinatra_logger_level
end

get '/telemetry' do
content_type :json

Telemetry.instance.stats
end

get '/ping' do
halt 200, 'Pong'
end
Expand Down
18 changes: 14 additions & 4 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

# SPDX-License-Identifier: BSD-2-Clause
#
# puma.rb
Expand All @@ -8,16 +6,28 @@
# Copyright (c) 2023 by
# Network Device Education Foundation, Inc. ("NetDEF")
#
# frozen_string_literal: true

require_relative '../config/setup'
require 'puma'

workers 10

threads_count = (ENV['RAILS_MAX_THREADS'] || 5).to_i
threads 1, threads_count
threads 1, (ENV['RAILS_MAX_THREADS'] || 5).to_i

port GitHubApp::Configuration.instance.config['port'] || 4667

activate_control_app

preload_app!

pidfile 'puma.pid'

before_fork do
Thread.new do
loop do
Telemetry.instance.update_stats Puma.stats
sleep 30
end
end
end
1 change: 1 addition & 0 deletions lib/github_ci_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require_relative 'helpers/github_logger'
require_relative 'helpers/request'
require_relative 'helpers/sinatra_payload'
require_relative 'helpers/telemetry'

# Slack libs
require_relative 'slack/slack'
Expand Down
26 changes: 26 additions & 0 deletions lib/helpers/telemetry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-License-Identifier: BSD-2-Clause
#
# telemetry.rb
# Part of NetDEF CI System
#
# Copyright (c) 2024 by
# Network Device Education Foundation, Inc. ("NetDEF")
#
# frozen_string_literal: true

require 'singleton'
require 'json'

class Telemetry
include Singleton

# :nocov:
def update_stats(stats)
File.write('telemetry.json', stats.to_json)
end

def stats
JSON.parse(File.read('telemetry.json'))
end
# :nocov:
end

0 comments on commit 4de789d

Please sign in to comment.