Class: CrossoverAgent::Base
- Inherits:
-
Object
- Object
- CrossoverAgent::Base
- Includes:
- Sys
- Defined in:
- lib/crossover_agent.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#ec2_instance_id ⇒ Object
readonly
Returns the value of attribute ec2_instance_id.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize {|@config| ... } ⇒ Base
constructor
A new instance of Base.
- #remote_url ⇒ Object
Constructor Details
#initialize {|@config| ... } ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/crossover_agent.rb', line 13 def initialize(&block) @config = OpenStruct.new(server: 'localhost', port: '3000', auth_token: '123456') yield @config @server = @config['server'] @port = @config['port'] @auth_token = @config['auth_token'] @limit = @config['limit'] || 10 @delay = @config['delay'] || 1 @ec2_instance_id = `wget -q -O - http://instance-data/latest/meta-data/instance-id` @ec2_instance_id = "localhost" if @ec2_instance_id.empty? @cpu = CPU::Load.new @disk_stat = Filesystem.stat('/') end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
12 13 14 |
# File 'lib/crossover_agent.rb', line 12 def auth_token @auth_token end |
#ec2_instance_id ⇒ Object (readonly)
Returns the value of attribute ec2_instance_id.
12 13 14 |
# File 'lib/crossover_agent.rb', line 12 def ec2_instance_id @ec2_instance_id end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/crossover_agent.rb', line 12 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
12 13 14 |
# File 'lib/crossover_agent.rb', line 12 def server @server end |
Class Method Details
.execute ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/crossover_agent.rb', line 31 def self.execute = %w(-s -p -t -l -d) args, = CliParser.parse([], ) agent = CrossoverAgent::Base.new do |cfg| cfg.server = ['-s'] if ['-s'] cfg.port = ['-p'] if ['-p'] cfg.auth_token = ['-t'] if ['-t'] cfg.limit = ['-l'].to_i if ['-l'] cfg.delay = ['-d'].to_i if ['-d'] end agent.execute end |
Instance Method Details
#execute ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/crossover_agent.rb', line 43 def execute loop do begin push_data rescue Exception => e puts e. ensure sleep @delay end end end |
#remote_url ⇒ Object
27 28 29 |
# File 'lib/crossover_agent.rb', line 27 def remote_url "http://#{@server}:#{@port}/metrics" end |