Class: NullStatsd::Statsd

Inherits:
Object
  • Object
show all
Defined in:
lib/null_statsd/statsd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, logger:) ⇒ Statsd

Returns a new instance of Statsd.



7
8
9
10
11
12
13
# File 'lib/null_statsd/statsd.rb', line 7

def initialize(host:, port:, logger:)
  @host = host
  @port = port
  @namespace = ""
  @logger = logger
  notify "Connecting to fake Statsd, pretending to be on #{host}:#{port}"
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/null_statsd/statsd.rb', line 5

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/null_statsd/statsd.rb', line 5

def logger
  @logger
end

#namespaceObject

Returns the value of attribute namespace.



5
6
7
# File 'lib/null_statsd/statsd.rb', line 5

def namespace
  @namespace
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/null_statsd/statsd.rb', line 5

def port
  @port
end

Instance Method Details

#batch {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



55
56
57
# File 'lib/null_statsd/statsd.rb', line 55

def batch
  yield self
end

#closeObject



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

def close
  notify "Close called"
end

#count(stat, count, opts = {}) ⇒ Object



23
24
25
# File 'lib/null_statsd/statsd.rb', line 23

def count(stat, count, opts = {})
  notify "Increasing #{stat} by #{count}#{opts_string(opts)}"
end

#decrement(stat, opts = {}) ⇒ Object



19
20
21
# File 'lib/null_statsd/statsd.rb', line 19

def decrement(stat, opts = {})
  notify "Decrementing #{stat}#{opts_string(opts)}"
end

#event(title, text, opts = {}) ⇒ Object



47
48
49
# File 'lib/null_statsd/statsd.rb', line 47

def event(title, text, opts = {})
  notify "Event #{title}: #{text}#{opts_string(opts)}"
end

#gauge(stat, value, opts = {}) ⇒ Object



27
28
29
# File 'lib/null_statsd/statsd.rb', line 27

def gauge(stat, value, opts = {})
  notify "Setting gauge #{stat} to #{value}#{opts_string(opts)}"
end

#histogram(stat, value, opts = {}) ⇒ Object



31
32
33
# File 'lib/null_statsd/statsd.rb', line 31

def histogram(stat, value, opts = {})
  notify "Logging histogram #{stat} -> #{value}#{opts_string(opts)}"
end

#increment(stat, opts = {}) ⇒ Object



15
16
17
# File 'lib/null_statsd/statsd.rb', line 15

def increment(stat, opts = {})
  notify "Incrementing #{stat}#{opts_string(opts)}"
end

#service_check(name, status, opts = {}) ⇒ Object



43
44
45
# File 'lib/null_statsd/statsd.rb', line 43

def service_check(name, status, opts = {})
  notify "Service check #{name}: #{status}#{opts_string(opts)}"
end

#set(stat, value, opts = {}) ⇒ Object



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

def set(stat, value, opts = {})
  notify "Setting #{stat} to #{value}#{opts_string(opts)}"
end

#time(stat, opts = {}) ⇒ Object



59
60
61
62
63
# File 'lib/null_statsd/statsd.rb', line 59

def time(stat, opts = {})
  time_in_sec, result = benchmark { yield }
  notify "Recording timing info in #{stat} -> #{time_in_sec} sec#{opts_string(opts)}"
  result
end

#timing(stat, ms, _sample_rate = 1, opts = {}) ⇒ Object



35
36
37
# File 'lib/null_statsd/statsd.rb', line 35

def timing(stat, ms, _sample_rate = 1, opts = {})
  notify "Timing #{stat} at #{ms} ms#{opts_string(opts)}"
end

#with_namespace(namespace) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/null_statsd/statsd.rb', line 65

def with_namespace(namespace)
  new_ns = dup
  if @namespace == "" || @namespace == nil
    new_ns.namespace = namespace
  else
    new_ns.namespace = "#{@namespace}.#{namespace}"
  end
  if block_given?
    yield new_ns
  else
    new_ns
  end
end