graphite-api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -90,6 +90,26 @@ client.metrics({
90
90
  # => webServer.web01.memUsage 40 1326067060
91
91
  ```
92
92
 
93
+ Increment records
94
+ ```ruby
95
+ require 'graphite-api'
96
+
97
+ client = GraphiteAPI::Client.new( graphite: 'graphite:2003' )
98
+
99
+ client.increment("jobs_in_queue", "num_errors")
100
+ # => jobs_in_queue 1 Time.now.to_i
101
+ # => num_errors 1 Time.now.to_i
102
+
103
+ client.increment("jobs_in_queue", "num_errors", by: 999)
104
+ # => jobs_in_queue 999 Time.now.to_i
105
+ # => num_errors 999 Time.now.to_i
106
+
107
+ client.increment("jobs_in_queue", "num_errors", by: 20, time: Time.at(123456))
108
+ # => jobs_in_queue 20 123456
109
+ # => num_errors 20 123456
110
+
111
+ ```
112
+
93
113
  Some DSL sweetness
94
114
  ```ruby
95
115
  require 'graphite-api'
@@ -67,8 +67,28 @@ module GraphiteAPI
67
67
  def metrics metric, time = Time.now
68
68
  buffer.push :metric => metric, :time => time
69
69
  end
70
+
70
71
  alias_method :add_metrics, :metrics
71
-
72
+
73
+ # increment keys
74
+ #
75
+ # increment("key1","key2")
76
+ # => metrics("key1" => 1, "key2" => 1)
77
+ #
78
+ # increment("key1","key2", {:by => 999})
79
+ # => metrics("key1" => 999, "key2" => 999)
80
+ #
81
+ # increment("key1","key2", {:time => Time.at(123456)})
82
+ # => metrics({"key1" => 1, "key2" => 1},Time.at(123456))
83
+ def increment(*keys)
84
+ opt = {}
85
+ opt.merge! keys.pop if keys.last.is_a? Hash
86
+ by = opt.fetch(:by,1)
87
+ time = opt.fetch(:time,Time.now)
88
+ metric = keys.inject({}) {|h,k| h.tap { h[k] = by}}
89
+ metrics(metric, time)
90
+ end
91
+
72
92
  def join
73
93
  sleep while buffer.new_records?
74
94
  end
@@ -1,5 +1,5 @@
1
1
  module GraphiteAPI
2
2
  class Version
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphite-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: