Module: Barnes

Defined in:
lib/barnes.rb,
lib/barnes/panel.rb,
lib/barnes/consts.rb,
lib/barnes/railtie.rb,
lib/barnes/version.rb,
lib/barnes/periodic.rb,
lib/barnes/reporter.rb,
lib/barnes/resource_usage.rb,
lib/barnes/instruments/ruby_gc.rb,
lib/barnes/instruments/stopwatch.rb,
lib/barnes/instruments/puma_instrument.rb,
lib/barnes/instruments/puma_stats_value.rb,
lib/barnes/instruments/object_space_counter.rb

Overview

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION

CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION

WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Instruments Classes: Panel, Periodic, Railtie, Reporter, ResourceUsage

Constant Summary collapse

DEFAULT_INTERVAL =
10
DEFAULT_PANELS =
[].freeze
VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.debug(message) ⇒ Object



71
72
73
74
75
# File 'lib/barnes.rb', line 71

def self.debug(message)
  if ENV["BARNES_DEBUG"]
    puts "Barnes: #{message}"
  end
end

.start(interval: DEFAULT_INTERVAL, panels: DEFAULT_PANELS) ⇒ Object

Starts the metrics reporting client.

Collects Ruby runtime metrics (GC stats, ObjectSpace counts, Puma pool stats) and POSTs them to HEROKU_METRICS_URL.

Arguments:

- interval: How often, in seconds, to instrument and report.
- panels: The instrumentation "panels" in use. See `resource_usage.rb` for
  an example panel, which is the default if none are provided.


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/barnes.rb', line 41

def self.start(interval: DEFAULT_INTERVAL, panels: DEFAULT_PANELS)
  return if ENV["DYNO"]&.start_with?("run.")

  url = ENV["HEROKU_METRICS_URL"]
  return unless url

  @mutex.synchronize do
    reporter = Barnes::Reporter.new(url: url)

    panels = panels.dup
    if panels.empty?
      panels << Barnes::ResourceUsage.new
    end

    if @periodic
      debug("Restarting Barnes. Previously started by caller:")
      debug(@caller.join("\n"))
      @periodic.stop(wait: false)
    end

    @caller = caller
    @periodic = Periodic.new(
      reporter: reporter,
      interval: interval,
      panels:   panels,
      debug:    ENV['BARNES_DEBUG']
    )
  end
end