Skip to content

Commit

Permalink
Refactor gauge calls to helper method in MRI probe
Browse files Browse the repository at this point in the history
Call a private method that calls `Appsignal.set_guage` so that if we
want to change some defaults in metrics reported by this probe we only
have to do it in one place. Like adding a hostname tag.
  • Loading branch information
tombruijn committed Jul 28, 2022
1 parent e225c79 commit 33b1cef
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions lib/appsignal/probes/mri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,48 @@ def initialize(appsignal = Appsignal)
def call
stat = RubyVM.stat

@appsignal.set_gauge(
set_gauge(
"ruby_vm",
stat[:class_serial],
:metric => :class_serial
)

@appsignal.set_gauge(
set_gauge(
"ruby_vm",
stat[:constant_cache] ? stat[:constant_cache].values.sum : stat[:global_constant_state],
:metric => :global_constant_state
)

@appsignal.set_gauge("thread_count", Thread.list.size)
@appsignal.set_gauge("gc_total_time", MriProbe.garbage_collection_profiler.total_time)
set_gauge("thread_count", Thread.list.size)
set_gauge("gc_total_time", MriProbe.garbage_collection_profiler.total_time)

gc_stats = GC.stat
allocated_objects =
gauge_delta(
:allocated_objects,
gc_stats[:total_allocated_objects] || gc_stats[:total_allocated_object]
)
if allocated_objects
@appsignal.set_gauge("allocated_objects", allocated_objects)
end
set_gauge("allocated_objects", allocated_objects) if allocated_objects

gc_count = gauge_delta(:gc_count, GC.count)
if gc_count
@appsignal.set_gauge("gc_count", gc_count, :metric => :gc_count)
end
set_gauge("gc_count", gc_count, :metric => :gc_count) if gc_count
minor_gc_count = gauge_delta(:minor_gc_count, gc_stats[:minor_gc_count])
if minor_gc_count
@appsignal.set_gauge("gc_count", minor_gc_count, :metric => :minor_gc_count)
set_gauge("gc_count", minor_gc_count, :metric => :minor_gc_count)
end
major_gc_count = gauge_delta(:major_gc_count, gc_stats[:major_gc_count])
if major_gc_count
@appsignal.set_gauge("gc_count", major_gc_count, :metric => :major_gc_count)
set_gauge("gc_count", major_gc_count, :metric => :major_gc_count)
end

@appsignal.set_gauge("heap_slots", gc_stats[:heap_live_slots] || gc_stats[:heap_live_slot], :metric => :heap_live)
@appsignal.set_gauge("heap_slots", gc_stats[:heap_free_slots] || gc_stats[:heap_free_slot], :metric => :heap_free)
set_gauge("heap_slots", gc_stats[:heap_live_slots] || gc_stats[:heap_live_slot], :metric => :heap_live)
set_gauge("heap_slots", gc_stats[:heap_free_slots] || gc_stats[:heap_free_slot], :metric => :heap_free)
end

private

def set_gauge(metric, value, tags = {})
@appsignal.set_gauge(metric, value, tags)
end
end
end
Expand Down

0 comments on commit 33b1cef

Please sign in to comment.