Sha256: 5d38d28a136e242f5ca104f98c7e7fc1e4d1b9425cfa5d222c88c2bea643f906

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/api/agent.rb
snowman-io-0.5.0 lib/snowman-io/api/agent.rb
snowman-io-0.4.0 lib/snowman-io/api/agent.rb
snowman-io-0.3.1 lib/snowman-io/api/agent.rb
snowman-io-0.3.0 lib/snowman-io/api/agent.rb
snowman-io-0.2.0 lib/snowman-io/api/agent.rb