module SnowmanIO module API class Agent < Grape::API namespace :agent do desc "Report metrics from agent" params do requires :token, type: String optional :metrics, type: Array do requires :name, type: String requires :kind, type: String requires :value end end post "metrics" do if app = App.where(system: false, 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 {status: "ok", processed: processed, accepted: accepted} else {status: "rejected", reason: "WRONG APP"} end end end end end end