Class: TwemproxyExporter::Twemproxy
- Inherits:
-
Object
- Object
- TwemproxyExporter::Twemproxy
- Defined in:
- lib/twemproxy_exporter/twemproxy.rb
Instance Attribute Summary collapse
-
#exporter ⇒ Object
readonly
Returns the value of attribute exporter.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(exporter, host = 'localhost', port = 22222) ⇒ Twemproxy
constructor
A new instance of Twemproxy.
- #stats ⇒ Object
Constructor Details
#initialize(exporter, host = 'localhost', port = 22222) ⇒ Twemproxy
Returns a new instance of Twemproxy.
10 11 12 13 14 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 10 def initialize(exporter, host = 'localhost', port = 22222) @exporter = exporter @host = host @port = port end |
Instance Attribute Details
#exporter ⇒ Object (readonly)
Returns the value of attribute exporter.
6 7 8 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 6 def exporter @exporter end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 8 def port @port end |
Instance Method Details
#count ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 16 def count stats = self.stats name = stats['source'] labels = {twemproxy: name} @exporter.total_connections.count stats['total_connections'], labels @exporter.curr_connections.count stats['curr_connections'], labels @exporter.uptime.count stats['uptime'], labels stats.each do |cluster, cinfo| next unless cinfo.is_a? Hash labels = {twemproxy: name, cluster: cluster} @exporter.fragments.count cinfo['fragments'], labels @exporter.forward_error.count cinfo['forward_error'], labels @exporter.server_ejects.count cinfo['server_ejects'], labels @exporter.client_connections.count cinfo['client_connections'], labels @exporter.client_err.count cinfo['client_err'], labels @exporter.client_eof.count cinfo['client_eof'], labels cinfo.each do |server, sinfo| next unless sinfo.is_a? Hash labels = {twemproxy: name, cluster: cluster, server: server} @exporter.in_queue.count sinfo['in_queue'], labels @exporter.in_queue_bytes.count sinfo['in_queue_bytes'], labels @exporter.out_queue.count sinfo['out_queue'], labels @exporter.out_queue_bytes.count sinfo['out_queue_bytes'], labels @exporter.request_bytes.count sinfo['request_bytes'], labels @exporter.requests.count sinfo['requests'], labels @exporter.response_bytes.count sinfo['response_bytes'], labels @exporter.responses.count sinfo['responses'], labels @exporter.server_connections.count sinfo['server_connections'], labels @exporter.server_ejected_at.count sinfo['server_ejected_at'], labels @exporter.server_eof.count sinfo['server_eof'], labels @exporter.server_err.count sinfo['server_err'], labels @exporter.server_timedout.count sinfo['server_timedout'], labels end end rescue StandardError => e warn e end |
#stats ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/twemproxy_exporter/twemproxy.rb', line 59 def stats socket = TCPSocket.new(@host, @port) return YAML.load(socket.read) if select([socket], nil, nil, @exporter.timeout) raise "Connection to #{@host}:#{@port} timed out after #{@exporter.timeout} seconds." ensure socket.close if socket end |