The project is in a healthy, maintained state
Thread-safe instrumentation for background jobs. Record execution duration and success/failure, compute percentiles (p50, p95, p99), and identify slowest or most-failing job classes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

philiprehberger-job_meter

Gem Version CI License

Framework-agnostic background job instrumentation and metrics for Ruby

Requirements

  • Ruby >= 3.1

Installation

Add to your Gemfile:

gem 'philiprehberger-job_meter'

Or install directly:

gem install philiprehberger-job_meter

Usage

require 'philiprehberger/job_meter'

# Record job executions
Philiprehberger::JobMeter.record('SendEmailJob', duration: 1.23, success: true)
Philiprehberger::JobMeter.record('SendEmailJob', duration: 0.87, success: false)
Philiprehberger::JobMeter.record('ImportCsvJob', duration: 45.6, success: true)

# Get stats for a specific job class
stats = Philiprehberger::JobMeter.stats('SendEmailJob')
# => { avg_duration: 1.05, p50_duration: ..., p95_duration: ...,
#      p99_duration: ..., success_rate: 0.5, total: 2, failed: 1 }

# Find slowest jobs by average duration
Philiprehberger::JobMeter.top_slowest(5)
# => [{ job_class: 'ImportCsvJob', avg_duration: 45.6, ... }, ...]

# Find jobs with highest failure rates
Philiprehberger::JobMeter.top_failing(5)
# => [{ job_class: 'SendEmailJob', success_rate: 0.5, ... }, ...]

# Clear all recorded metrics
Philiprehberger::JobMeter.reset!

API

JobMeter.record(job_class, duration:, success:)

Record a single job execution. duration is in seconds (Float). success is a boolean.

JobMeter.stats(job_class)

Returns a hash with :avg_duration, :p50_duration, :p95_duration, :p99_duration, :success_rate, :total, and :failed. Returns nil if the job class has no recorded data.

JobMeter.top_slowest(num = 5)

Returns an array of hashes for the slowest job classes by average duration, sorted descending.

JobMeter.top_failing(num = 5)

Returns an array of hashes for job classes with the lowest success rate, sorted ascending.

JobMeter.reset!

Clears all recorded metrics.

Development

bundle install
bundle exec rspec
bundle exec rubocop

License

MIT