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 +20 -0
- data/lib/graphite-api/client.rb +21 -1
- data/lib/graphite-api/version.rb +1 -1
- metadata +1 -1
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'
|
data/lib/graphite-api/client.rb
CHANGED
@@ -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
|
data/lib/graphite-api/version.rb
CHANGED