Class: Statsd::Admin
- Inherits:
-
Object
- Object
- Statsd::Admin
- Defined in:
- lib/statsd.rb
Class Attribute Summary collapse
-
.logger ⇒ Object
Set to a standard logger instance to enable debug logging.
Instance Attribute Summary collapse
-
#host ⇒ Object
StatsD host.
-
#host.= ⇒ Object
writeonly
Users should call connect after changing this.
-
#port ⇒ Object
StatsD admin port.
-
#port.= ⇒ Object
writeonly
Users should call connect after changing this.
Instance Method Summary collapse
-
#connect ⇒ Object
Reconnects the socket, for when the statsd address may have changed.
-
#counters ⇒ Object
Reads all counters from StatsD.
-
#delcounters(item) ⇒ Object
@param item Deletes one or more counters.
-
#delgauges(item) ⇒ Object
@param item Deletes one or more gauges.
-
#deltimers(item) ⇒ Object
@param item Deletes one or more timers.
-
#gauges ⇒ Object
Reads all gauges from StatsD.
-
#initialize(host = '127.0.0.1', port = 8126) ⇒ Admin
constructor
A new instance of Admin.
- #stats ⇒ Object
-
#timers ⇒ Object
Reads all timers from StatsD.
Constructor Details
#initialize(host = '127.0.0.1', port = 8126) ⇒ Admin
Returns a new instance of Admin.
146 147 148 149 150 151 152 153 |
# File 'lib/statsd.rb', line 146 def initialize(host = '127.0.0.1', port = 8126) @host = host || '127.0.0.1' @port = port || 8126 # protects @socket transactions @socket = nil @s_mu = Mutex.new connect end |
Class Attribute Details
.logger ⇒ Object
Set to a standard logger instance to enable debug logging.
129 130 131 |
# File 'lib/statsd.rb', line 129 def logger @logger end |
Instance Attribute Details
#host ⇒ Object
StatsD host. Defaults to 127.0.0.1.
122 123 124 |
# File 'lib/statsd.rb', line 122 def host @host end |
#host.=(value) ⇒ Object (writeonly)
Users should call connect after changing this.
134 135 136 |
# File 'lib/statsd.rb', line 134 def host=(host) @host = host || '127.0.0.1' end |
#port ⇒ Object
StatsD admin port. Defaults to 8126.
125 126 127 |
# File 'lib/statsd.rb', line 125 def port @port end |
#port.=(value) ⇒ Object (writeonly)
Users should call connect after changing this.
140 141 142 |
# File 'lib/statsd.rb', line 140 def port=(port) @port = port || 8126 end |
Instance Method Details
#connect ⇒ Object
Reconnects the socket, for when the statsd address may have changed. Users do not normally need to call this, but calling it may be appropriate when reconfiguring a process (e.g. from HUP)
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/statsd.rb', line 205 def connect @s_mu.synchronize do begin @socket.flush rescue nil @socket.close if @socket rescue # Ignore socket errors on close. end @socket = TCPSocket.new(host, port) end end |
#counters ⇒ Object
Reads all counters from StatsD.
166 167 168 |
# File 'lib/statsd.rb', line 166 def counters read_metric :counters end |
#delcounters(item) ⇒ Object
@param item
Deletes one or more counters. Wildcards are allowed.
184 185 186 |
# File 'lib/statsd.rb', line 184 def delcounters item delete_metric :counters, item end |
#delgauges(item) ⇒ Object
@param item
Deletes one or more gauges. Wildcards are allowed.
172 173 174 |
# File 'lib/statsd.rb', line 172 def delgauges item delete_metric :gauges, item end |
#deltimers(item) ⇒ Object
@param item
Deletes one or more timers. Wildcards are allowed.
178 179 180 |
# File 'lib/statsd.rb', line 178 def deltimers item delete_metric :timers, item end |
#gauges ⇒ Object
Reads all gauges from StatsD.
156 157 158 |
# File 'lib/statsd.rb', line 156 def gauges read_metric :gauges end |
#stats ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/statsd.rb', line 188 def stats result = @s_mu.synchronize do # the format of "stats" isn't JSON, who knows why send_to_socket "stats" read_from_socket end items = {} result.split("\n").each do |line| key, val = line.chomp.split(": ") items[key] = val.to_i end items end |
#timers ⇒ Object
Reads all timers from StatsD.
161 162 163 |
# File 'lib/statsd.rb', line 161 def timers read_metric :timers end |