-
Notifications
You must be signed in to change notification settings - Fork 27
/
parser.rb
69 lines (60 loc) · 2.33 KB
/
parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
require 'prometheus/client'
module Puma
module Metrics
class Parser
def initialize(clustered: false)
register_default_metrics
register_clustered_metrics if clustered
end
def parse(symbol_keyed_stats, labels = {})
symbol_keyed_stats.each do |key, value|
value.each { |s| parse(s, labels.merge(index: s[:index])) } if key == :worker_status
parse(value, labels) if key == :last_status
update_metric(key, value, labels)
end
end
private
def register_clustered_metrics
registry.gauge(:puma_booted_workers,
docstring: 'Number of booted workers')
.set(1)
registry.gauge(:puma_old_workers,
docstring: 'Number of old workers')
.set(0)
end
def register_default_metrics # rubocop:disable Metrics/MethodLength
registry.gauge(:puma_backlog,
docstring: 'Number of established but unaccepted connections in the backlog',
labels: [:index],
preset_labels: { index: 0 })
registry.gauge(:puma_running,
docstring: 'Number of running worker threads',
labels: [:index],
preset_labels: { index: 0 })
registry.gauge(:puma_pool_capacity,
docstring: 'Number of allocatable worker threads',
labels: [:index],
preset_labels: { index: 0 })
registry.gauge(:puma_max_threads,
docstring: 'Maximum number of worker threads',
labels: [:index],
preset_labels: { index: 0 })
registry.gauge(:puma_requests_count,
docstring: 'Number of processed requests',
labels: [:index],
preset_labels: { index: 0 })
registry.gauge(:puma_workers,
docstring: 'Number of configured workers')
.set(1)
end
def registry
Prometheus::Client.registry
end
def update_metric(key, value, labels)
return if registry.get("puma_#{key}").nil?
registry.get("puma_#{key}").set(value, labels: labels)
end
end
end
end