-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatsagent.rb
46 lines (38 loc) · 1.09 KB
/
statsagent.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
require 'sinatra'
require 'json'
require 'logging'
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'exceptions'
require 'statsmanager'
#require 'active_support/core_ext/hash/keys'
class StatsAgent < Sinatra::Base
use Rack::Logger
configure do
enable :logging, :dump_errors, :raise_errors, :show_exceptions
disable :reload_templates, :protection, :caching
end
def initialize
@app = app
Logging::Config::YamlConfigurator.load('config.yml')
@logger = Logging.logger[self]
@manager = StatsManager.instance
@logger.info "app setup complete"
end
get '/' do
@manager.collectors.values.map(&:to_hash).to_json
end
get '/heartbeat' do
@manager.heartbeat.to_json
end
get '/add/:collector/:type/:interval' do
begin
raise UnknownCollector unless params[:type]
@manager.add_collector(params[:collector].to_sym, params.delete('interval').to_f, params.symbolize_keys).to_json
rescue CollectorBaseException => e
e.to_json
end
end
get '/remove/:id' do
@manager.remove_collector(params[:id].to_i).to_json
end
end