Slide 1

Slide 1 text

STORES 株式会社 Visualize the internal state of Ruby processes in Real-Time @hogelog (Sunao Komuro) RubyKaigi 2024 Lightning Talk STORES, Inc.

Slide 2

Slide 2 text

Who is hogelog? 2 - @hogelog (GitHub, Twitter, …) - 小室 直 (Sunao Komuro) - Software Engineer at STORES, Inc. - I like Ruby and programming

Slide 3

Slide 3 text

What I created

Slide 4

Slide 4 text

metrics_monitor gem 4 - https://github.com/hogelog/metrics_monitor - Visualize internal state of a Ruby program - mm

Slide 5

Slide 5 text

Why I created metrics_monitor 5 - There are some Ruby programs out there with issues - CPU, Memory, ... - Some I wrote myself, and some that were already around - Everyone wants to solve problems

Slide 6

Slide 6 text

Finding Ruby program issues 6 - Profiler? - pf2, ruby-prof, stackprof, memory_profiler, … excellent! - APM? - Datadog, Scout APM, … great! - But, I wanted an easier way to observe

Slide 7

Slide 7 text

My true trigger 7 - Frankly, I wanted VisualVM for Ruby - https://visualvm.github.io/ -

Slide 8

Slide 8 text

Let’s demo 8 str = "foobar" 10.times do str = str*8 sleep 3 end

Slide 9

Slide 9 text

9

Slide 10

Slide 10 text

How to create

Slide 11

Slide 11 text

Ruby Program Child Process Main Process metrics_monitor metrics_monitor components 11 - Components: Collector, Visualizer Visualizer Main Collector Collector Child Collector … … Pipe Target Program HTTP

Slide 12

Slide 12 text

Custom Collector 12 class RandomCollector < MetricsMonitor::Collector::CollectorBase def self.default_options = { enabled: true, interval: 5_000 } def meta_data = { title: "Random", monitors: [{ key: :random, title: "Random values", type: :chart, mode: :line }], data: { random: { mode: "append" } }, } def data = { random: rand } end

Slide 13

Slide 13 text

Built-in Collectors: BasicCollector 13 - Basic metrics collector like cpu, memory and etc

Slide 14

Slide 14 text

Built-in Collectors: GcStatCollector 14 - Garbage collection statistics collector

Slide 15

Slide 15 text

Built-in Collectors: ObjectStatCollector 15 - Object statistics collector

Slide 16

Slide 16 text

Built-in Collectors: ObjectTraceCollector 16 - Object tracing data collector

Slide 17

Slide 17 text

Conclusion

Slide 18

Slide 18 text

Summary 18 - I created metrics_monitor gem - Plug in and visualize program's internal state - Set up a simple collector to interactively visualize - More casual research options before serious analysis - Happy ruby programming, profiling, monitoring, analysis!

Slide 19

Slide 19 text

Future work 19 - Attaching without `require` - More extensive visualizer - Improving the overloaded collectors - Dynamically configure collectors from the view - Overall improvements