This guide will demonstrate using the New Relic Ruby agent to report metrics for Sidekiq jobs being performed by workers. A minimal Ruby on Rails app with a minimal Sidekiq job class will be created.
required
- Ruby
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# A standalone example of using the New Relic Ruby agent's | |
# NewRelic::Agent.increment_metric public API | |
# | |
# INSTRUCTIONS: | |
# - Place this file somewhere. It can be called something like `increment.rb` | |
# | |
# - Either place a newrelic.yml file in the same directory as this file OR |
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# INSTRUCTIONS: | |
# - Place this file somewhere. It can be called something like `reporter.rb` | |
# | |
# - Either place a newrelic.yml file in the same directory as this file OR | |
# export the NEW_RELIC_LICENSE_KEY and NEW_RELIC_HOST environment variables. | |
# If using a newrelic.yml file, it should look like this: | |
# # newrelic.yml |
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'async', '~> 2.2' | |
end |
require 'zlib' | |
CHARACTERS = ['a'..'z', 'A'..'Z', 0..9].map(&:to_a).flatten.freeze | |
TRIES = 10_000 | |
BYTE_RANGE = 50..1000 | |
savings = TRIES.times.each_with_object([]) do |_, arr| | |
string = (0...rand(BYTE_RANGE)).map { CHARACTERS[rand(CHARACTERS.size)] }.join | |
gzipped = Zlib.gzip(string) | |
arr << (1 - gzipped.size.to_f / string.size) * 100 |
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# This standalone Ruby script is intended to demonstrate the use of the 'grpc' | |
# gem to establish a minimal unary rpc and spawn both a gRPC server and client | |
# and have them use gzip to compress content being sent to one another after | |
# the client requests the use of gzip at channel creation, stub creation, and | |
# call time. | |
# | |
# Instructions: |
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# encoding: utf-8 | |
require 'fileutils' | |
require 'nokogiri' | |
SOURCE_IMG_DIR = 'media/covers' | |
TARGET_IMG_DIR = 'Imgs' | |
UNUSED_ELEMENTS = %w[desc developer genre kidgame marquee players rating releasedate publisher video] |
standalone.rb
file to your computer. Place it in an empty directory by itself. The file does not need to be made executable. The first "shebang" line of the file will be ignored, so the path is not important.newrelic.yml
file or copy an existing one from an existing project to the directory containing standalone.rb
ruby standalone.rb
Starting New Relic agent...
Waiting for New Relic agent to connect...
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# The New Relic Ruby agent can be instructed to manually notice an error by | |
# using the public NewRelic::Agent.notice_error method. | |
# | |
# NewRelic::Agent.notice_error does not require that a New Relic Ruby agent | |
# transaction exist. It simply requires that the New Relic Ruby agent be | |
# connected, which itself requires the use of a valid license key. | |
# |
The New Relic Ruby agent has instrumentation support for the redis Rubygem.
By default, the agent will instrument redis
in "auto" mode and automatically decide whether to use method prepending or method chaining. The "auto" mode will opt for the use of method prepending unless it detects a condition known to cause a conflict. To explicitly use "chain" mode to force method chaining, the newrelic.yml
configuration file can be given the following entry:
instrumentation.redis: chain