Module: Metrica

Defined in:
lib/metrica.rb,
lib/metrica/version.rb,
lib/metrica/reporter.rb,
lib/metrica/transaction.rb,
lib/metrica/rails/railtie.rb,
lib/metrica/rack/middleware.rb,
lib/metrica/scheduled_reporter.rb,
lib/metrica/instrumentation/redis.rb,
lib/metrica/reporters/jmx_reporter.rb,
lib/metrica/method_instrumentation.rb,
lib/metrica/reporters/console_reporter.rb,
lib/metrica/reporters/opentsdb_reporter.rb,
lib/metrica/reporters/graphite_reporter.rb,
lib/metrica/instrumentation/active_record.rb,
lib/metrica/instrumentation/action_controller.rb

Defined Under Namespace

Modules: Instrumentation, MethodInstrumentation, Rack, Rails, Reporters, Transaction Classes: Configuration, Reporter, ScheduledReporter

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configMetrica::Configuration (readonly)

Returns the configuration object.

Returns:


45
46
47
# File 'lib/metrica.rb', line 45

def config
  @config
end

.configurationMetrica::Configuration (readonly)

Returns the configuration object.

Returns:


45
# File 'lib/metrica.rb', line 45

attr_reader :config

.registrycom.codahale.metrics.MetricRegistry (readonly)

Returns the central metrics registry.

Returns:

  • (com.codahale.metrics.MetricRegistry)

    The central metrics registry.


39
40
41
# File 'lib/metrica.rb', line 39

def registry
  @registry
end

Class Method Details

.configure {|config| ... } ⇒ Object

Allows you to configure Metrica.

Yield Parameters:


115
116
117
# File 'lib/metrica.rb', line 115

def configure
  yield @config if block_given?
end

.counter(name) ⇒ com.codahale.metrics.Counter

Creates a new counter with the specified name.

Parameters:

  • name (String)

    The name of the counter.

Returns:

  • (com.codahale.metrics.Counter)

See Also:


60
61
62
# File 'lib/metrica.rb', line 60

def counter(name)
  @registry.counter(name)
end

.fetch(name) ⇒ com.codahale.metrics.Metric

Returns a metric registered with the given name, or nil.

Parameters:

  • name (String)

    The name of the metric.

Returns:

  • (com.codahale.metrics.Metric)

51
52
53
# File 'lib/metrica.rb', line 51

def fetch(name)
  @registry.getMetrics.get(name)
end

.gauge(name, &block) ⇒ com.codahale.metrics.Gauge

Creates a new gauge with the specified name. The value returned by the block at any given time determines the value of the gauge.

Parameters:

  • name (String)

    The name of the gauge.

  • block (Proc)

    A block that determines the value of the gauge.

Returns:

  • (com.codahale.metrics.Gauge)

See Also:


71
72
73
# File 'lib/metrica.rb', line 71

def gauge(name, &block)
  @registry.register(name, block.to_java(com.codahale.metrics.Gauge))
end

.histogram(name) ⇒ com.codahale.metrics.Histogram

Creates a new histogram with the specified name.

Parameters:

  • name (String)

    The name of the histogram.

Returns:

  • (com.codahale.metrics.Histogram)

See Also:


80
81
82
# File 'lib/metrica.rb', line 80

def histogram(name)
  @registry.histogram(name)
end

.meter(name) ⇒ com.codahale.metrics.Meter

Returns a new meter with the specified name.

Parameters:

  • name (String)

    The name of the timer.

Returns:

  • (com.codahale.metrics.Meter)

See Also:


108
109
110
# File 'lib/metrica.rb', line 108

def meter(name)
  @registry.meter(name)
end

.register(name, metric) ⇒ Object

Adds a metric to the registry under the given name. Use this method if you need to customize the metric and can't use the default methods like Metrica.timer.

Parameters:

  • name (String)

    The name of the metric.

  • metric (com.codahale.metrics.Metric)

    The metric itself.


99
100
101
# File 'lib/metrica.rb', line 99

def register(name, metric)
  @registry.register(name, metric)
end

.startObject

Starts all configured Reporters. If you're using Rails, calling this method is not necessary as long as you've configured the environments correctly.


122
123
124
# File 'lib/metrica.rb', line 122

def start
  @config.reporters.each(&:start)
end

.stopObject

Stops all configured Reporters.


127
128
129
# File 'lib/metrica.rb', line 127

def stop
  @config.reporters.each(&:stop)
end

.timer(name) ⇒ com.codahale.metrics.Timer

Creates a new timer with the specified name.

Parameters:

  • name (String)

    The name of the timer.

Returns:

  • (com.codahale.metrics.Timer)

See Also:


89
90
91
# File 'lib/metrica.rb', line 89

def timer(name)
  @registry.timer(name)
end