lib/snowman-io/api/agent.rb in snowman-io-0.0.6 vs lib/snowman-io/api/agent.rb in snowman-io-0.1.0

- old
+ new

@@ -4,24 +4,31 @@ namespace :agent do desc "Report metrics from agent" params do requires :token, type: String - optional :metrics, type: Array + optional :metrics, type: Array do + requires :name, type: String + requires :kind, type: String + requires :value + end end post "metrics" do - if app = App.where(token: params[:token]).first - params[:metrics].each do |metric| + if app = App.where(token: permitted_params[:token]).first + processed = 0 + accepted = 0 + (permitted_params[:metrics] || []).each do |metric| + processed += 1 if Metric.supported?(metric["kind"]) app.register_metric_value(metric["name"], metric["kind"], metric["value"].to_f, Time.now) + accepted += 1 end end - "OK" + {status: "ok", processed: processed, accepted: accepted} else - "WRONG APP" + {status: "rejected", reason: "WRONG APP"} end end - end end end end