upfluence-utils 0.12.11 → 0.12.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/upfluence/http/server.rb +8 -0
- data/lib/upfluence/instrumentation/active_record_pool_instrumenter.rb +30 -0
- data/lib/upfluence/instrumentation/gc_instrumenter.rb +28 -0
- data/lib/upfluence/instrumentation/periodic_instrumenter.rb +61 -0
- data/lib/upfluence/instrumentation/puma_instrumenter.rb +33 -0
- data/lib/upfluence/instrumentation.rb +3 -0
- data/lib/upfluence/utils/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ddcbd6854f88cf5645e0295a48ac21f9aec1da81d71cf20d49214c61d57f8d9
|
4
|
+
data.tar.gz: 43907a8dc7d24c0609d914f46c8954dd67b6af664f474f26038ae5551eac6f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a54773f0b7123115b0139bb417972df0b47347e10b03bfa9299adfe6e9921166510328776863ea5850ad6f36a9102c84a58c55a3e23fe6ad758c169ce9066f8
|
7
|
+
data.tar.gz: 85b2ac6104fb0e8eeda611b6e7cc2027f24214e49e726e083b0ba111a237e8daade7ef18f40f256a03300cd21b80445989d674f5c8ca3ae9dfa5789b152b2447
|
@@ -18,6 +18,7 @@ require 'upfluence/http/middleware/handle_exception'
|
|
18
18
|
require 'upfluence/http/middleware/prometheus'
|
19
19
|
require 'upfluence/http/middleware/cors'
|
20
20
|
require 'upfluence/http/middleware/request_stapler'
|
21
|
+
require 'upfluence/instrumentation'
|
21
22
|
|
22
23
|
Rack::Timeout::Logger.disable
|
23
24
|
|
@@ -42,6 +43,11 @@ module Upfluence
|
|
42
43
|
max_threads: ENV.fetch('HTTP_SERVER_MAX_THREADS', 5).to_i,
|
43
44
|
request_timeout: ENV['HTTP_SERVER_REQUEST_TIMEOUT']&.to_i,
|
44
45
|
middlewares: [],
|
46
|
+
instrumentations: [
|
47
|
+
Instrumentation::PumaInstrumenter.new,
|
48
|
+
Instrumentation::GCInstrumenter.new,
|
49
|
+
Instrumentation::ActiveRecordPoolInstrumenter.new
|
50
|
+
],
|
45
51
|
debug: ENV.fetch('DEBUG', nil)
|
46
52
|
}
|
47
53
|
|
@@ -103,6 +109,8 @@ module Upfluence
|
|
103
109
|
|
104
110
|
Thread.new { run_prometheus_exporter } if @options[:push_gateway_url]
|
105
111
|
|
112
|
+
@options[:instrumentations].each(&:start)
|
113
|
+
|
106
114
|
@handler.run(@builder, **@options) do |server|
|
107
115
|
server.threaded = @options[:threaded] if server.respond_to? :threaded=
|
108
116
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'upfluence/instrumentation/periodic_instrumenter'
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module Upfluence
|
5
|
+
module Instrumentation
|
6
|
+
class ActiveRecordPoolInstrumenter < PeriodicInstrumenter
|
7
|
+
KEYS = %i[
|
8
|
+
size connections busy dead idle waiting
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
def prefix
|
12
|
+
'active_record_pool'
|
13
|
+
end
|
14
|
+
|
15
|
+
def metrics
|
16
|
+
KEYS.reduce({}) do |acc, k|
|
17
|
+
acc.merge(k => { docstring: "Gauge for #{k}" })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def values
|
22
|
+
return {} unless ActiveRecord::Base.connected?
|
23
|
+
|
24
|
+
ActiveRecord::Base.connection_pool.stat.slice(*KEYS).reduce({}) do |acc, (k, v)|
|
25
|
+
acc.merge(k => [{ value: v }])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'upfluence/instrumentation/periodic_instrumenter'
|
2
|
+
|
3
|
+
module Upfluence
|
4
|
+
module Instrumentation
|
5
|
+
class GCInstrumenter < PeriodicInstrumenter
|
6
|
+
KEYS = %i[
|
7
|
+
heap_live_slots heap_free_slots major_gc_count minor_gc_count
|
8
|
+
total_allocated_objects
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
def prefix
|
12
|
+
'ruby_gc'
|
13
|
+
end
|
14
|
+
|
15
|
+
def metrics
|
16
|
+
KEYS.reduce({}) do |acc, k|
|
17
|
+
acc.merge(k => { docstring: "Gauge for #{k}" })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def values
|
22
|
+
GC.stat.slice(*KEYS).reduce({}) do |acc, (k, v)|
|
23
|
+
acc.merge(k => [{ value: v }])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Upfluence
|
2
|
+
module Instrumentation
|
3
|
+
class PeriodicInstrumenter
|
4
|
+
def initialize(interval: 30, registry: ::Prometheus::Client.registry)
|
5
|
+
@interval = interval
|
6
|
+
@gauges = metrics.reduce({}) do |acc, (metric, values)|
|
7
|
+
metric_name = [prefix, metric].compact.join("_").to_sym
|
8
|
+
|
9
|
+
acc.merge(
|
10
|
+
metric => registry.get(metric_name) || registry.gauge(
|
11
|
+
metric_name,
|
12
|
+
docstring: values[:docstring] || '',
|
13
|
+
labels: values[:labels] || []
|
14
|
+
)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
@stop_thread = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def start
|
22
|
+
@thread ||= Thread.new do
|
23
|
+
until @stop_thread
|
24
|
+
begin
|
25
|
+
values.each do |(metric, vs)|
|
26
|
+
vs.each do |v|
|
27
|
+
@gauges[metric].set(v[:value], labels: v[:labels] || {})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue => e
|
31
|
+
Upfluence.error_logger.notify(e)
|
32
|
+
ensure
|
33
|
+
sleep @interval
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop
|
40
|
+
return unless @thread&.alive?
|
41
|
+
|
42
|
+
@stop_thread = true
|
43
|
+
@thread.wakeup
|
44
|
+
@thread.join
|
45
|
+
@thread = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def prefix
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def values
|
53
|
+
raise "Please implement a subcalss"
|
54
|
+
end
|
55
|
+
|
56
|
+
def metrics
|
57
|
+
raise "Please implement a subcalss"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'upfluence/instrumentation/periodic_instrumenter'
|
2
|
+
require 'puma'
|
3
|
+
|
4
|
+
module Upfluence
|
5
|
+
module Instrumentation
|
6
|
+
class PumaInstrumenter < PeriodicInstrumenter
|
7
|
+
KEYS = %i[backlog_thread running_thread pool_capacity requests_count].freeze
|
8
|
+
|
9
|
+
def prefix
|
10
|
+
'puma'
|
11
|
+
end
|
12
|
+
|
13
|
+
def metrics
|
14
|
+
KEYS.reduce({}) do |acc, k|
|
15
|
+
acc.merge(k => { docstring: "Gauge for #{k}" })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def values
|
20
|
+
stats = Puma.stats_hash
|
21
|
+
|
22
|
+
{
|
23
|
+
requests_count: [{ value: stats[:requests_count] }],
|
24
|
+
backlog_thread: [{ value: stats[:backlog] }],
|
25
|
+
running_thread: [{ value: stats[:running] }],
|
26
|
+
pool_capacity: [{ value: stats[:pool_capacity] }]
|
27
|
+
}
|
28
|
+
rescue NoMethodError
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upfluence-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Upfluence
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -283,6 +283,11 @@ files:
|
|
283
283
|
- lib/upfluence/http/middleware/prometheus.rb
|
284
284
|
- lib/upfluence/http/middleware/request_stapler.rb
|
285
285
|
- lib/upfluence/http/server.rb
|
286
|
+
- lib/upfluence/instrumentation.rb
|
287
|
+
- lib/upfluence/instrumentation/active_record_pool_instrumenter.rb
|
288
|
+
- lib/upfluence/instrumentation/gc_instrumenter.rb
|
289
|
+
- lib/upfluence/instrumentation/periodic_instrumenter.rb
|
290
|
+
- lib/upfluence/instrumentation/puma_instrumenter.rb
|
286
291
|
- lib/upfluence/logger.rb
|
287
292
|
- lib/upfluence/mixin/html_scrubbing.rb
|
288
293
|
- lib/upfluence/mixin/pagination.rb
|