blob: ce99b68464e4f76ac4c36ffd2c5dc950acde9548 (
plain)
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
|
# frozen_string_literal: true
module Gitlab
module Memory
class Watchdog
module Monitor
# A monitor that observes Ruby heap fragmentation.
# See Gitlab::Metrics::Memory for how heap fragmentation is defined.
class HeapFragmentation
attr_reader :max_heap_fragmentation
# max_heap_fragmentation:
# The degree to which the Ruby heap is allowed to be fragmented. Range [0,1].
def initialize(max_heap_fragmentation:)
@max_heap_fragmentation = max_heap_fragmentation
init_frag_limit_metrics
end
def call
heap_fragmentation = Gitlab::Metrics::Memory.gc_heap_fragmentation
return { threshold_violated: false, payload: {} } if heap_fragmentation <= max_heap_fragmentation
{ threshold_violated: true, payload: payload(heap_fragmentation) }
end
private
def payload(heap_fragmentation)
{
message: 'heap fragmentation limit exceeded',
memwd_cur_heap_frag: heap_fragmentation,
memwd_max_heap_frag: max_heap_fragmentation
}
end
def init_frag_limit_metrics
heap_frag_limit = Gitlab::Metrics.gauge(
:gitlab_memwd_heap_frag_limit,
'The configured limit for how fragmented the Ruby heap is allowed to be'
)
heap_frag_limit.set({}, max_heap_fragmentation)
end
end
end
end
end
end
|