Process::Metrics GuidesGetting Started

Getting Started

This guide explains how to use the process-metrics gem to collect and analyze process metrics including processor and memory utilization.

Installation

Add the gem to your project:

$ bundle add process-metrics

Or, if you prefer, install it globally:

$ gem install process-metrics

Core Concepts

The process-metrics gem provides a simple interface to collect and analyze process metrics.

Usage

To collect process metrics, use the Process::Metrics::General.capture method:

Process::Metrics::General.capture(pid: Process.pid)
# => 
# {3517456=>
#   #<struct Process::Metrics::General
#    pid=3517456,
#    ppid=3517432,
#    pgid=3517456,
#    processor_utilization=0.0,
#    vsz=0,
#    rss=486892,
#    time=29928,
#    etime=2593,
#    command="irb",
#    memory=
#     #<struct Process::Metrics::Memory
#      map_count=193,
#      total_size=486896,
#      resident_size=30556,
#      proportional_size=25672,
#      shared_clean_size=5008,
#      shared_dirty_size=0,
#      private_clean_size=5180,
#      private_dirty_size=20368,
#      referenced_size=30548,
#      anonymous_size=20376,
#      swap_size=0,
#      proportional_swap_size=0>>}

If you want to capture a tree of processes, you can specify the ppid: option instead.

Fields

The class Process::Metrics::General struct contains the following fields:

The class Process::Metrics::Memory struct contains the following fields:

In general, the interpretation of these fields is operating system specific. At best, they provide a rough estimate of the process's memory usage, but you should consult the documentation for your operating system for more details on exactly what each field represents.