puma-log_stats-codeur 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7088c577694fb2913018a740122202a4ef2a27eaae1beed620b0a12fcf459059
4
- data.tar.gz: 1e98c214093d2b80b5a214b554e2d004ffba39aeb24d205c018fccea8d074321
3
+ metadata.gz: 7dccacaaaed068382710999238bf1563335653ba81ac0afe70373eb53fc6c4ec
4
+ data.tar.gz: 3183d3640deb3b060873061e10087c06e429aa0be8d60ba0b8924adf3c379890
5
5
  SHA512:
6
- metadata.gz: 885dbee8b5d1f80f666f004d733487ed6f6dc809cefa5505309bc9f4bd266fb6cfaa85b505ed6f63ecab669b0aefab4c7754929a0d0912f5c7c2a0727a866ad9
7
- data.tar.gz: 51d5bc462ff4c14dab1769a01b4a19f34e380e3f533fa769a78da3079b55090ade9c8f5d54a547d4058579c4e839ea492100e3339119323fbf36e9287e07a342
6
+ metadata.gz: 060ed7df03b49ccfb212d4d18f117bff2f4fc054fc6dcece408d11efbd8bbacf4f958c9e7e46251fb3da1703318afb60df7bad77723038677febf1197cc5d7bf
7
+ data.tar.gz: fbf036c802861ff041d4a3c777af0767b6c8e0d73cebb489c2049dea6183036f16bd6964cd8b8c54312a244502454271ead82259e2cb4abcee93f82811919a6c
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Puma
4
4
  module LogStats
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -2,138 +2,140 @@
2
2
 
3
3
  require "puma/plugin"
4
4
 
5
- module LogStats
6
- class << self
7
- # Interval between logging attempts in seconds.
8
- attr_accessor :interval
9
- LogStats.interval = 10
5
+ module Puma
6
+ module LogStats
7
+ class << self
8
+ # Interval between logging attempts in seconds.
9
+ attr_accessor :interval
10
+ LogStats.interval = 10
10
11
 
11
- attr_accessor :notify_change_with
12
- LogStats.notify_change_with = :sentry
12
+ attr_accessor :notify_change_with
13
+ LogStats.notify_change_with = :sentry
13
14
 
14
- attr_accessor :warning_threshold
15
- LogStats.warning_threshold = 0.7
15
+ attr_accessor :warning_threshold
16
+ LogStats.warning_threshold = 0.7
16
17
 
17
- attr_accessor :critical_threshold
18
- LogStats.critical_threshold = 0.85
19
- end
18
+ attr_accessor :critical_threshold
19
+ LogStats.critical_threshold = 0.85
20
+ end
20
21
 
21
- def start(launcher)
22
- @launcher = launcher
23
- launcher.events.register(:state) do |state|
24
- if %i[halt restart stop].include?(state)
25
- @running = false
22
+ def start(launcher)
23
+ @launcher = launcher
24
+ launcher.events.register(:state) do |state|
25
+ if %i[halt restart stop].include?(state)
26
+ @running = false
27
+ end
26
28
  end
27
- end
28
29
 
29
- in_background do
30
- @running = true
31
- @load_level = :normal
32
- while @running
33
- sleep LogStats.interval
34
- @previous_status_message = @status_message
35
- @stats = Puma.stats_hash
36
- @status_message = status_message
37
- log(@status_message) if @previous_status_message != @status_message
38
- check_alarms
30
+ in_background do
31
+ @running = true
32
+ @load_level = :normal
33
+ while @running
34
+ sleep LogStats.interval
35
+ @previous_status_message = @status_message
36
+ @stats = Puma.stats_hash
37
+ @status_message = status_message
38
+ log(@status_message) if @previous_status_message != @status_message
39
+ check_alarms
40
+ end
39
41
  end
40
42
  end
41
- end
42
43
 
43
- def check_alarms
44
- threshold_reached(:critical, LogStats.critical_threshold) ||
45
- threshold_reached(:warning, LogStats.warning_threshold) ||
46
- normal_load
47
- end
44
+ def check_alarms
45
+ threshold_reached(:critical, LogStats.critical_threshold) ||
46
+ threshold_reached(:warning, LogStats.warning_threshold) ||
47
+ normal_load
48
+ end
48
49
 
49
- def threshold_reached(level, threshold)
50
- return false if threads_load < threshold
50
+ def threshold_reached(level, threshold)
51
+ return false if threads_load < threshold
51
52
 
52
- change_level(level, "Puma threads load is greater than #{threshold * 100}% (#{max_threads - pool_capacity}/#{max_threads})")
53
- true
54
- end
53
+ change_level(level, "Puma threads load is greater than #{threshold * 100}% (#{max_threads - pool_capacity}/#{max_threads})")
54
+ true
55
+ end
55
56
 
56
- def normal_load
57
- change_level(:normal, "Puma threads load is back to normal values")
58
- end
57
+ def normal_load
58
+ change_level(:normal, "Puma threads load is back to normal values")
59
+ end
59
60
 
60
- def change_level(level, message)
61
- return if @load_level == level
61
+ def change_level(level, message)
62
+ return if @load_level == level
62
63
 
63
- log("#{level.to_s.upcase}: #{message}")
64
- notify(level, message)
65
- @load_level = level
66
- end
64
+ log("#{level.to_s.upcase}: #{message}")
65
+ notify(level, message)
66
+ @load_level = level
67
+ end
67
68
 
68
- def notify(level, message)
69
- if LogStats.notify_change_with == :sentry
70
- Sentry.capture_message(message, level: level == :critical ? :error : level) if defined?(Sentry) && level != :normal
71
- elsif LogStats.notify_change_with.respond_to?(:call)
72
- LogStats.notify_change_with.call(level: level, message: message, threads_load: threads_load)
69
+ def notify(level, message)
70
+ if LogStats.notify_change_with == :sentry
71
+ Sentry.capture_message(message, level: (level == :critical) ? :error : level) if defined?(Sentry) && level != :normal
72
+ elsif LogStats.notify_change_with.respond_to?(:call)
73
+ LogStats.notify_change_with.call(level: level, message: message, threads_load: threads_load)
74
+ end
73
75
  end
74
- end
75
76
 
76
- def status_message
77
- if clustered?
78
- "cluster: #{booted_workers}/#{workers} workers: #{running}/#{max_threads} threads, #{pool_capacity} available, #{backlog} backlog"
79
- else
80
- "single: #{running}/#{max_threads} threads, #{pool_capacity} available, #{backlog} backlog"
77
+ def status_message
78
+ if clustered?
79
+ "cluster: #{booted_workers}/#{workers} workers: #{running}/#{max_threads} threads, #{pool_capacity} available, #{backlog} backlog"
80
+ else
81
+ "single: #{running}/#{max_threads} threads, #{pool_capacity} available, #{backlog} backlog"
82
+ end
81
83
  end
82
- end
83
84
 
84
- def log(str)
85
- @launcher.log_writer.log("[#{Time.now}][puma #{Puma::Const::VERSION}] #{str}")
86
- end
85
+ def log(str)
86
+ @launcher.log_writer.log("[#{Time.now}][puma #{Puma::Const::VERSION}] #{str}")
87
+ end
87
88
 
88
- def threads_load
89
- 1.0 - pool_capacity.to_f / max_threads.to_f
90
- end
89
+ def threads_load
90
+ 1.0 - pool_capacity.to_f / max_threads.to_f
91
+ end
91
92
 
92
- def clustered?
93
- @stats.key?(:workers)
94
- end
93
+ def clustered?
94
+ @stats.key?(:workers)
95
+ end
95
96
 
96
- def workers
97
- @stats.fetch(:workers, 1)
98
- end
97
+ def workers
98
+ @stats.fetch(:workers, 1)
99
+ end
99
100
 
100
- def booted_workers
101
- @stats.fetch(:booted_workers, 1)
102
- end
101
+ def booted_workers
102
+ @stats.fetch(:booted_workers, 1)
103
+ end
103
104
 
104
- def running
105
- if clustered?
106
- @stats[:worker_status].sum { |s| s[:last_status].fetch(:running, 0) }
107
- else
108
- @stats.fetch(:running, 0)
105
+ def running
106
+ if clustered?
107
+ @stats[:worker_status].sum { |s| s[:last_status].fetch(:running, 0) }
108
+ else
109
+ @stats.fetch(:running, 0)
110
+ end
109
111
  end
110
- end
111
112
 
112
- def backlog
113
- if clustered?
114
- @stats[:worker_status].sum { |s| s[:last_status].fetch(:backlog, 0) }
115
- else
116
- @stats.fetch(:backlog, 0)
113
+ def backlog
114
+ if clustered?
115
+ @stats[:worker_status].sum { |s| s[:last_status].fetch(:backlog, 0) }
116
+ else
117
+ @stats.fetch(:backlog, 0)
118
+ end
117
119
  end
118
- end
119
120
 
120
- def pool_capacity
121
- if clustered?
122
- @stats[:worker_status].sum { |s| s[:last_status].fetch(:pool_capacity, 0) }
123
- else
124
- @stats.fetch(:pool_capacity, 0)
121
+ def pool_capacity
122
+ if clustered?
123
+ @stats[:worker_status].sum { |s| s[:last_status].fetch(:pool_capacity, 0) }
124
+ else
125
+ @stats.fetch(:pool_capacity, 0)
126
+ end
125
127
  end
126
- end
127
128
 
128
- def max_threads
129
- if clustered?
130
- @stats[:worker_status].sum { |s| s[:last_status].fetch(:max_threads, 0) }
131
- else
132
- @stats.fetch(:max_threads, 0)
129
+ def max_threads
130
+ if clustered?
131
+ @stats[:worker_status].sum { |s| s[:last_status].fetch(:max_threads, 0) }
132
+ else
133
+ @stats.fetch(:max_threads, 0)
134
+ end
133
135
  end
134
136
  end
135
137
  end
136
138
 
137
139
  Puma::Plugin.create do
138
- include LogStats
140
+ include Puma::LogStats
139
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puma-log_stats-codeur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Jordan