Skip to content

Commit

Permalink
Reorganizing code
Browse files Browse the repository at this point in the history
Also adds a #restart method to reporters to restart the reporter thread.
  • Loading branch information
eric committed Mar 4, 2012
1 parent 4225435 commit 44b6c23
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
13 changes: 10 additions & 3 deletions lib/metriks/reporter/graphite.rb
Expand Up @@ -2,9 +2,11 @@
module Metriks::Reporter
class Graphite
def initialize(host, port, options = {})
@host = host
@port = port
@prefix = options[:prefix]
@host = host
@port = port

@prefix = options[:prefix]

@registry = options[:registry] || Metriks::Registry.default
@interval = options[:interval] || 60
@on_errror = options[:on_error] || proc { |ex| }
Expand Down Expand Up @@ -36,6 +38,11 @@ def stop
@thread = nil
end

def restart
stop
start
end

def write
@registry.each do |name, metric|
case metric
Expand Down
15 changes: 11 additions & 4 deletions lib/metriks/reporter/librato_metrics.rb
Expand Up @@ -19,13 +19,15 @@ def self.connection


def initialize(email, token, options = {})
@email = email
@token = token
@prefix = options[:prefix]
@email = email
@token = token

@prefix = options[:prefix]
@source = options[:source]

@registry = options[:registry] || Metriks::Registry.default
@interval = options[:interval] || 60
@on_errror = options[:on_error] || proc { |ex| }
@source = options[:source]
end

def start
Expand All @@ -49,6 +51,11 @@ def stop
@thread = nil
end

def restart
stop
start
end

def write
gauges = []
@registry.each do |name, metric|
Expand Down
12 changes: 9 additions & 3 deletions lib/metriks/reporter/logger.rb
Expand Up @@ -3,12 +3,13 @@
module Metriks::Reporter
class Logger
def initialize(options = {})
@registry = options[:registry] || Metriks::Registry.default
@logger = options[:logger] || ::Logger.new(STDOUT)
@log_level = options[:log_level] || ::Logger::INFO
@prefix = options[:prefix] || 'metriks:'
@interval = options[:interval] || 60
@on_errror = options[:on_error] || proc { |ex| }

@registry = options[:registry] || Metriks::Registry.default
@interval = options[:interval] || 60
@on_errror = options[:on_error] || proc { |ex| }
end

def start
Expand All @@ -32,6 +33,11 @@ def stop
@thread = nil
end

def restart
stop
start
end

def write
@registry.each do |name, metric|
case metric
Expand Down
10 changes: 8 additions & 2 deletions lib/metriks/reporter/proc_title.rb
@@ -1,11 +1,12 @@
module Metriks::Reporter
class ProcTitle
def initialize(options = {})
@rounding = options[:rounding] || 1
@prefix = options[:prefix] || $0.dup

@interval = options[:interval] || 5
@rounding = options[:rounding] || 1
@on_errror = options[:on_error] || proc { |ex| }

@prefix = $0.dup
@metrics = []
end

Expand Down Expand Up @@ -40,6 +41,11 @@ def stop
@thread = nil
end

def restart
stop
start
end

protected
def generate_title
@metrics.collect do |name, suffix, block|
Expand Down

0 comments on commit 44b6c23

Please sign in to comment.