NOTE: This page is Work In Progress. Custom Metrics functionality is not enabled in SPM yet.
Pushing Metrics
Request format
...
Code Block | ||
---|---|---|
| ||
TIMESTAMP=$(($(date +%s)*1000)) METRIC=`echo -n "$TIMESTAMP\tcustom\tconsumed_coffee\toffice-1\tkitchen-2\t100.0\tsum"` TOKEN=488858e2-759b-46bf-a9d3-f6069b579be3 curl -H "Content-Type: text/plain" -X POST -d "$METRIC" "http://apps-local.sematext.com:8082/spm-receiver/receive?host=`hostname`&token=$TOKEN" |
...
Code Block | ||
---|---|---|
| ||
require 'httparty' class MetricSerializer def serialize(options) "#{options[:timestamp]}\tcustom\t#{options[:name]}\t#{options[:filter1]}\t#{options[:filter2]}\t#{options[:value]}\t#{options[:agg]}" end end class MetricSender include HTTParty def initialize(options) raise "receiver_url is required" unless options[:receiver_url] raise "host is required" unless options[:host] raise "token is required" unless options[:token] self.class.default_options[:base_uri] = options[:receiver_url] @serializer = MetricSerializer.new @host = options[:host] @token = options[:token] @version = "1.9.0" end def send(options) current_time = (Time.now.to_f * 1000).to_i merged_options = { :timestamp => current_time, :agg => 'avg' }.merge(options) s = @serializer.serialize(merged_options) puts s post_metric(s) end private def post_metric(body) post_options = { :query => {:host => @host, :token => @token, :v => @version}, :headers => {'Content-Type' => 'text/plain; charset=utf-8'}, :body => body } self.class.post('receive', post_options) end end RECEIVER_OPTIONS = { :receiver_url => "http://apps-localappssematext.sematext.com:8082/spm-receiver/", :host => "katrin", :token => "488858e2-759b-46bf-a9d3-f6069b579be3" } sender = MetricSender.new(RECEIVER_OPTIONS) sender.send :name => "coffee_consumed", :filter1 => "office-1", :filter2 => "kitchen-2", :value => 100.0, :agg => "sum" |
...
Any frequency limitations depends depend on AF implementation.
TODO Former user (Deleted) (reffer refer to AF frequency limits).
TODO Pavel Zalunin (add Java example)