lib/fnordmetric/web/app.rb in fnordmetric-1.0.1 vs lib/fnordmetric/web/app.rb in fnordmetric-1.2.0
- old
+ new
@@ -20,10 +20,15 @@
helpers do
include Rack::Utils
include FnordMetric::AppHelpers
end
+ %w(fnordmetric-ui.js fnordmetric-ui.css fnordmetric-core.css fnordmetric-core.js).each do |f|
+ next if ::File.exists?(::File.expand_path("../../../../web/#{f}", __FILE__))
+ raise "error: file 'web/#{f}' does not exist, please run build.sh in web/"
+ end
+
def initialize(opts = {})
@opts = FnordMetric.default_options(opts)
@namespaces = FnordMetric.namespaces
@redis = Redis.connect(:url => @opts[:redis_url])
@@ -35,88 +40,24 @@
redirect "#{path_prefix}/#{@namespaces.keys.first}"
end
get '/:namespace' do
pass unless current_namespace
+ current_namespace.ready!(@redis)
haml :app
end
post '/events' do
+ params = JSON.parse(request.body.read) unless params
halt 400, 'please specify the event_type (_type)' unless params["_type"]
track_event((8**32).to_s(36), parse_params(params))
end
# FIXPAUL move to websockets
get '/:namespace/dashboard/:dashboard' do
dashboard = current_namespace.dashboards.fetch(params[:dashboard])
dashboard.to_json
end
-
-
- # get '/favicon.ico' do
- # ""
- # end
-
- # get '/:namespace/gauge/:name' do
- # gauge = if params[:name].include?("++")
- # parts = params[:name].split("++")
- # current_namespace.gauges[parts.first.to_sym].fetch_gauge(parts.last, params[:tick].to_i)
- # else
- # current_namespace.gauges[params[:name].to_sym]
- # end
-
- # if !gauge
- # status 404
- # return ""
- # end
-
- # data = if gauge.three_dimensional?
- # _t = (params[:at] || Time.now).to_i
- # { :count => gauge.field_values_total(_t), :values => gauge.field_values_at(_t) }
- # elsif params[:at] && params[:at] =~ /^[0-9]+$/
- # { (_t = gauge.tick_at(params[:at].to_i)) => gauge.value_at(_t) }
- # elsif params[:at] && params[:at] =~ /^([0-9]+)-([0-9]+)$/
- # _range = params[:at].split("-").map(&:to_i)
- # _values = gauge.values_in(_range.first.._range.last)
- # params[:sum] ? { :sum => _values.values.compact.map(&:to_i).sum } : _values
- # else
- # { (_t = gauge.tick_at(Time.now.to_i-gauge.tick)) => gauge.value_at(_t) }
- # end
-
- # data.to_json
- # end
-
- # get '/:namespace/sessions' do
- # sessions = current_namespace.sessions(:all, :limit => 100).map do |session|
- # session.fetch_data!
- # session.to_json
- # end
-
- # { :sessions => sessions }.to_json
- # end
-
- # get '/:namespace/events' do
- # events = if params[:type]
- # current_namespace.events(:by_type, :type => params[:type])
- # elsif params[:session_key]
- # current_namespace.events(:by_session_key, :session_key => params[:session_key])
- # else
- # find_opts = { :limit => 100 }
- # find_opts.merge!(:since => params[:since].to_i+1) if params[:since]
- # current_namespace.events(:all, find_opts)
- # end
-
- # { :events => events.map(&:to_json) }.to_json
- # end
-
- # get '/:namespace/event_types' do
- # types_key = current_namespace.key_prefix("type-")
- # keys = @redis.keys("#{types_key}*").map{ |k| k.gsub(types_key,'') }
-
- # { :types => keys }.to_json
- # end
-
-
end