module EducationStats

Constants

HOSTED_GRAPHITE_HOST
HOSTED_GRAPHITE_PORT
VERSION

Attributes

hosted_graphite_api_key[RW]
hosted_graphite_namespace[RW]
use_hosted_graphite[W]

Public Class Methods

add_statsd_client(statsd_client) click to toggle source

Public: Add an instance of Statsd::Client to report to.

# File lib/education_stats.rb, line 41
def add_statsd_client(statsd_client)
  statsd_clients << statsd_client
end
all_clients() click to toggle source

Public: Get all the configured Statsd clients that will be reported to.

Returns an array of Statsd client classes

# File lib/education_stats.rb, line 48
def all_clients
  @all_clients ||= if use_hosted_graphite
    statsd_clients.push(build_hosted_graphite_statsd_client)
  else
    statsd_clients
  end
end
client() click to toggle source

Public: Get the configured EducationStats client. This acts as a single Statd client, but will forward all commands to the internal clients.

Example

client = EducationStats.client
client.increment 'education.mymetric'

Returns a configured instance of EducationStats::Client

# File lib/education_stats.rb, line 36
def client
  EducationStats::Client.new(all_clients)
end
configure() { |self| ... } click to toggle source

Public: Configuration for EducationStats

Example

EducationStats.configure do |config|
  config.hosted_graphite_api_key = 'abc123'
end

Yields self for configuring options

# File lib/education_stats.rb, line 23
def configure
  yield self
end
reset() click to toggle source

Public: returns EducationStats to its original unconfigured state

Returns an unconfigured EducationStats class

# File lib/education_stats.rb, line 66
def reset
  @hosted_graphite_api_key = nil
  @hosted_graphite_namespace = nil
  @use_hosted_graphite = nil
  @all_clients = nil
  @statsd_clients = nil
  self
end
use_hosted_graphite() click to toggle source

Public: should EducationStats use a HostedGraphite Statsd

Returns a Boolean

# File lib/education_stats.rb, line 59
def use_hosted_graphite
  @use_hosted_graphite ||= !!hosted_graphite_api_key
end

Private Class Methods

build_hosted_graphite_statsd_client() click to toggle source

Internal: Builds an Statsd client for HostedGraphite.

Returns a Statsd class configured for HostedGraphite

# File lib/education_stats.rb, line 86
def build_hosted_graphite_statsd_client
  Statsd.new(HOSTED_GRAPHITE_HOST, HOSTED_GRAPHITE_PORT).tap do |statsd|
    statsd.namespace = [
      hosted_graphite_api_key, @hosted_graphite_namespace
    ].compact.join('.')
  end
end
statsd_clients() click to toggle source

Internal: Returns an array of manually added clients.

Returns an array of Statsd client classes

# File lib/education_stats.rb, line 79
def statsd_clients
  @statsd_clients ||= []
end