{"action":"created","comment":{"url":"https://api.github.com/repos/bukowskis/meter/pulls/comments/26376807","id":26376807,"diff_hunk":"@@ -1,36 +1,58 @@\n-require 'meter/backends'\n+require 'meter/backends/base'\n+require 'meter/backends/udp'\n+require 'meter/backends/statsd'\n+require 'meter/backends/datadog'\n+require 'meter/backends/json_log'\n require 'meter/configure'\n+require 'meter/mdc'\n+require 'meter/metric/base'\n+require 'meter/metric/counter'\n+require 'meter/metric/gauge'\n+require 'meter/metric/histogram'\n+require 'meter/metric/timing'\n+require 'meter/rails/middleware'\n+require \"meter/rails/railtie\" if defined?(Rails::Railtie)\n \n module Meter\n \n-  def self.increment(key, options = {})\n-    id = options.delete(:id)\n-    backends.datadog.increment key, options\n-    backends.counter.increment(\"#{::Meter.config.namespace}.#{key}.#{id}\", options) if id\n-\n-  rescue => exception\n-    ::Meter.config.logger.error exception.inspect\n-  end\n-\n-  def self.gauge(key, value, options = {})\n-    backends.datadog.gauge key, value, options\n-\n-  rescue => exception\n-    ::Meter.config.logger.error exception.inspect\n+  class << self\n+    def increment(key, value: 1, sample_rate: 1, tags: {}, data: {})\n+      metric = Metric::Counter.new(name: key, value: value, sample_rate: sample_rate, tags: tags, data: data)\n+      send_metric_to_backends(metric)\n+    rescue => exception\n+      ::Meter.config.logger.error exception.inspect\n+    end\n+    alias :track :increment\n+\n+    def gauge(key, value, sample_rate: 1, tags: {}, data: {})\n+      metric = Metric::Gauge.new(name: key, value: value, sample_rate: sample_rate, tags: tags, data: data)\n+      send_metric_to_backends(metric)\n+    rescue => exception\n+      ::Meter.config.logger.error exception.inspect\n+    end\n+\n+    def histogram(key, value, sample_rate: 1, tags: {}, data: {})\n+      metric = Metric::Histogram.new(name: key, value: value, sample_rate: sample_rate, tags: tags, data: data)\n+      send_metric_to_backends(metric)\n+    rescue => exception\n+      ::Meter.config.logger.error exception.inspect\n+    end\n+\n+    def timing(key, value, sample_rate: 1, tags: {}, data: {})\n+      metric = Metric::Timing.new(name: key, value: value, sample_rate: sample_rate, tags: tags, data: data)\n+      send_metric_to_backends(metric)\n+    rescue => exception\n+      ::Meter.config.logger.error exception.inspect\n+    end\n+\n+    def send_metric_to_backends(metric)\n+      return unless should_sample? metric.sample_rate\n+      config.backends.each {|backend| backend.emit_metric(metric)}\n+      metric\n+    end\n+\n+    def should_sample?(sample_rate = 1)\n+      sample_rate == 1 or rand < sample_rate","path":"lib/meter.rb","position":70,"original_position":70,"commit_id":"1026e0c2e7bbbd69406d22dc9cf8cf1710285fb6","original_commit_id":"1026e0c2e7bbbd69406d22dc9cf8cf1710285fb6","user":{"login":"mmzoo","id":1029840,"avatar_url":"https://avatars.githubusercontent.com/u/1029840?v=3","gravatar_id":"","url":"https://api.github.com/users/mmzoo","html_url":"https://github.com/mmzoo","followers_url":"https://api.github.com/users/mmzoo/followers","following_url":"https://api.github.com/users/mmzoo/following{/other_user}","gists_url":"https://api.github.com/users/mmzoo/gists{/gist_id}","starred_url":"https://api.github.com/users/mmzoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmzoo/subscriptions","organizations_url":"https://api.github.com/users/mmzoo/orgs","repos_url":"https://api.github.com/users/mmzoo/repos","events_url":"https://api.github.com/users/mmzoo/events{/privacy}","received_events_url":"https://api.github.com/users/mmzoo/received_events","type":"User","site_admin":false},"body":"Och vad gör koden egentligen :)","created_at":"2015-03-13T10:45:47Z","updated_at":"2015-03-13T10:45:47Z","html_url":"https://github.com/bukowskis/meter/pull/2#discussion_r26376807","pull_request_url":"https://api.github.com/repos/bukowskis/meter/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/comments/26376807"},"html":{"href":"https://github.com/bukowskis/meter/pull/2#discussion_r26376807"},"pull_request":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/bukowskis/meter/pulls/2","id":31115400,"html_url":"https://github.com/bukowskis/meter/pull/2","diff_url":"https://github.com/bukowskis/meter/pull/2.diff","patch_url":"https://github.com/bukowskis/meter/pull/2.patch","issue_url":"https://api.github.com/repos/bukowskis/meter/issues/2","number":2,"state":"open","locked":false,"title":"Experimental refactor","user":{"login":"mmzoo","id":1029840,"avatar_url":"https://avatars.githubusercontent.com/u/1029840?v=3","gravatar_id":"","url":"https://api.github.com/users/mmzoo","html_url":"https://github.com/mmzoo","followers_url":"https://api.github.com/users/mmzoo/followers","following_url":"https://api.github.com/users/mmzoo/following{/other_user}","gists_url":"https://api.github.com/users/mmzoo/gists{/gist_id}","starred_url":"https://api.github.com/users/mmzoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmzoo/subscriptions","organizations_url":"https://api.github.com/users/mmzoo/orgs","repos_url":"https://api.github.com/users/mmzoo/repos","events_url":"https://api.github.com/users/mmzoo/events{/privacy}","received_events_url":"https://api.github.com/users/mmzoo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-13T10:42:36Z","updated_at":"2015-03-13T10:45:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b99b5d13a78320d7e6296eb934f2dc64cad2ab1b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bukowskis/meter/pulls/2/commits","review_comments_url":"https://api.github.com/repos/bukowskis/meter/pulls/2/comments","review_comment_url":"https://api.github.com/repos/bukowskis/meter/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bukowskis/meter/issues/2/comments","statuses_url":"https://api.github.com/repos/bukowskis/meter/statuses/1026e0c2e7bbbd69406d22dc9cf8cf1710285fb6","head":{"label":"bukowskis:experimental-refactor","ref":"experimental-refactor","sha":"1026e0c2e7bbbd69406d22dc9cf8cf1710285fb6","user":{"login":"bukowskis","id":754811,"avatar_url":"https://avatars.githubusercontent.com/u/754811?v=3","gravatar_id":"","url":"https://api.github.com/users/bukowskis","html_url":"https://github.com/bukowskis","followers_url":"https://api.github.com/users/bukowskis/followers","following_url":"https://api.github.com/users/bukowskis/following{/other_user}","gists_url":"https://api.github.com/users/bukowskis/gists{/gist_id}","starred_url":"https://api.github.com/users/bukowskis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bukowskis/subscriptions","organizations_url":"https://api.github.com/users/bukowskis/orgs","repos_url":"https://api.github.com/users/bukowskis/repos","events_url":"https://api.github.com/users/bukowskis/events{/privacy}","received_events_url":"https://api.github.com/users/bukowskis/received_events","type":"Organization","site_admin":false},"repo":{"id":10817539,"name":"meter","full_name":"bukowskis/meter","owner":{"login":"bukowskis","id":754811,"avatar_url":"https://avatars.githubusercontent.com/u/754811?v=3","gravatar_id":"","url":"https://api.github.com/users/bukowskis","html_url":"https://github.com/bukowskis","followers_url":"https://api.github.com/users/bukowskis/followers","following_url":"https://api.github.com/users/bukowskis/following{/other_user}","gists_url":"https://api.github.com/users/bukowskis/gists{/gist_id}","starred_url":"https://api.github.com/users/bukowskis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bukowskis/subscriptions","organizations_url":"https://api.github.com/users/bukowskis/orgs","repos_url":"https://api.github.com/users/bukowskis/repos","events_url":"https://api.github.com/users/bukowskis/events{/privacy}","received_events_url":"https://api.github.com/users/bukowskis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bukowskis/meter","description":"A generic abstraction layer for fire and forgetting measurements via UDP.","fork":false,"url":"https://api.github.com/repos/bukowskis/meter","forks_url":"https://api.github.com/repos/bukowskis/meter/forks","keys_url":"https://api.github.com/repos/bukowskis/meter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bukowskis/meter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bukowskis/meter/teams","hooks_url":"https://api.github.com/repos/bukowskis/meter/hooks","issue_events_url":"https://api.github.com/repos/bukowskis/meter/issues/events{/number}","events_url":"https://api.github.com/repos/bukowskis/meter/events","assignees_url":"https://api.github.com/repos/bukowskis/meter/assignees{/user}","branches_url":"https://api.github.com/repos/bukowskis/meter/branches{/branch}","tags_url":"https://api.github.com/repos/bukowskis/meter/tags","blobs_url":"https://api.github.com/repos/bukowskis/meter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bukowskis/meter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bukowskis/meter/git/refs{/sha}","trees_url":"https://api.github.com/repos/bukowskis/meter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bukowskis/meter/statuses/{sha}","languages_url":"https://api.github.com/repos/bukowskis/meter/languages","stargazers_url":"https://api.github.com/repos/bukowskis/meter/stargazers","contributors_url":"https://api.github.com/repos/bukowskis/meter/contributors","subscribers_url":"https://api.github.com/repos/bukowskis/meter/subscribers","subscription_url":"https://api.github.com/repos/bukowskis/meter/subscription","commits_url":"https://api.github.com/repos/bukowskis/meter/commits{/sha}","git_commits_url":"https://api.github.com/repos/bukowskis/meter/git/commits{/sha}","comments_url":"https://api.github.com/repos/bukowskis/meter/comments{/number}","issue_comment_url":"https://api.github.com/repos/bukowskis/meter/issues/comments{/number}","contents_url":"https://api.github.com/repos/bukowskis/meter/contents/{+path}","compare_url":"https://api.github.com/repos/bukowskis/meter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bukowskis/meter/merges","archive_url":"https://api.github.com/repos/bukowskis/meter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bukowskis/meter/downloads","issues_url":"https://api.github.com/repos/bukowskis/meter/issues{/number}","pulls_url":"https://api.github.com/repos/bukowskis/meter/pulls{/number}","milestones_url":"https://api.github.com/repos/bukowskis/meter/milestones{/number}","notifications_url":"https://api.github.com/repos/bukowskis/meter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bukowskis/meter/labels{/name}","releases_url":"https://api.github.com/repos/bukowskis/meter/releases{/id}","created_at":"2013-06-20T10:29:18Z","updated_at":"2015-02-20T09:18:52Z","pushed_at":"2015-03-13T10:34:54Z","git_url":"git://github.com/bukowskis/meter.git","ssh_url":"git@github.com:bukowskis/meter.git","clone_url":"https://github.com/bukowskis/meter.git","svn_url":"https://github.com/bukowskis/meter","homepage":null,"size":460,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"bukowskis:master","ref":"master","sha":"8c608911007230fa4abd76513594e443adad687a","user":{"login":"bukowskis","id":754811,"avatar_url":"https://avatars.githubusercontent.com/u/754811?v=3","gravatar_id":"","url":"https://api.github.com/users/bukowskis","html_url":"https://github.com/bukowskis","followers_url":"https://api.github.com/users/bukowskis/followers","following_url":"https://api.github.com/users/bukowskis/following{/other_user}","gists_url":"https://api.github.com/users/bukowskis/gists{/gist_id}","starred_url":"https://api.github.com/users/bukowskis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bukowskis/subscriptions","organizations_url":"https://api.github.com/users/bukowskis/orgs","repos_url":"https://api.github.com/users/bukowskis/repos","events_url":"https://api.github.com/users/bukowskis/events{/privacy}","received_events_url":"https://api.github.com/users/bukowskis/received_events","type":"Organization","site_admin":false},"repo":{"id":10817539,"name":"meter","full_name":"bukowskis/meter","owner":{"login":"bukowskis","id":754811,"avatar_url":"https://avatars.githubusercontent.com/u/754811?v=3","gravatar_id":"","url":"https://api.github.com/users/bukowskis","html_url":"https://github.com/bukowskis","followers_url":"https://api.github.com/users/bukowskis/followers","following_url":"https://api.github.com/users/bukowskis/following{/other_user}","gists_url":"https://api.github.com/users/bukowskis/gists{/gist_id}","starred_url":"https://api.github.com/users/bukowskis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bukowskis/subscriptions","organizations_url":"https://api.github.com/users/bukowskis/orgs","repos_url":"https://api.github.com/users/bukowskis/repos","events_url":"https://api.github.com/users/bukowskis/events{/privacy}","received_events_url":"https://api.github.com/users/bukowskis/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bukowskis/meter","description":"A generic abstraction layer for fire and forgetting measurements via UDP.","fork":false,"url":"https://api.github.com/repos/bukowskis/meter","forks_url":"https://api.github.com/repos/bukowskis/meter/forks","keys_url":"https://api.github.com/repos/bukowskis/meter/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bukowskis/meter/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bukowskis/meter/teams","hooks_url":"https://api.github.com/repos/bukowskis/meter/hooks","issue_events_url":"https://api.github.com/repos/bukowskis/meter/issues/events{/number}","events_url":"https://api.github.com/repos/bukowskis/meter/events","assignees_url":"https://api.github.com/repos/bukowskis/meter/assignees{/user}","branches_url":"https://api.github.com/repos/bukowskis/meter/branches{/branch}","tags_url":"https://api.github.com/repos/bukowskis/meter/tags","blobs_url":"https://api.github.com/repos/bukowskis/meter/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bukowskis/meter/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bukowskis/meter/git/refs{/sha}","trees_url":"https://api.github.com/repos/bukowskis/meter/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bukowskis/meter/statuses/{sha}","languages_url":"https://api.github.com/repos/bukowskis/meter/languages","stargazers_url":"https://api.github.com/repos/bukowskis/meter/stargazers","contributors_url":"https://api.github.com/repos/bukowskis/meter/contributors","subscribers_url":"https://api.github.com/repos/bukowskis/meter/subscribers","subscription_url":"https://api.github.com/repos/bukowskis/meter/subscription","commits_url":"https://api.github.com/repos/bukowskis/meter/commits{/sha}","git_commits_url":"https://api.github.com/repos/bukowskis/meter/git/commits{/sha}","comments_url":"https://api.github.com/repos/bukowskis/meter/comments{/number}","issue_comment_url":"https://api.github.com/repos/bukowskis/meter/issues/comments{/number}","contents_url":"https://api.github.com/repos/bukowskis/meter/contents/{+path}","compare_url":"https://api.github.com/repos/bukowskis/meter/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bukowskis/meter/merges","archive_url":"https://api.github.com/repos/bukowskis/meter/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bukowskis/meter/downloads","issues_url":"https://api.github.com/repos/bukowskis/meter/issues{/number}","pulls_url":"https://api.github.com/repos/bukowskis/meter/pulls{/number}","milestones_url":"https://api.github.com/repos/bukowskis/meter/milestones{/number}","notifications_url":"https://api.github.com/repos/bukowskis/meter/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bukowskis/meter/labels{/name}","releases_url":"https://api.github.com/repos/bukowskis/meter/releases{/id}","created_at":"2013-06-20T10:29:18Z","updated_at":"2015-02-20T09:18:52Z","pushed_at":"2015-03-13T10:34:54Z","git_url":"git://github.com/bukowskis/meter.git","ssh_url":"git@github.com:bukowskis/meter.git","clone_url":"https://github.com/bukowskis/meter.git","svn_url":"https://github.com/bukowskis/meter","homepage":null,"size":460,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/2"},"html":{"href":"https://github.com/bukowskis/meter/pull/2"},"issue":{"href":"https://api.github.com/repos/bukowskis/meter/issues/2"},"comments":{"href":"https://api.github.com/repos/bukowskis/meter/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bukowskis/meter/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/bukowskis/meter/statuses/1026e0c2e7bbbd69406d22dc9cf8cf1710285fb6"}}}}