librato-metrics 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +3 -0
- data/.gitignore +3 -1
- data/CHANGELOG.md +10 -0
- data/README.md +33 -5
- data/Rakefile +5 -1
- data/certs/librato-public.pem +20 -0
- data/examples/simple.rb +24 -0
- data/examples/submit_every.rb +27 -0
- data/lib/librato/metrics/aggregator.rb +11 -3
- data/lib/librato/metrics/annotator.rb +54 -13
- data/lib/librato/metrics/client.rb +26 -6
- data/lib/librato/metrics/queue.rb +12 -4
- data/lib/librato/metrics/version.rb +1 -1
- data/librato-metrics.gemspec +3 -0
- data/spec/integration/metrics/annotator_spec.rb +50 -0
- data/spec/integration/metrics_spec.rb +115 -61
- data/spec/unit/metrics/queue_spec.rb +3 -3
- metadata +35 -7
- metadata.gz.sig +2 -0
data.tar.gz.sig
ADDED
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### Version 1.1.0
|
4
|
+
* Add ability to update annotation events
|
5
|
+
* Add ability to fetch annotation events
|
6
|
+
* Add block form of annotation
|
7
|
+
* Add metric batch update support
|
8
|
+
* Add support for pattern-based metric deletes
|
9
|
+
* Add set of code examples
|
10
|
+
* Sign gem when building
|
11
|
+
* Documentation improvements
|
12
|
+
|
3
13
|
### Version 1.0.4
|
4
14
|
* Ensure sane default timeouts for all requests
|
5
15
|
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
Librato Metrics
|
2
2
|
=======
|
3
3
|
|
4
|
-
[![Build Status](https://secure.travis-ci.org/librato/librato-metrics.png?branch=master)](http://travis-ci.org/librato/librato-metrics)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/librato-metrics.png)](http://badge.fury.io/rb/librato-metrics) [![Build Status](https://secure.travis-ci.org/librato/librato-metrics.png?branch=master)](http://travis-ci.org/librato/librato-metrics) [![Code Climate](https://codeclimate.com/github/librato/librato-metrics.png)](https://codeclimate.com/github/librato/librato-metrics)
|
5
5
|
|
6
6
|
A convenient Ruby wrapper for the Librato Metrics API.
|
7
7
|
|
8
|
+
This gem provides granular control for scripting interactions with the Metrics core API. It is well suited for integrations, scripts, workers & background jobs. If you want to submit from a web app, take at look at [librato-rails](https://github.com/librato/librato-rails) and/or [librato-rack](https://github.com/librato/librato-rack).
|
9
|
+
|
8
10
|
## Installation
|
9
11
|
|
10
12
|
In your shell:
|
@@ -130,7 +132,7 @@ If you need extra attributes for a `Queue` timing measurement, simply add them o
|
|
130
132
|
|
131
133
|
Annotation streams are a great way to track events like deploys, backups or anything else that might affect your system. They can be overlaid on any other metric stream so you can easily see the impact of changes.
|
132
134
|
|
133
|
-
At a minimum each annotation needs to be assigned to a stream and to have a title. Let's add an annotation for deploying v45 of our app to the `deployments` stream:
|
135
|
+
At a minimum each annotation needs to be assigned to a stream and to have a title. Let's add an annotation for deploying `v45` of our app to the `deployments` stream:
|
134
136
|
|
135
137
|
Librato::Metrics.annotate :deployments, 'deployed v45'
|
136
138
|
|
@@ -140,6 +142,12 @@ There are a number of optional fields which can make annotations even more power
|
|
140
142
|
:start_time => 1354662596, :end_time => 1354662608,
|
141
143
|
:description => 'Deployed 6f3bc6e67682: fix lotsa bugs…'
|
142
144
|
|
145
|
+
You can also automatically annotate the start and end time of an action by using `annotate`'s block form:
|
146
|
+
|
147
|
+
Librato::Metrics.annotate :deployments, 'deployed v46' do
|
148
|
+
# do work..
|
149
|
+
end
|
150
|
+
|
143
151
|
More fine-grained control of annotations is available via the `Annotator` object:
|
144
152
|
|
145
153
|
annotator = Librato::Metrics::Annotator.new
|
@@ -202,15 +210,29 @@ Get the 20 most recent 15 minute data point rollups for `temperature`:
|
|
202
210
|
|
203
211
|
data = Librato::Metrics.fetch :temperature, :count => 20, :resolution => 900
|
204
212
|
|
205
|
-
There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/gauges/:name) or the [fetch documentation](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics
|
213
|
+
There are many more options supported for querying, take a look at the [REST API docs](http://dev.librato.com/v1/get/gauges/:name) or the [fetch documentation](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#fetch-instance_method) for more details.
|
214
|
+
|
215
|
+
## Setting Metric Properties
|
216
|
+
|
217
|
+
Setting custom [properties](http://dev.librato.com/v1/metrics#metric_properties) on your metrics is easy:
|
218
|
+
|
219
|
+
# assign a period and default color
|
220
|
+
Librato::Metrics.update :temperature, :period => 15, :attributes => { :color => 'F00' }
|
221
|
+
|
222
|
+
It is also possible to update properties for multiple metrics at once, see the [#update method documentation](http://rubydoc.info/github/librato/librato-metrics/master/Librato/Metrics/Client#update-instance_method) for more information.
|
206
223
|
|
207
224
|
## Deleting Metrics
|
208
225
|
|
209
226
|
If you ever need to remove a metric and all of its measurements, doing so is easy:
|
210
227
|
|
211
|
-
#
|
228
|
+
# delete the metrics 'temperature' and 'humidity'
|
212
229
|
Librato::Metrics.delete :temperature, :humidity
|
213
230
|
|
231
|
+
You can also delete using wildcards:
|
232
|
+
|
233
|
+
# delete metrics that start with cpu. except for cpu.free
|
234
|
+
Librato::Metrics.delete :names => 'cpu.*', :exclude => ['cpu.free']
|
235
|
+
|
214
236
|
Note that deleted metrics and their measurements are unrecoverable, so use with care.
|
215
237
|
|
216
238
|
## Using Multiple Accounts Simultaneously
|
@@ -244,7 +266,13 @@ Once the queue is associated you can use it normally:
|
|
244
266
|
|
245
267
|
## Thread Safety
|
246
268
|
|
247
|
-
The `librato-metrics` gem currently does not do internal locking for thread safety. When used in multi-threaded applications, please add your own mutexes for sensitive operations.
|
269
|
+
The `librato-metrics` gem currently does not do internal locking for thread safety. When used in multi-threaded applications, please add your own [mutexes](http://www.ruby-doc.org/core-2.0/Mutex.html) for sensitive operations.
|
270
|
+
|
271
|
+
## More Information
|
272
|
+
|
273
|
+
`librato-metrics` is sufficiently complex that not everything can be documented in the README. Additional options are documented regularly in the codebase. You are encouraged to take a quick look through the [docs](http://rubydoc.info/github/librato/librato-metrics/frames) and [source](https://github.com/librato/librato-metrics) for more.
|
274
|
+
|
275
|
+
We also maintain a set of [examples of common uses](https://github.com/librato/librato-metrics/tree/master/examples) and appreciate contributions if you have them.
|
248
276
|
|
249
277
|
## Contribution
|
250
278
|
|
data/Rakefile
CHANGED
@@ -38,6 +38,10 @@ YARD::Rake::YardocTask.new
|
|
38
38
|
# IRB
|
39
39
|
desc "Open an irb session preloaded with this library"
|
40
40
|
task :console do
|
41
|
-
|
41
|
+
if !`which pry`.empty?
|
42
|
+
sh "pry -r ./lib/librato/metrics.rb"
|
43
|
+
else
|
44
|
+
sh "irb -rubygems -r ./lib/librato/metrics.rb"
|
45
|
+
end
|
42
46
|
end
|
43
47
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIDNjCCAh6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBBMREwDwYDVQQDDAhydWJ5
|
3
|
+
Z2VtczEXMBUGCgmSJomT8ixkARkWB2xpYnJhdG8xEzARBgoJkiaJk/IsZAEZFgNj
|
4
|
+
b20wHhcNMTMwODA4MjIxOTQ2WhcNMTQwODA4MjIxOTQ2WjBBMREwDwYDVQQDDAhy
|
5
|
+
dWJ5Z2VtczEXMBUGCgmSJomT8ixkARkWB2xpYnJhdG8xEzARBgoJkiaJk/IsZAEZ
|
6
|
+
FgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/X7kdKwZ/oi/A
|
7
|
+
Bjs/caxkyDIZgLS/kgmuloThfPBBR6MuN4GXe/hsdzSH8XhtBYoYpK/F2rRBsrS+
|
8
|
+
jLrZbKJAGUIrqHiSfdLzx2k2sGUYlKzf6a4xWi587ndC8Bvh5ldc85W1llHDeASS
|
9
|
+
R5Wjper4KU1NWG1FAVvQCXhSKdmki+wX7Jnd7CQ+oz7kkKYPM8G/ZTdb+qn7wRLV
|
10
|
+
KaR+zzGDmwTQ2WzMitSXmf/ku4MUmRzsyepDXXERLynSp8ITk67g2HMCyvOPsf8K
|
11
|
+
cYvl/wbb8By/r6HOjy7SM7Yo354uIfhniu8AKymIKxsb4Ig71S0cU7Hm3+WBTi28
|
12
|
+
AIg8TUaXAgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFDbyQQqO4xJmaKBE
|
13
|
+
neQ4y+RWCvOXMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAKAzXbA47
|
14
|
+
9U59SsEfqR+DLdv1VAcdmxawqC+ZmG4FpxZhuHhaoUui35AoQjzSiHEUNDTIu3u7
|
15
|
+
TcsYwXMPzuyzZJJKXvBKmSb9mWJ99DOH81oUmOzX7jClQXZHrnFtHdARcLQsPmga
|
16
|
+
4Dh+fWXWxPJ6fkvg826vJ4pDml7Oo9sCXTpC2ki/5VekTXkpFrUsQRXjlXPkmT3/
|
17
|
+
xa858BGRjvU59WPE13QGiba7YIeHtREvNx42JIfoJMV74ofrKIuTw9CMto2gz9Xx
|
18
|
+
Kx1ncn07A+bJnKZ6henQAF1CH96ZcqcJH179S2tIiKDM8keeRIUOPC3WT0faok/2
|
19
|
+
gA2ozdr851c/nA==
|
20
|
+
-----END CERTIFICATE-----
|
data/examples/simple.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'librato/metrics'
|
2
|
+
|
3
|
+
Librato::Metrics.authenticate 'my email', 'my api key'
|
4
|
+
|
5
|
+
# send a measurement of 12 for 'foo'
|
6
|
+
Librato::Metrics.submit :cpu => 54
|
7
|
+
|
8
|
+
# submit multiple metrics at once
|
9
|
+
Librato::Metrics.submit :cpu => 63, :memory => 213
|
10
|
+
|
11
|
+
# submit a metric with a custom source
|
12
|
+
Librato::Metrics.submit :cpu => {:source => 'myapp', :value => 75}
|
13
|
+
|
14
|
+
# if you are sending many metrics it is much more performant
|
15
|
+
# to submit them in sets rather than individually:
|
16
|
+
|
17
|
+
queue = Librato::Metrics::Queue.new
|
18
|
+
|
19
|
+
queue.add 'disk.free' => 1223121
|
20
|
+
queue.add :memory => 2321
|
21
|
+
queue.add :cpu => {:source => 'myapp', :value => 52}
|
22
|
+
#...
|
23
|
+
|
24
|
+
queue.submit
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# send a set of metrics every 60 seconds
|
2
|
+
|
3
|
+
require 'librato/metrics'
|
4
|
+
|
5
|
+
Librato::Metrics.authenticate 'my email', 'my api key'
|
6
|
+
queue = Librato::Metrics::Queue.new
|
7
|
+
|
8
|
+
def sleep_until(time)
|
9
|
+
secs = time - Time.now
|
10
|
+
puts "sleeping for #{secs}"
|
11
|
+
sleep secs
|
12
|
+
end
|
13
|
+
|
14
|
+
loop do
|
15
|
+
start = Time.now
|
16
|
+
|
17
|
+
queue.add 'my.metric' => 1234
|
18
|
+
# do work, add more metrics..
|
19
|
+
|
20
|
+
begin
|
21
|
+
queue.submit
|
22
|
+
rescue Exception => e
|
23
|
+
$stderr.puts e
|
24
|
+
end
|
25
|
+
|
26
|
+
sleep_until(start+60)
|
27
|
+
end
|
@@ -11,9 +11,15 @@ module Librato
|
|
11
11
|
|
12
12
|
attr_reader :source
|
13
13
|
|
14
|
-
|
14
|
+
# @option opts [Integer] :autosubmit_interval If set the aggregator will auto-submit if the given number of seconds has passed when a new metric is added.
|
15
|
+
# @option opts [Boolean] :clear_failures Should the aggregator remove all stored data if it runs into problems with a request? (default: false)
|
16
|
+
# @option opts [Client] :client The client object to use to connect to Metrics. (default: Librato::Metrics.client)
|
17
|
+
# @option opts [Time|Integer] :measure_time A default measure_time to use for measurements added.
|
18
|
+
# @option opts [String] :prefix If set will apply the given prefix to all metric names of measurements added.
|
19
|
+
# @option opts [String] :source The default source to use for measurements added.
|
20
|
+
def initialize(opts={})
|
15
21
|
@aggregated = {}
|
16
|
-
setup_common_options(
|
22
|
+
setup_common_options(opts)
|
17
23
|
end
|
18
24
|
|
19
25
|
# Add a metric entry to the metric set:
|
@@ -43,7 +49,7 @@ module Librato
|
|
43
49
|
|
44
50
|
# Returns true if aggregate contains no measurements
|
45
51
|
#
|
46
|
-
# @return Boolean
|
52
|
+
# @return [Boolean]
|
47
53
|
def empty?
|
48
54
|
@aggregated.empty?
|
49
55
|
end
|
@@ -55,6 +61,8 @@ module Librato
|
|
55
61
|
end
|
56
62
|
alias :flush :clear
|
57
63
|
|
64
|
+
# Returns currently queued data
|
65
|
+
#
|
58
66
|
def queued
|
59
67
|
gauges = []
|
60
68
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Librato::Metrics
|
2
2
|
|
3
|
-
#
|
4
|
-
# given client connection
|
3
|
+
# Read & write annotation streams for a given client connection.
|
5
4
|
class Annotator
|
6
5
|
|
6
|
+
# @option options [Client] :client Client instance used to connect to Metrics
|
7
7
|
def initialize(options={})
|
8
8
|
@client = options[:client] || Librato::Metrics.client
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module Librato::Metrics
|
|
15
15
|
#
|
16
16
|
# @example Annotation with start and end times
|
17
17
|
# annotator.add :deployments, 'deployed v56', :start_time => start,
|
18
|
-
# :end_time =>
|
18
|
+
# :end_time => end_time
|
19
19
|
#
|
20
20
|
# @example Annotation with a specific source
|
21
21
|
# annotator.add :deployments, 'deployed v60', :source => 'app12'
|
@@ -24,6 +24,11 @@ module Librato::Metrics
|
|
24
24
|
# annotator.add :deployments, 'deployed v61',
|
25
25
|
# :description => '9b562b2: shipped new feature foo!'
|
26
26
|
#
|
27
|
+
# @example Annotate with automatic start and end times
|
28
|
+
# annotator.add(:deployments, 'deployed v62') do
|
29
|
+
# # do work..
|
30
|
+
# end
|
31
|
+
#
|
27
32
|
def add(stream, title, options={})
|
28
33
|
options[:title] = title
|
29
34
|
if options[:start_time]
|
@@ -33,21 +38,26 @@ module Librato::Metrics
|
|
33
38
|
options[:end_time] = options[:end_time].to_i
|
34
39
|
end
|
35
40
|
payload = SmartJSON.write(options)
|
36
|
-
|
37
|
-
|
41
|
+
response = connection.post("annotations/#{stream}", payload)
|
42
|
+
# will raise exception if not 200 OK
|
43
|
+
event = SmartJSON.read(response.body)
|
44
|
+
if block_given?
|
45
|
+
yield
|
46
|
+
update_event stream, event['id'], :end_time => Time.now.to_i
|
47
|
+
# need to get updated representation
|
48
|
+
event = fetch_event stream, event['id']
|
49
|
+
end
|
50
|
+
event
|
38
51
|
end
|
39
52
|
|
53
|
+
# client instance used by this object
|
40
54
|
def client
|
41
55
|
@client
|
42
56
|
end
|
43
57
|
|
44
|
-
|
45
|
-
client.connection
|
46
|
-
end
|
47
|
-
|
48
|
-
# Delete an annotation streams
|
58
|
+
# Delete an annotation stream
|
49
59
|
#
|
50
|
-
# @example Delete 'deployment' annotation stream
|
60
|
+
# @example Delete the 'deployment' annotation stream
|
51
61
|
# annotator.delete :deployment
|
52
62
|
#
|
53
63
|
def delete(stream)
|
@@ -77,17 +87,28 @@ module Librato::Metrics
|
|
77
87
|
# annotator.fetch :deployments
|
78
88
|
#
|
79
89
|
# @example Get events on 'deployments' between start and end times
|
80
|
-
# annotator.fetch :deployments, :start_time => start,
|
90
|
+
# annotator.fetch :deployments, :start_time => start,
|
91
|
+
# :end_time => end_time
|
81
92
|
#
|
82
93
|
# @example Source-limited listing
|
83
94
|
# annotator.fetch :deployments, :sources => ['foo','bar','baz'],
|
84
|
-
# :start_time => start, :end_time =>
|
95
|
+
# :start_time => start, :end_time => end_time
|
85
96
|
#
|
86
97
|
def fetch(stream, options={})
|
87
98
|
response = connection.get("annotations/#{stream}", options)
|
88
99
|
SmartJSON.read(response.body)
|
89
100
|
end
|
90
101
|
|
102
|
+
# Get properties for a given annotation stream event
|
103
|
+
#
|
104
|
+
# @example Get event
|
105
|
+
# annotator.fetch :deployments, 23
|
106
|
+
#
|
107
|
+
def fetch_event(stream, id)
|
108
|
+
response = connection.get("annotations/#{stream}/#{id}")
|
109
|
+
SmartJSON.read(response.body)
|
110
|
+
end
|
111
|
+
|
91
112
|
# List currently existing annotation streams
|
92
113
|
#
|
93
114
|
# @example List all annotation streams
|
@@ -101,6 +122,26 @@ module Librato::Metrics
|
|
101
122
|
SmartJSON.read(response.body)
|
102
123
|
end
|
103
124
|
|
125
|
+
# Update an event's properties
|
126
|
+
#
|
127
|
+
# @example Set an end time for a previously submitted event
|
128
|
+
# annotator.update_event 'deploys', 'v24', :end_time => end_time
|
129
|
+
#
|
130
|
+
def update_event(stream, id, options={})
|
131
|
+
url = "annotations/#{stream}/#{id}"
|
132
|
+
connection.put do |request|
|
133
|
+
request.url connection.build_url(url)
|
134
|
+
request.body = SmartJSON.write(options)
|
135
|
+
end
|
136
|
+
# expects 204 will raise exception otherwise
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def connection
|
142
|
+
client.connection
|
143
|
+
end
|
144
|
+
|
104
145
|
end
|
105
146
|
|
106
147
|
end
|
@@ -90,16 +90,22 @@ module Librato
|
|
90
90
|
#
|
91
91
|
# @example Delete metrics 'foo' and 'bar'
|
92
92
|
# Librato::Metrics.delete :foo, :bar
|
93
|
+
#
|
94
|
+
# @example Delete metrics that start with 'foo' except 'foobar'
|
95
|
+
# Librato::Metrics.delete :names => 'foo*', :exclude => ['foobar']
|
96
|
+
#
|
93
97
|
def delete(*metric_names)
|
94
98
|
raise(NoMetricsProvided, 'Metric name missing.') if metric_names.empty?
|
95
|
-
metric_names.
|
96
|
-
|
99
|
+
if metric_names[0].respond_to?(:keys) # hash form
|
100
|
+
params = metric_names[0]
|
101
|
+
else
|
102
|
+
params = { :names => metric_names.map(&:to_s) }
|
103
|
+
end
|
97
104
|
connection.delete do |request|
|
98
105
|
request.url connection.build_url("metrics")
|
99
106
|
request.body = SmartJSON.write(params)
|
100
107
|
end
|
101
|
-
# expects 204, middleware will raise exception
|
102
|
-
# otherwise.
|
108
|
+
# expects 204, middleware will raise exception otherwise.
|
103
109
|
true
|
104
110
|
end
|
105
111
|
|
@@ -226,7 +232,9 @@ module Librato
|
|
226
232
|
@queue.submit
|
227
233
|
end
|
228
234
|
|
229
|
-
# Update
|
235
|
+
# Update one or more metrics. Note that attributes are specified in
|
236
|
+
# their own hash for updating a single metric but are included inline
|
237
|
+
# when updating multiple metrics.
|
230
238
|
#
|
231
239
|
# @example Update metric 'temperature'
|
232
240
|
# Librato::Metrics.update :temperature, :period => 15, :attributes => { :color => 'F00' }
|
@@ -234,9 +242,21 @@ module Librato
|
|
234
242
|
# @example Update metric 'humidity', creating it if it doesn't exist
|
235
243
|
# Librato::Metrics.update 'humidity', :type => :gauge, :period => 60, :display_name => 'Humidity'
|
236
244
|
#
|
245
|
+
# @example Update multiple metrics by name
|
246
|
+
# Librato::Metrics.update :names => ["foo", "bar"], :period => 60
|
247
|
+
#
|
248
|
+
# @example Update all metrics that start with 'foo' that aren't 'foobar'
|
249
|
+
# Librato::Metrics.update :names => 'foo*', :exclude => ['foobar'], :display_min => 0
|
250
|
+
#
|
237
251
|
def update(metric, options = {})
|
252
|
+
if metric.respond_to?(:each)
|
253
|
+
url = "metrics" # update multiple metrics
|
254
|
+
options = metric
|
255
|
+
else
|
256
|
+
url = "metrics/#{metric}" # update single
|
257
|
+
end
|
238
258
|
connection.put do |request|
|
239
|
-
request.url connection.build_url(
|
259
|
+
request.url connection.build_url(url)
|
240
260
|
request.body = SmartJSON.write(options)
|
241
261
|
end
|
242
262
|
end
|
@@ -7,11 +7,19 @@ module Librato
|
|
7
7
|
|
8
8
|
attr_accessor :skip_measurement_times
|
9
9
|
|
10
|
-
|
10
|
+
# @option opts [Integer] :autosubmit_count If set the queue will auto-submit any time it hits this number of measurements.
|
11
|
+
# @option opts [Integer] :autosubmit_interval If set the queue will auto-submit if the given number of seconds has passed when a new metric is added.
|
12
|
+
# @option opts [Boolean] :clear_failures Should the queue remove any queued measurements from its queue if it runs into problems with a request? (default: false)
|
13
|
+
# @option opts [Client] :client The client object to use to connect to Metrics. (default: Librato::Metrics.client)
|
14
|
+
# @option opts [Time|Integer] :measure_time A default measure_time to use for measurements added.
|
15
|
+
# @option opts [String] :prefix If set will apply the given prefix to all metric names of measurements added.
|
16
|
+
# @option opts [Boolean] :skip_measurement_times If true will not assign measurement_time to each measure as they are added.
|
17
|
+
# @option opts [String] :source The default source to use for measurements added.
|
18
|
+
def initialize(opts={})
|
11
19
|
@queued = {}
|
12
|
-
@autosubmit_count =
|
13
|
-
@skip_measurement_times =
|
14
|
-
setup_common_options(
|
20
|
+
@autosubmit_count = opts[:autosubmit_count]
|
21
|
+
@skip_measurement_times = opts[:skip_measurement_times]
|
22
|
+
setup_common_options(opts)
|
15
23
|
end
|
16
24
|
|
17
25
|
# Add a metric entry to the metric set:
|
data/librato-metrics.gemspec
CHANGED
@@ -41,4 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
|
42
42
|
s.files = `git ls-files`.split("\n")
|
43
43
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
44
|
+
|
45
|
+
s.signing_key = File.expand_path("~/.gem/librato-private_key.pem")
|
46
|
+
s.cert_chain = ["certs/librato-public.pem"]
|
44
47
|
end
|
@@ -41,6 +41,21 @@ module Librato
|
|
41
41
|
first['title'].should == 'deployed v71'
|
42
42
|
first['description'].should == 'deployed foobar!'
|
43
43
|
end
|
44
|
+
it "should have an id for further use" do
|
45
|
+
annotation = subject.add :deployment, "deployed v23"
|
46
|
+
annotation['id'].should_not be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a block" do
|
50
|
+
it "should set both start and end times" do
|
51
|
+
annotation = subject.add 'deploys', 'v345' do
|
52
|
+
sleep 1.0
|
53
|
+
end
|
54
|
+
data = subject.fetch_event 'deploys', annotation['id']
|
55
|
+
data['start_time'].should_not be_nil
|
56
|
+
data['end_time'].should_not be_nil
|
57
|
+
end
|
58
|
+
end
|
44
59
|
end
|
45
60
|
|
46
61
|
describe "#delete" do
|
@@ -109,6 +124,23 @@ module Librato
|
|
109
124
|
end
|
110
125
|
end
|
111
126
|
|
127
|
+
describe "#fetch_event" do
|
128
|
+
context "with existing event" do
|
129
|
+
it "should return event properties" do
|
130
|
+
annotation = subject.add 'deploys', 'v69'
|
131
|
+
data = subject.fetch_event 'deploys', annotation['id']
|
132
|
+
data['title'].should == 'v69'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
context "when event doesn't exist" do
|
136
|
+
it "should raise NotFound" do
|
137
|
+
lambda {
|
138
|
+
data = subject.fetch_event 'deploys', 324
|
139
|
+
}.should raise_error(Metrics::NotFound)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
112
144
|
describe "#list" do
|
113
145
|
before(:each) do
|
114
146
|
subject.add :backups, 'backup 1'
|
@@ -134,6 +166,24 @@ module Librato
|
|
134
166
|
end
|
135
167
|
end
|
136
168
|
|
169
|
+
describe "#update_event" do
|
170
|
+
context "when event exists" do
|
171
|
+
it "should update event" do
|
172
|
+
end_time = (Time.now + 60).to_i
|
173
|
+
annotation = subject.add 'deploys', 'v24'
|
174
|
+
subject.update_event 'deploys', annotation['id'],
|
175
|
+
:end_time => end_time, :title => 'v28'
|
176
|
+
data = subject.fetch_event 'deploys', annotation['id']
|
177
|
+
|
178
|
+
data['title'].should == 'v28'
|
179
|
+
data['end_time'].should == end_time
|
180
|
+
end
|
181
|
+
end
|
182
|
+
context "when event does not exist" do
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
137
187
|
end
|
138
188
|
|
139
189
|
end
|
@@ -46,38 +46,59 @@ module Librato
|
|
46
46
|
describe "#delete" do
|
47
47
|
before(:each) { delete_all_metrics }
|
48
48
|
|
49
|
-
context
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
context 'by names' do
|
50
|
+
|
51
|
+
context "with a single argument" do
|
52
|
+
it "should delete named metric" do
|
53
|
+
Metrics.submit :foo => 123
|
54
|
+
Metrics.list(:name => :foo).should_not be_empty
|
55
|
+
Metrics.delete :foo
|
56
|
+
Metrics.list(:name => :foo).should be_empty
|
57
|
+
end
|
55
58
|
end
|
56
|
-
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
context "with multiple arguments" do
|
61
|
+
it "should delete named metrics" do
|
62
|
+
Metrics.submit :foo => 123, :bar => 345, :baz => 567
|
63
|
+
Metrics.delete :foo, :bar
|
64
|
+
Metrics.list(:name => :foo).should be_empty
|
65
|
+
Metrics.list(:name => :bar).should be_empty
|
66
|
+
Metrics.list(:name => :baz).should_not be_empty
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "with missing metric" do
|
71
|
+
it "should run cleanly" do
|
72
|
+
# the API currently returns success even if
|
73
|
+
# the metric has already been deleted or is absent.
|
74
|
+
Metrics.delete :missing
|
75
|
+
end
|
65
76
|
end
|
66
|
-
end
|
67
77
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
context "with no arguments" do
|
79
|
+
it "should not make request" do
|
80
|
+
lambda {
|
81
|
+
Metrics.delete
|
82
|
+
}.should raise_error(Metrics::NoMetricsProvided)
|
83
|
+
end
|
73
84
|
end
|
85
|
+
|
74
86
|
end
|
75
87
|
|
76
|
-
context
|
77
|
-
it "should
|
78
|
-
|
79
|
-
|
80
|
-
|
88
|
+
context 'by pattern' do
|
89
|
+
it "should filter properly" do
|
90
|
+
Metrics.submit :foo => 1, :foobar => 2, :foobaz => 3, :bar => 4
|
91
|
+
Metrics.delete :names => 'fo*', :exclude => ['foobar']
|
92
|
+
|
93
|
+
%w{foo foobaz}.each do |name|
|
94
|
+
lambda {
|
95
|
+
Metrics.fetch name
|
96
|
+
}.should raise_error(Librato::Metrics::NotFound)
|
97
|
+
end
|
98
|
+
|
99
|
+
%w{foobar bar}.each do |name|
|
100
|
+
Metrics.fetch name # stil exist
|
101
|
+
end
|
81
102
|
end
|
82
103
|
end
|
83
104
|
end
|
@@ -104,7 +125,8 @@ module Librato
|
|
104
125
|
|
105
126
|
context "with a start_time" do
|
106
127
|
it "should return entries since that time" do
|
107
|
-
|
128
|
+
# 1 hr ago
|
129
|
+
data = Metrics.fetch :my_counter, :start_time => Time.now-3600
|
108
130
|
data['unassigned'].length.should == 3
|
109
131
|
data['baz'].length.should == 2
|
110
132
|
end
|
@@ -205,52 +227,84 @@ module Librato
|
|
205
227
|
|
206
228
|
describe "#update" do
|
207
229
|
|
208
|
-
context
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
it "should update the metric" do
|
215
|
-
Metrics.update :foo, :display_name => "Foo Metric",
|
216
|
-
:period => 15,
|
217
|
-
:attributes => {
|
218
|
-
:display_max => 1000
|
219
|
-
}
|
220
|
-
foo = Metrics.fetch :foo
|
221
|
-
foo['display_name'].should == 'Foo Metric'
|
222
|
-
foo['period'].should == 15
|
223
|
-
foo['attributes']['display_max'].should == 1000
|
224
|
-
end
|
225
|
-
end
|
230
|
+
context 'with a single metric' do
|
231
|
+
context "with an existing metric" do
|
232
|
+
before do
|
233
|
+
delete_all_metrics
|
234
|
+
Metrics.submit :foo => 123
|
235
|
+
end
|
226
236
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
foo['period'].should == 15
|
239
|
-
foo['attributes']['display_max'].should == 1000
|
237
|
+
it "should update the metric" do
|
238
|
+
Metrics.update :foo, :display_name => "Foo Metric",
|
239
|
+
:period => 15,
|
240
|
+
:attributes => {
|
241
|
+
:display_max => 1000
|
242
|
+
}
|
243
|
+
foo = Metrics.fetch :foo
|
244
|
+
foo['display_name'].should == 'Foo Metric'
|
245
|
+
foo['period'].should == 15
|
246
|
+
foo['attributes']['display_max'].should == 1000
|
247
|
+
end
|
240
248
|
end
|
241
249
|
|
242
|
-
|
243
|
-
|
244
|
-
|
250
|
+
context "without an existing metric" do
|
251
|
+
it "should create the metric if type specified" do
|
252
|
+
delete_all_metrics
|
245
253
|
Metrics.update :foo, :display_name => "Foo Metric",
|
254
|
+
:type => 'gauge',
|
246
255
|
:period => 15,
|
247
256
|
:attributes => {
|
248
257
|
:display_max => 1000
|
249
258
|
}
|
250
|
-
|
259
|
+
foo = Metrics.fetch :foo
|
260
|
+
foo['display_name'].should == 'Foo Metric'
|
261
|
+
foo['period'].should == 15
|
262
|
+
foo['attributes']['display_max'].should == 1000
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should raise error if no type specified" do
|
266
|
+
delete_all_metrics
|
267
|
+
lambda {
|
268
|
+
Metrics.update :foo, :display_name => "Foo Metric",
|
269
|
+
:period => 15,
|
270
|
+
:attributes => {
|
271
|
+
:display_max => 1000
|
272
|
+
}
|
273
|
+
}.should raise_error
|
274
|
+
end
|
251
275
|
end
|
276
|
+
|
252
277
|
end
|
253
278
|
|
279
|
+
context 'with multiple metrics' do
|
280
|
+
before do
|
281
|
+
delete_all_metrics
|
282
|
+
Metrics.submit 'my.1' => 1, 'my.2' => 2, 'my.3' => 3, 'my.4' => 4
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should support named list" do
|
286
|
+
names = ['my.1', 'my.3']
|
287
|
+
Metrics.update :names => names, :period => 60
|
288
|
+
|
289
|
+
names.each do |name|
|
290
|
+
metric = Metrics.fetch name
|
291
|
+
metric['period'].should == 60
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should support patterns" do
|
296
|
+
Metrics.update :names => 'my.*', :exclude => ['my.3'],
|
297
|
+
:display_max => 100
|
298
|
+
|
299
|
+
%w{my.1 my.2 my.4}.each do |name|
|
300
|
+
metric = Metrics.fetch name
|
301
|
+
metric['attributes']['display_max'].should == 100
|
302
|
+
end
|
303
|
+
|
304
|
+
excluded = Metrics.fetch 'my.3'
|
305
|
+
excluded['attributes']['display_max'].should_not == 100
|
306
|
+
end
|
307
|
+
end
|
254
308
|
end
|
255
309
|
|
256
310
|
end
|
@@ -6,7 +6,7 @@ module Librato
|
|
6
6
|
describe Queue do
|
7
7
|
|
8
8
|
before(:each) do
|
9
|
-
@time =
|
9
|
+
@time = (Time.now.to_i - 1*60)
|
10
10
|
Queue.any_instance.stub(:epoch_time).and_return(@time)
|
11
11
|
end
|
12
12
|
|
@@ -120,13 +120,13 @@ module Librato
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should accept integers" do
|
123
|
-
time =
|
123
|
+
time = @time.to_i
|
124
124
|
subject.add :foo => {:measure_time => time, :value => 123}
|
125
125
|
subject.queued[:gauges][0][:measure_time].should == time
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should accept strings" do
|
129
|
-
time =
|
129
|
+
time = @time.to_s
|
130
130
|
subject.add :foo => {:measure_time => time, :value => 123}
|
131
131
|
subject.queued[:gauges][0][:measure_time].should == time.to_i
|
132
132
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librato-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matt Sanders
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
|
11
|
+
cert_chain:
|
12
|
+
- !binary |-
|
13
|
+
LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUROakNDQWg2Z0F3SUJB
|
14
|
+
Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREJCTVJFd0R3WURWUVFEREFoeWRX
|
15
|
+
SjUKWjJWdGN6RVhNQlVHQ2dtU0pvbVQ4aXhrQVJrV0IyeHBZbkpoZEc4eEV6
|
16
|
+
QVJCZ29Ka2lhSmsvSXNaQUVaRmdOagpiMjB3SGhjTk1UTXdPREE0TWpJeE9U
|
17
|
+
UTJXaGNOTVRRd09EQTRNakl4T1RRMldqQkJNUkV3RHdZRFZRUUREQWh5CmRX
|
18
|
+
SjVaMlZ0Y3pFWE1CVUdDZ21TSm9tVDhpeGtBUmtXQjJ4cFluSmhkRzh4RXpB
|
19
|
+
UkJnb0praWFKay9Jc1pBRVoKRmdOamIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFF
|
20
|
+
QkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDL1g3a2RLd1ovb2kvQQpCanMvY2F4
|
21
|
+
a3lESVpnTFMva2dtdWxvVGhmUEJCUjZNdU40R1hlL2hzZHpTSDhYaHRCWW9Z
|
22
|
+
cEsvRjJyUkJzclMrCmpMclpiS0pBR1VJcnFIaVNmZEx6eDJrMnNHVVlsS3pm
|
23
|
+
NmE0eFdpNTg3bmRDOEJ2aDVsZGM4NVcxbGxIRGVBU1MKUjVXanBlcjRLVTFO
|
24
|
+
V0cxRkFWdlFDWGhTS2Rta2krd1g3Sm5kN0NRK296N2trS1lQTThHL1pUZGIr
|
25
|
+
cW43d1JMVgpLYVIrenpHRG13VFEyV3pNaXRTWG1mL2t1NE1VbVJ6c3llcERY
|
26
|
+
WEVSTHluU3A4SVRrNjdnMkhNQ3l2T1BzZjhLCmNZdmwvd2JiOEJ5L3I2SE9q
|
27
|
+
eTdTTTdZbzM1NHVJZmhuaXU4QUt5bUlLeHNiNElnNzFTMGNVN0htMytXQlRp
|
28
|
+
MjgKQUlnOFRVYVhBZ01CQUFHak9UQTNNQWtHQTFVZEV3UUNNQUF3SFFZRFZS
|
29
|
+
ME9CQllFRkRieVFRcU80eEptYUtCRQpuZVE0eStSV0N2T1hNQXNHQTFVZER3
|
30
|
+
UUVBd0lFc0RBTkJna3Foa2lHOXcwQkFRVUZBQU9DQVFFQUtBelhiQTQ3CjlV
|
31
|
+
NTlTc0VmcVIrRExkdjFWQWNkbXhhd3FDK1ptRzRGcHhaaHVIaGFvVXVpMzVB
|
32
|
+
b1FqelNpSEVVTkRUSXUzdTcKVGNzWXdYTVB6dXl6WkpKS1h2QkttU2I5bVdK
|
33
|
+
OTlET0g4MW9VbU96WDdqQ2xRWFpIcm5GdEhkQVJjTFFzUG1nYQo0RGgrZldY
|
34
|
+
V3hQSjZma3ZnODI2dko0cERtbDdPbzlzQ1hUcEMya2kvNVZla1RYa3BGclVz
|
35
|
+
UVJYamxYUGttVDMvCnhhODU4QkdSanZVNTlXUEUxM1FHaWJhN1lJZUh0UkV2
|
36
|
+
Tng0MkpJZm9KTVY3NG9mcktJdVR3OUNNdG8yZ3o5WHgKS3gxbmNuMDdBK2JK
|
37
|
+
bktaNmhlblFBRjFDSDk2WmNxY0pIMTc5UzJ0SWlLRE04a2VlUklVT1BDM1dU
|
38
|
+
MGZhb2svMgpnQTJvemRyODUxYy9uQT09Ci0tLS0tRU5EIENFUlRJRklDQVRF
|
39
|
+
LS0tLS0K
|
40
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
13
41
|
dependencies:
|
14
42
|
- !ruby/object:Gem::Dependency
|
15
43
|
name: faraday
|
@@ -171,6 +199,9 @@ files:
|
|
171
199
|
- README.md
|
172
200
|
- Rakefile
|
173
201
|
- benchmarks/array_vs_set.rb
|
202
|
+
- certs/librato-public.pem
|
203
|
+
- examples/simple.rb
|
204
|
+
- examples/submit_every.rb
|
174
205
|
- lib/librato/metrics.rb
|
175
206
|
- lib/librato/metrics/aggregator.rb
|
176
207
|
- lib/librato/metrics/annotator.rb
|
@@ -216,9 +247,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
216
247
|
- - ! '>='
|
217
248
|
- !ruby/object:Gem::Version
|
218
249
|
version: '0'
|
219
|
-
segments:
|
220
|
-
- 0
|
221
|
-
hash: 236501250346713379
|
222
250
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
251
|
none: false
|
224
252
|
requirements:
|
@@ -227,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
255
|
version: '0'
|
228
256
|
requirements: []
|
229
257
|
rubyforge_project:
|
230
|
-
rubygems_version: 1.8.
|
258
|
+
rubygems_version: 1.8.23
|
231
259
|
signing_key:
|
232
260
|
specification_version: 2
|
233
261
|
summary: Ruby wrapper for Librato's Metrics API
|
metadata.gz.sig
ADDED