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.
144 145 146 147 148 149 150 151 |
# File 'lib/statsd.rb', line 144 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.
127 128 129 |
# File 'lib/statsd.rb', line 127 def logger @logger end |
Instance Attribute Details
#host ⇒ Object
StatsD host. Defaults to 127.0.0.1.
120 121 122 |
# File 'lib/statsd.rb', line 120 def host @host end |
#host.=(value) ⇒ Object (writeonly)
Users should call connect after changing this.
132 133 134 |
# File 'lib/statsd.rb', line 132 def host=(host) @host = host || '127.0.0.1' end |
#port ⇒ Object
StatsD admin port. Defaults to 8126.
123 124 125 |
# File 'lib/statsd.rb', line 123 def port @port end |
#port.=(value) ⇒ Object (writeonly)
Users should call connect after changing this.
138 139 140 |
# File 'lib/statsd.rb', line 138 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)
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/statsd.rb', line 203 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.
164 165 166 |
# File 'lib/statsd.rb', line 164 def counters read_metric :counters end |
#delcounters(item) ⇒ Object
@param item
Deletes one or more counters. Wildcards are allowed.
182 183 184 |
# File 'lib/statsd.rb', line 182 def delcounters item delete_metric :counters, item end |
#delgauges(item) ⇒ Object
@param item
Deletes one or more gauges. Wildcards are allowed.
170 171 172 |
# File 'lib/statsd.rb', line 170 def delgauges item delete_metric :gauges, item end |
#deltimers(item) ⇒ Object
@param item
Deletes one or more timers. Wildcards are allowed.
176 177 178 |
# File 'lib/statsd.rb', line 176 def deltimers item delete_metric :timers, item end |
#gauges ⇒ Object
Reads all gauges from StatsD.
154 155 156 |
# File 'lib/statsd.rb', line 154 def gauges read_metric :gauges end |
#stats ⇒ Object
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/statsd.rb', line 186 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.
159 160 161 |
# File 'lib/statsd.rb', line 159 def timers read_metric :timers end |