appoptics-api-ruby 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +24 -24
- data/appoptics-api-ruby.gemspec +5 -5
- data/examples/simple.rb +5 -5
- data/examples/submit_every.rb +2 -2
- data/lib/appoptics/metrics.rb +11 -11
- data/lib/appoptics/metrics/aggregator.rb +3 -3
- data/lib/appoptics/metrics/annotator.rb +2 -2
- data/lib/appoptics/metrics/client.rb +24 -24
- data/lib/appoptics/metrics/collection.rb +1 -1
- data/lib/appoptics/metrics/connection.rb +5 -5
- data/lib/appoptics/metrics/errors.rb +1 -1
- data/lib/appoptics/metrics/middleware/count_requests.rb +1 -1
- data/lib/appoptics/metrics/middleware/expects_status.rb +1 -1
- data/lib/appoptics/metrics/middleware/request_body.rb +1 -1
- data/lib/appoptics/metrics/middleware/retry.rb +2 -2
- data/lib/appoptics/metrics/persistence/direct.rb +2 -2
- data/lib/appoptics/metrics/persistence/test.rb +1 -1
- data/lib/appoptics/metrics/processor.rb +6 -6
- data/lib/appoptics/metrics/queue.rb +2 -2
- data/lib/appoptics/metrics/smart_json.rb +1 -1
- data/lib/appoptics/metrics/util.rb +1 -1
- data/lib/appoptics/metrics/version.rb +2 -2
- data/spec/integration/metrics/annotator_spec.rb +1 -1
- data/spec/integration/metrics/connection_spec.rb +1 -1
- data/spec/integration/metrics/middleware/count_requests_spec.rb +1 -1
- data/spec/integration/metrics/queue_spec.rb +3 -3
- data/spec/integration/metrics_spec.rb +5 -5
- data/spec/spec_helper.rb +5 -5
- data/spec/unit/metrics/aggregator_spec.rb +5 -5
- data/spec/unit/metrics/client_spec.rb +2 -2
- data/spec/unit/metrics/connection_spec.rb +1 -1
- data/spec/unit/metrics/queue/autosubmission_spec.rb +1 -1
- data/spec/unit/metrics/queue_spec.rb +9 -9
- data/spec/unit/metrics/smart_json_spec.rb +1 -1
- data/spec/unit/metrics/util_spec.rb +1 -1
- data/spec/unit/metrics_spec.rb +6 -6
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8960b0f874d99c1e5e75950f0fca0c4e0e6f6996
|
4
|
+
data.tar.gz: e1a7df7d6b822ce6cffd9554d26aa860f2b131aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7315a9d19572506ac89cc6c14d9808a12e9c459d677b606cb53daf4f69bbe6cd3d53971f0868fd820c6495b06464733b97fbef44886a7ae67451fa437f6b7ad
|
7
|
+
data.tar.gz: b49d02718e01084e7df7bf198e9f78d0e13d113b4a1e94f4e09e2bbb55d2c93450bbcb4ad84a189e65ff6e530cde3f73df856389fb031834fec6cc210d0d9cdd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,8 +29,8 @@ If you are using jruby, you need to ensure [jruby-openssl](https://github.com/jr
|
|
29
29
|
|
30
30
|
If you are looking for the quickest possible route to getting a data into Metrics, you only need two lines:
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
AppOptics::Metrics.authenticate 'api_key'
|
33
|
+
AppOptics::Metrics.submit my_metric: { value: 42, tags: { host: 'localhost' } }
|
34
34
|
|
35
35
|
While this is all you need to get started, if you are sending a number of metrics regularly a queue may be easier/more performant so read on...
|
36
36
|
|
@@ -39,7 +39,7 @@ While this is all you need to get started, if you are sending a number of metric
|
|
39
39
|
|
40
40
|
Make sure you have [an account for AppOptics](https://www.appoptics.com/) and then authenticate with your email and API key (on your account page):
|
41
41
|
|
42
|
-
|
42
|
+
AppOptics::Metrics.authenticate 'api_key'
|
43
43
|
|
44
44
|
|
45
45
|
## Sending Measurements
|
@@ -48,7 +48,7 @@ A measurement includes a metric name, value, and one or more tags. Tags include
|
|
48
48
|
|
49
49
|
Queue up a simple metric named `temperature`:
|
50
50
|
|
51
|
-
queue =
|
51
|
+
queue = AppOptics::Metrics::Queue.new
|
52
52
|
queue.add temperature: {value: 77, tags: { city: 'oakland' }}
|
53
53
|
queue.submit
|
54
54
|
|
@@ -56,7 +56,7 @@ Queue up a simple metric named `temperature`:
|
|
56
56
|
|
57
57
|
You can initialize `Queue` and/or `Aggregator` with top-level tags that will be applied to every measurement:
|
58
58
|
|
59
|
-
queue =
|
59
|
+
queue = AppOptics::Metrics::Queue.new(tags: { service: 'auth', environment: 'prod', host: 'auth-prod-1' })
|
60
60
|
queue.add my_metric: 10
|
61
61
|
queue.submit
|
62
62
|
|
@@ -74,11 +74,11 @@ For more information, visit the [API documentation](https://docs.appoptics.com/a
|
|
74
74
|
|
75
75
|
Get name and properties for all metrics you have in the system:
|
76
76
|
|
77
|
-
metrics =
|
77
|
+
metrics = AppOptics::Metrics.metrics
|
78
78
|
|
79
79
|
Get only metrics whose name includes `time`:
|
80
80
|
|
81
|
-
metrics =
|
81
|
+
metrics = AppOptics::Metrics.metrics name: 'time'
|
82
82
|
|
83
83
|
|
84
84
|
## Retrieving Measurements
|
@@ -93,7 +93,7 @@ query = {
|
|
93
93
|
group_by_function: "sum",
|
94
94
|
tags_search: "environment=prod*"
|
95
95
|
}
|
96
|
-
|
96
|
+
AppOptics::Metrics.get_series :exceptions, query
|
97
97
|
```
|
98
98
|
|
99
99
|
For more information, visit the [API documentation](https://docs.appoptics.com/api/#retrieve-a-measurement).
|
@@ -105,7 +105,7 @@ If you are measuring something very frequently e.g. per-request in a web applica
|
|
105
105
|
|
106
106
|
Aggregate a simple gauge metric named `response_latency`:
|
107
107
|
|
108
|
-
aggregator =
|
108
|
+
aggregator = AppOptics::Metrics::Aggregator.new
|
109
109
|
aggregator.add response_latency: 85.0
|
110
110
|
aggregator.add response_latency: 100.5
|
111
111
|
aggregator.add response_latency: 150.2
|
@@ -118,7 +118,7 @@ Which would result in a gauge measurement like:
|
|
118
118
|
|
119
119
|
You can specify a source during aggregate construction:
|
120
120
|
|
121
|
-
aggregator =
|
121
|
+
aggregator = AppOptics::Metrics::Aggregator.new(tags: { service: 'auth', environment: 'prod', host: 'auth-prod-1' })
|
122
122
|
|
123
123
|
You can aggregate multiple metrics at once:
|
124
124
|
|
@@ -150,23 +150,23 @@ Annotation streams are a great way to track events like deploys, backups or anyt
|
|
150
150
|
|
151
151
|
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:
|
152
152
|
|
153
|
-
|
153
|
+
AppOptics::Metrics.annotate :deployments, 'deployed v45'
|
154
154
|
|
155
155
|
There are a number of optional fields which can make annotations even more powerful:
|
156
156
|
|
157
|
-
|
157
|
+
AppOptics::Metrics.annotate :deployments, 'deployed v46', source: 'frontend',
|
158
158
|
start_time: 1354662596, end_time: 1354662608,
|
159
159
|
description: 'Deployed 6f3bc6e67682: fix lotsa bugs…'
|
160
160
|
|
161
161
|
You can also automatically annotate the start and end time of an action by using `annotate`'s block form:
|
162
162
|
|
163
|
-
|
163
|
+
AppOptics::Metrics.annotate :deployments, 'deployed v46' do
|
164
164
|
# do work..
|
165
165
|
end
|
166
166
|
|
167
167
|
More fine-grained control of annotations is available via the `Annotator` object:
|
168
168
|
|
169
|
-
annotator =
|
169
|
+
annotator = AppOptics::Metrics::Annotator.new
|
170
170
|
|
171
171
|
# list annotation streams
|
172
172
|
streams = annotator.list
|
@@ -184,15 +184,15 @@ See the documentation of `Annotator` for more details and examples of use.
|
|
184
184
|
Both `Queue` and `Aggregator` support automatically submitting measurements on a given time interval:
|
185
185
|
|
186
186
|
# submit once per minute
|
187
|
-
timed_queue =
|
187
|
+
timed_queue = AppOptics::Metrics::Queue.new(autosubmit_interval: 60)
|
188
188
|
|
189
189
|
# submit every 5 minutes
|
190
|
-
timed_aggregator =
|
190
|
+
timed_aggregator = AppOptics::Metrics::Aggregator.new(autosubmit_interval: 300)
|
191
191
|
|
192
192
|
`Queue` also supports auto-submission based on measurement volume:
|
193
193
|
|
194
194
|
# submit when the 400th measurement is queued
|
195
|
-
volume_queue =
|
195
|
+
volume_queue = AppOptics::Metrics::Queue.new(autosubmit_count: 400)
|
196
196
|
|
197
197
|
These options can also be combined for more flexible behavior.
|
198
198
|
|
@@ -205,19 +205,19 @@ If your goal is to collect metrics every _x_ seconds and submit them, [check out
|
|
205
205
|
Setting custom [properties](https://docs.appoptics.com/api/#metric-attributes) on your metrics is easy:
|
206
206
|
|
207
207
|
# assign a period and default color
|
208
|
-
|
208
|
+
AppOptics::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' }
|
209
209
|
|
210
210
|
## Deleting Metrics
|
211
211
|
|
212
212
|
If you ever need to remove a metric and all of its measurements, doing so is easy:
|
213
213
|
|
214
214
|
# delete the metrics 'temperature' and 'humidity'
|
215
|
-
|
215
|
+
AppOptics::Metrics.delete_metrics :temperature, :humidity
|
216
216
|
|
217
217
|
You can also delete using wildcards:
|
218
218
|
|
219
219
|
# delete metrics that start with cpu. except for cpu.free
|
220
|
-
|
220
|
+
AppOptics::Metrics.delete_metrics names: 'cpu.*', exclude: ['cpu.free']
|
221
221
|
|
222
222
|
Note that deleted metrics and their measurements are unrecoverable, so use with care.
|
223
223
|
|
@@ -225,13 +225,13 @@ Note that deleted metrics and their measurements are unrecoverable, so use with
|
|
225
225
|
|
226
226
|
If you need to use metrics with multiple sets of authentication credentials simultaneously, you can do it with `Client`:
|
227
227
|
|
228
|
-
joe =
|
228
|
+
joe = AppOptics::Metrics::Client.new
|
229
229
|
joe.authenticate 'api_key1'
|
230
230
|
|
231
|
-
mike =
|
231
|
+
mike = AppOptics::Metrics::Client.new
|
232
232
|
mike.authenticate 'api_key2'
|
233
233
|
|
234
|
-
All of the same operations you can call directly from `
|
234
|
+
All of the same operations you can call directly from `AppOptics::Metrics` are available per-client:
|
235
235
|
|
236
236
|
# list Joe's metrics
|
237
237
|
joe.metrics
|
@@ -239,7 +239,7 @@ All of the same operations you can call directly from `Appoptics::Metrics` are a
|
|
239
239
|
There are two ways to associate a new queue with a client:
|
240
240
|
|
241
241
|
# these are functionally equivalent
|
242
|
-
joe_queue =
|
242
|
+
joe_queue = AppOptics::Metrics::Queue.new(client: joe)
|
243
243
|
joe_queue = joe.new_queue
|
244
244
|
|
245
245
|
Once the queue is associated you can use it normally:
|
data/appoptics-api-ruby.gemspec
CHANGED
@@ -5,8 +5,8 @@ require 'appoptics/metrics/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'appoptics-api-ruby'
|
8
|
-
s.version = '2.1.
|
9
|
-
s.date = '2017-10-
|
8
|
+
s.version = '2.1.4'
|
9
|
+
s.date = '2017-10-16'
|
10
10
|
s.summary = "Ruby bindings for the AppOptics API"
|
11
11
|
s.description = "An easy to use ruby wrapper for the AppOptics API"
|
12
12
|
s.authors = ["Greg McKeever", "Matt Sanders"]
|
@@ -14,17 +14,17 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = ["lib/appoptics/metrics.rb"]
|
15
15
|
s.homepage =
|
16
16
|
'https://github.com/AppOptics/appoptics-api-ruby'
|
17
|
-
s.license = 'BSD
|
17
|
+
s.license = 'BSD-3-Clause'
|
18
18
|
s.require_paths = %w[lib]
|
19
19
|
|
20
20
|
## runtime dependencies
|
21
|
-
s.add_dependency 'faraday'
|
21
|
+
s.add_dependency 'faraday', '~> 0.7'
|
22
22
|
s.add_dependency 'aggregate', '~> 0.2.2'
|
23
23
|
|
24
24
|
s.files = `git ls-files`.split("\n")
|
25
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
26
|
|
27
|
-
s.cert_chain = ["certs/
|
27
|
+
s.cert_chain = ["certs/librato-public.pem"]
|
28
28
|
if ENV['GEM_SIGNING_KEY']
|
29
29
|
s.signing_key = ENV['GEM_SIGNING_KEY']
|
30
30
|
end
|
data/examples/simple.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
require 'appoptics-api-ruby'
|
2
2
|
|
3
|
-
|
3
|
+
AppOptics::Metrics.authenticate 'my email', 'my api key'
|
4
4
|
|
5
5
|
# send a measurement of 12 for 'foo'
|
6
|
-
|
6
|
+
AppOptics::Metrics.submit cpu: 54
|
7
7
|
|
8
8
|
# submit multiple metrics at once
|
9
|
-
|
9
|
+
AppOptics::Metrics.submit cpu: 63, memory: 213
|
10
10
|
|
11
11
|
# submit a metric with a custom source
|
12
|
-
|
12
|
+
AppOptics::Metrics.submit cpu: {source: 'myapp', value: 75}
|
13
13
|
|
14
14
|
# if you are sending many metrics it is much more performant
|
15
15
|
# to submit them in sets rather than individually:
|
16
16
|
|
17
|
-
queue =
|
17
|
+
queue = AppOptics::Metrics::Queue.new
|
18
18
|
|
19
19
|
queue.add 'disk.free' => 1223121
|
20
20
|
queue.add memory: 2321
|
data/examples/submit_every.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'appoptics-api-ruby'
|
4
4
|
|
5
|
-
|
6
|
-
queue =
|
5
|
+
AppOptics::Metrics.authenticate 'my email', 'my api key'
|
6
|
+
queue = AppOptics::Metrics::Queue.new
|
7
7
|
|
8
8
|
def sleep_until(time)
|
9
9
|
secs = time - Time.now
|
data/lib/appoptics/metrics.rb
CHANGED
@@ -16,7 +16,7 @@ require 'metrics/smart_json'
|
|
16
16
|
require 'metrics/util'
|
17
17
|
require 'metrics/version'
|
18
18
|
|
19
|
-
module
|
19
|
+
module AppOptics
|
20
20
|
|
21
21
|
# Metrics provides a simple wrapper for the Metrics web API with a
|
22
22
|
# number of added conveniences for common use cases.
|
@@ -24,19 +24,19 @@ module Appoptics
|
|
24
24
|
# See the {file:README.md README} for more information and examples.
|
25
25
|
#
|
26
26
|
# @example Simple use case
|
27
|
-
#
|
27
|
+
# AppOptics::Metrics.authenticate 'email', 'api_key'
|
28
28
|
#
|
29
29
|
# # list current metrics
|
30
|
-
#
|
30
|
+
# AppOptics::Metrics.metrics
|
31
31
|
#
|
32
32
|
# # submit a metric immediately
|
33
|
-
#
|
33
|
+
# AppOptics::Metrics.submit foo: 12712
|
34
34
|
#
|
35
35
|
# # fetch the last 10 values of foo
|
36
|
-
#
|
36
|
+
# AppOptics::Metrics.get_measurements :foo, count: 10
|
37
37
|
#
|
38
38
|
# @example Queuing metrics for submission
|
39
|
-
# queue =
|
39
|
+
# queue = AppOptics::Metrics::Queue.new
|
40
40
|
#
|
41
41
|
# # queue some metrics
|
42
42
|
# queue.add foo: 12312
|
@@ -46,7 +46,7 @@ module Appoptics
|
|
46
46
|
# queue.submit
|
47
47
|
#
|
48
48
|
# @example Using a Client object
|
49
|
-
# client =
|
49
|
+
# client = AppOptics::Metrics::Client.new
|
50
50
|
# client.authenticate 'email', 'api_key'
|
51
51
|
#
|
52
52
|
# # list client's metrics
|
@@ -60,7 +60,7 @@ module Appoptics
|
|
60
60
|
# queue.add bar: 45678
|
61
61
|
# queue.submit
|
62
62
|
#
|
63
|
-
# @note Most of the methods you can call directly on
|
63
|
+
# @note Most of the methods you can call directly on AppOptics::Metrics are
|
64
64
|
# delegated to {Client} and are documented there.
|
65
65
|
module Metrics
|
66
66
|
extend SingleForwardable
|
@@ -69,7 +69,7 @@ module Appoptics
|
|
69
69
|
PLURAL_TYPES = TYPES.map { |type| "#{type}s".to_sym }
|
70
70
|
MIN_MEASURE_TIME = (Time.now-(3600*24*365)).to_i
|
71
71
|
|
72
|
-
# Most of the singleton methods of
|
72
|
+
# Most of the singleton methods of AppOptics::Metrics are actually
|
73
73
|
# being called on a global Client instance. See further docs on
|
74
74
|
# Client.
|
75
75
|
#
|
@@ -83,12 +83,12 @@ module Appoptics
|
|
83
83
|
:sources, :submit, :update_metric, :update_metrics,
|
84
84
|
:update_source
|
85
85
|
|
86
|
-
# The
|
86
|
+
# The AppOptics::Metrics::Client being used by module-level
|
87
87
|
# access.
|
88
88
|
#
|
89
89
|
# @return [Client]
|
90
90
|
def self.client
|
91
|
-
@client ||=
|
91
|
+
@client ||= AppOptics::Metrics::Client.new
|
92
92
|
end
|
93
93
|
|
94
94
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'aggregate'
|
2
2
|
require 'metrics/processor'
|
3
3
|
|
4
|
-
module
|
4
|
+
module AppOptics
|
5
5
|
module Metrics
|
6
6
|
|
7
7
|
# If you are measuring something very frequently you can sample into
|
@@ -31,7 +31,7 @@ module Appoptics
|
|
31
31
|
|
32
32
|
# @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.
|
33
33
|
# @option opts [Boolean] :clear_failures Should the aggregator remove all stored data if it runs into problems with a request? (default: false)
|
34
|
-
# @option opts [Client] :client The client object to use to connect to Metrics. (default:
|
34
|
+
# @option opts [Client] :client The client object to use to connect to Metrics. (default: AppOptics::Metrics.client)
|
35
35
|
# @option opts [Time|Integer] :measure_time A default measure_time to use for measurements added.
|
36
36
|
# @option opts [String] :prefix If set will apply the given prefix to all metric names of measurements added.
|
37
37
|
# @option opts [String] :source The default source to use for measurements added.
|
@@ -64,7 +64,7 @@ module Appoptics
|
|
64
64
|
metric = "#{metric}#{SEPARATOR}#{data[:source]}"
|
65
65
|
entry[:source] = data[:source].to_s
|
66
66
|
elsif data[:tags] && data[:tags].respond_to?(:each)
|
67
|
-
metric =
|
67
|
+
metric = AppOptics::Metrics::Util.build_key_for(metric.to_s, data[:tags])
|
68
68
|
entry[:tags] = data[:tags]
|
69
69
|
end
|
70
70
|
else
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module AppOptics::Metrics
|
2
2
|
|
3
3
|
# Read & write annotation streams for a given client connection.
|
4
4
|
class Annotator
|
5
5
|
|
6
6
|
# @option options [Client] :client Client instance used to connect to Metrics
|
7
7
|
def initialize(options={})
|
8
|
-
@client = options[:client] ||
|
8
|
+
@client = options[:client] || AppOptics::Metrics.client
|
9
9
|
end
|
10
10
|
|
11
11
|
# Creates a new annotation on the annotation stream
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppOptics
|
2
2
|
module Metrics
|
3
3
|
|
4
4
|
class Client
|
@@ -9,13 +9,13 @@ module Appoptics
|
|
9
9
|
attr_accessor :api_key, :proxy
|
10
10
|
|
11
11
|
# @example Have the gem build your identifier string
|
12
|
-
#
|
12
|
+
# AppOptics::Metrics.agent_identifier 'flintstone', '0.5', 'fred'
|
13
13
|
#
|
14
14
|
# @example Provide your own identifier string
|
15
|
-
#
|
15
|
+
# AppOptics::Metrics.agent_identifier 'flintstone/0.5 (dev_id:fred)'
|
16
16
|
#
|
17
17
|
# @example Remove identifier string
|
18
|
-
#
|
18
|
+
# AppOptics::Metrics.agent_identifier ''
|
19
19
|
def agent_identifier(*args)
|
20
20
|
if args.length == 1
|
21
21
|
@agent_identifier = args.first
|
@@ -82,13 +82,13 @@ module Appoptics
|
|
82
82
|
# careful with this, this is instant and permanent.
|
83
83
|
#
|
84
84
|
# @example Delete metric 'temperature'
|
85
|
-
#
|
85
|
+
# AppOptics::Metrics.delete_metrics :temperature
|
86
86
|
#
|
87
87
|
# @example Delete metrics 'foo' and 'bar'
|
88
|
-
#
|
88
|
+
# AppOptics::Metrics.delete_metrics :foo, :bar
|
89
89
|
#
|
90
90
|
# @example Delete metrics that start with 'foo' except 'foobar'
|
91
|
-
#
|
91
|
+
# AppOptics::Metrics.delete_metrics names: 'foo*', exclude: ['foobar']
|
92
92
|
#
|
93
93
|
def delete_metrics(*metric_names)
|
94
94
|
raise(NoMetricsProvided, 'Metric name missing.') if metric_names.empty?
|
@@ -122,7 +122,7 @@ module Appoptics
|
|
122
122
|
# optional.
|
123
123
|
#
|
124
124
|
# @example Get 5m moving average of 'foo'
|
125
|
-
# measurements =
|
125
|
+
# measurements = AppOptics::Metrics.get_composite
|
126
126
|
# 'moving_average(mean(series("foo", "*"), {size: "5"}))',
|
127
127
|
# start_time: Time.now.to_i - 60*60, resolution: 300
|
128
128
|
#
|
@@ -144,10 +144,10 @@ module Appoptics
|
|
144
144
|
# Retrieve a specific metric by name, optionally including data points
|
145
145
|
#
|
146
146
|
# @example Get attributes for a metric
|
147
|
-
# metric =
|
147
|
+
# metric = AppOptics::Metrics.get_metric :temperature
|
148
148
|
#
|
149
149
|
# @example Get a metric and its 20 most recent data points
|
150
|
-
# metric =
|
150
|
+
# metric = AppOptics::Metrics.get_metric :temperature, count: 20
|
151
151
|
# metric['measurements'] # => {...}
|
152
152
|
#
|
153
153
|
# A full list of query parameters can be found in the API
|
@@ -177,15 +177,15 @@ module Appoptics
|
|
177
177
|
# Retrieve series of measurements for a given metric
|
178
178
|
#
|
179
179
|
# @example Get series for metric
|
180
|
-
# series =
|
180
|
+
# series = AppOptics::Metrics.get_series :requests, resolution: 1, duration: 3600
|
181
181
|
#
|
182
182
|
# @example Get series for metric grouped by tag
|
183
183
|
# query = { duration: 3600, resolution: 1, group_by: "environment", group_by_function: "sum" }
|
184
|
-
# series =
|
184
|
+
# series = AppOptics::Metrics.get_series :requests, query
|
185
185
|
#
|
186
186
|
# @example Get series for metric grouped by tag and negated by tag filter
|
187
187
|
# query = { duration: 3600, resolution: 1, group_by: "environment", group_by_function: "sum", tags_search: "environment=!staging" }
|
188
|
-
# series =
|
188
|
+
# series = AppOptics::Metrics.get_series :requests, query
|
189
189
|
#
|
190
190
|
# @param [Symbol|String] metric_name Metric name
|
191
191
|
# @param [Hash] options Query options
|
@@ -211,17 +211,17 @@ module Appoptics
|
|
211
211
|
# Retrieve data points for a specific metric
|
212
212
|
#
|
213
213
|
# @example Get 20 most recent data points for metric
|
214
|
-
# data =
|
214
|
+
# data = AppOptics::Metrics.get_measurements :temperature, count: 20
|
215
215
|
#
|
216
216
|
# @example Get the 20 most recent 15 minute data point rollups
|
217
|
-
# data =
|
217
|
+
# data = AppOptics::Metrics.get_measurements :temperature, count: 20,
|
218
218
|
# resolution: 900
|
219
219
|
#
|
220
220
|
# @example Get data points for the last hour
|
221
|
-
# data =
|
221
|
+
# data = AppOptics::Metrics.get_measurements start_time: Time.now-3600
|
222
222
|
#
|
223
223
|
# @example Get 15 min data points from two hours to an hour ago
|
224
|
-
# data =
|
224
|
+
# data = AppOptics::Metrics.get_measurements start_time: Time.now-7200,
|
225
225
|
# end_time: Time.now-3600,
|
226
226
|
# resolution: 900
|
227
227
|
#
|
@@ -245,10 +245,10 @@ module Appoptics
|
|
245
245
|
# List currently existing metrics
|
246
246
|
#
|
247
247
|
# @example List all metrics
|
248
|
-
#
|
248
|
+
# AppOptics::Metrics.metrics
|
249
249
|
#
|
250
250
|
# @example List metrics with 'foo' in the name
|
251
|
-
#
|
251
|
+
# AppOptics::Metrics.metrics name: 'foo'
|
252
252
|
#
|
253
253
|
# @param [Hash] options
|
254
254
|
def metrics(options={})
|
@@ -300,10 +300,10 @@ module Appoptics
|
|
300
300
|
# Update a single metric with new attributes.
|
301
301
|
#
|
302
302
|
# @example Update metric 'temperature'
|
303
|
-
#
|
303
|
+
# AppOptics::Metrics.update_metric :temperature, period: 15, attributes: { color: 'F00' }
|
304
304
|
#
|
305
305
|
# @example Update metric 'humidity', creating it if it doesn't exist
|
306
|
-
#
|
306
|
+
# AppOptics::Metrics.update_metric 'humidity', type: :gauge, period: 60, display_name: 'Humidity'
|
307
307
|
#
|
308
308
|
def update_metric(metric, options = {})
|
309
309
|
url = "metrics/#{metric}"
|
@@ -316,10 +316,10 @@ module Appoptics
|
|
316
316
|
# Update multiple metrics.
|
317
317
|
#
|
318
318
|
# @example Update multiple metrics by name
|
319
|
-
#
|
319
|
+
# AppOptics::Metrics.update_metrics names: ["foo", "bar"], period: 60
|
320
320
|
#
|
321
321
|
# @example Update all metrics that start with 'foo' that aren't 'foobar'
|
322
|
-
#
|
322
|
+
# AppOptics::Metrics.update_metrics names: 'foo*', exclude: ['foobar'], display_min: 0
|
323
323
|
#
|
324
324
|
def update_metrics(metrics)
|
325
325
|
url = "metrics" # update multiple metrics
|
@@ -332,7 +332,7 @@ module Appoptics
|
|
332
332
|
# Retrive a snapshot, to check its progress or find its image_href
|
333
333
|
#
|
334
334
|
# @example Get a snapshot identified by 42
|
335
|
-
#
|
335
|
+
# AppOptics::Metrics.get_snapshot 42
|
336
336
|
#
|
337
337
|
# @param [Integer|String] id
|
338
338
|
def get_snapshot(id)
|
@@ -4,7 +4,7 @@ require 'metrics/middleware/expects_status'
|
|
4
4
|
require 'metrics/middleware/request_body'
|
5
5
|
require 'metrics/middleware/retry'
|
6
6
|
|
7
|
-
module
|
7
|
+
module AppOptics
|
8
8
|
module Metrics
|
9
9
|
|
10
10
|
class Connection
|
@@ -34,10 +34,10 @@ module Appoptics
|
|
34
34
|
url: api_endpoint + "/v1/",
|
35
35
|
request: {open_timeout: 20, timeout: 30}) do |f|
|
36
36
|
|
37
|
-
f.use
|
38
|
-
f.use
|
39
|
-
f.use
|
40
|
-
f.use
|
37
|
+
f.use AppOptics::Metrics::Middleware::RequestBody
|
38
|
+
f.use AppOptics::Metrics::Middleware::Retry
|
39
|
+
f.use AppOptics::Metrics::Middleware::CountRequests
|
40
|
+
f.use AppOptics::Metrics::Middleware::ExpectsStatus
|
41
41
|
|
42
42
|
f.adapter @adapter || Metrics.faraday_adapter
|
43
43
|
f.proxy @proxy if @proxy
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module AppOptics
|
2
2
|
module Metrics
|
3
3
|
module Middleware
|
4
4
|
|
@@ -15,7 +15,7 @@ module Appoptics
|
|
15
15
|
begin
|
16
16
|
env[:body] = request_body # after failure is set to response body
|
17
17
|
@app.call(env)
|
18
|
-
rescue
|
18
|
+
rescue AppOptics::Metrics::ServerError, Timeout::Error,
|
19
19
|
Faraday::Error::ConnectionFailed
|
20
20
|
if retries > 0
|
21
21
|
retries -= 1 and retry
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
# Manages direct persistence with the Appoptics API
|
3
3
|
|
4
|
-
module
|
4
|
+
module AppOptics
|
5
5
|
module Metrics
|
6
6
|
module Persistence
|
7
7
|
class Direct
|
@@ -56,7 +56,7 @@ module Appoptics
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def top_level_keys
|
59
|
-
[
|
59
|
+
[AppOptics::Metrics::PLURAL_TYPES, :measurements].flatten
|
60
60
|
end
|
61
61
|
|
62
62
|
def fetch_globals(queued)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "set"
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
module Metrics
|
5
5
|
|
6
6
|
# Mixin which provides common logic between {Queue} and {Aggregator}
|
@@ -17,12 +17,12 @@ module Appoptics
|
|
17
17
|
|
18
18
|
# The current Client instance this queue is using to authenticate
|
19
19
|
# and connect to Appoptics. This will default to the primary
|
20
|
-
# client used by the
|
20
|
+
# client used by the AppOptics::Metrics module unless it has been
|
21
21
|
# set to something else.
|
22
22
|
#
|
23
|
-
# @return [
|
23
|
+
# @return [AppOptics::Metrics::Client]
|
24
24
|
def client
|
25
|
-
@client ||=
|
25
|
+
@client ||= AppOptics::Metrics.client
|
26
26
|
end
|
27
27
|
|
28
28
|
def has_tags?
|
@@ -85,7 +85,7 @@ module Appoptics
|
|
85
85
|
|
86
86
|
def create_persister
|
87
87
|
type = self.client.persistence.to_s.capitalize
|
88
|
-
|
88
|
+
AppOptics::Metrics::Persistence.const_get(type).new
|
89
89
|
end
|
90
90
|
|
91
91
|
def epoch_time
|
@@ -95,7 +95,7 @@ module Appoptics
|
|
95
95
|
def setup_common_options(options)
|
96
96
|
validate_parameters(options)
|
97
97
|
@autosubmit_interval = options[:autosubmit_interval]
|
98
|
-
@client = options[:client] ||
|
98
|
+
@client = options[:client] || AppOptics::Metrics.client
|
99
99
|
@per_request = options[:per_request] || MEASUREMENTS_PER_REQUEST
|
100
100
|
@source = options[:source]
|
101
101
|
@tags = options.fetch(:tags, {})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'metrics/processor'
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
module Metrics
|
5
5
|
class Queue
|
6
6
|
include Processor
|
@@ -10,7 +10,7 @@ module Appoptics
|
|
10
10
|
# @option opts [Integer] :autosubmit_count If set the queue will auto-submit any time it hits this number of measurements.
|
11
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
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:
|
13
|
+
# @option opts [Client] :client The client object to use to connect to Metrics. (default: AppOptics::Metrics.client)
|
14
14
|
# @option opts [Time|Integer] :measure_time A default measure_time to use for measurements added.
|
15
15
|
# @option opts [String] :prefix If set will apply the given prefix to all metric names of measurements added.
|
16
16
|
# @option opts [Boolean] :skip_measurement_times If true will not assign measurement_time to each measure as they are added.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
module Metrics
|
5
5
|
|
6
6
|
describe Queue do
|
@@ -80,11 +80,11 @@ module Appoptics
|
|
80
80
|
queue.add test_2: { value: 456, tags: { hostname: "metrics-web-stg-2" }}
|
81
81
|
queue.submit
|
82
82
|
|
83
|
-
test_1 =
|
83
|
+
test_1 = AppOptics::Metrics.get_series :test_1, resolution: 1, duration: 3600
|
84
84
|
expect(test_1[0]["tags"]["hostname"]).to eq("metrics-web-stg-1")
|
85
85
|
expect(test_1[0]["measurements"][0]["value"]).to eq(123)
|
86
86
|
|
87
|
-
test_2 =
|
87
|
+
test_2 = AppOptics::Metrics.get_series :test_2, resolution: 1, duration: 3600
|
88
88
|
expect(test_2[0]["tags"]["hostname"]).to eq("metrics-web-stg-2")
|
89
89
|
expect(test_2[0]["measurements"][0]["value"]).to eq(456)
|
90
90
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
describe Metrics do
|
5
5
|
before(:all) { prep_integration_tests }
|
6
6
|
|
@@ -93,7 +93,7 @@ module Appoptics
|
|
93
93
|
%w{foo foobaz}.each do |name|
|
94
94
|
expect {
|
95
95
|
Metrics.get_metric name
|
96
|
-
}.to raise_error(
|
96
|
+
}.to raise_error(AppOptics::Metrics::NotFound)
|
97
97
|
end
|
98
98
|
|
99
99
|
%w{foobar bar}.each do |name|
|
@@ -220,7 +220,7 @@ module Appoptics
|
|
220
220
|
Metrics.submit foo: {type: :counter, value: 12}
|
221
221
|
expect {
|
222
222
|
Metrics.submit foo: 15 # submitting as gauge
|
223
|
-
}.to raise_error(
|
223
|
+
}.to raise_error(AppOptics::Metrics::ClientError)
|
224
224
|
expect {
|
225
225
|
Metrics.submit foo: {type: :counter, value: 17}
|
226
226
|
}.not_to raise_error
|
@@ -273,7 +273,7 @@ module Appoptics
|
|
273
273
|
attributes: {
|
274
274
|
display_max: 1000
|
275
275
|
}
|
276
|
-
}.to raise_error(
|
276
|
+
}.to raise_error(AppOptics::Metrics::ClientError)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -348,7 +348,7 @@ module Appoptics
|
|
348
348
|
source_name = "sources_api_test_#{Time.now.to_f}"
|
349
349
|
expect {
|
350
350
|
no_source = Metrics.get_source(source_name)
|
351
|
-
}.to raise_error(
|
351
|
+
}.to raise_error(AppOptics::Metrics::NotFound)
|
352
352
|
|
353
353
|
Metrics.update_source(source_name, display_name: "New Source")
|
354
354
|
|
data/spec/spec_helper.rb
CHANGED
@@ -18,8 +18,8 @@ RSpec.configure do |config|
|
|
18
18
|
|
19
19
|
# purge all metrics from test account
|
20
20
|
def delete_all_metrics
|
21
|
-
connection =
|
22
|
-
|
21
|
+
connection = AppOptics::Metrics.client.connection
|
22
|
+
AppOptics::Metrics.metrics.each do |metric|
|
23
23
|
#puts "deleting #{metric['name']}..."
|
24
24
|
# expects 204
|
25
25
|
connection.delete("metrics/#{metric['name']}")
|
@@ -28,7 +28,7 @@ RSpec.configure do |config|
|
|
28
28
|
|
29
29
|
# purge all annotations from test account
|
30
30
|
def delete_all_annotations
|
31
|
-
annotator =
|
31
|
+
annotator = AppOptics::Metrics::Annotator.new
|
32
32
|
streams = annotator.list
|
33
33
|
if streams['annotations']
|
34
34
|
names = streams['annotations'].map{|s| s['name']}
|
@@ -41,9 +41,9 @@ RSpec.configure do |config|
|
|
41
41
|
raise 'no TEST_API_USER specified in environment' unless ENV['TEST_API_USER']
|
42
42
|
raise 'no TEST_API_KEY specified in environment' unless ENV['TEST_API_KEY']
|
43
43
|
if ENV['TEST_API_ENDPOINT']
|
44
|
-
|
44
|
+
AppOptics::Metrics.api_endpoint = ENV['TEST_API_ENDPOINT']
|
45
45
|
end
|
46
|
-
|
46
|
+
AppOptics::Metrics.authenticate ENV['TEST_API_USER'], ENV['TEST_API_KEY']
|
47
47
|
end
|
48
48
|
|
49
49
|
def rackup_path(*parts)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require "spec_helper.rb"
|
2
|
-
module
|
2
|
+
module AppOptics
|
3
3
|
module Metrics
|
4
4
|
|
5
5
|
describe Aggregator do
|
@@ -19,9 +19,9 @@ module Appoptics
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context "without specified client" do
|
22
|
-
it "uses
|
22
|
+
it "uses AppOptics::Metrics client" do
|
23
23
|
a = Aggregator.new
|
24
|
-
expect(a.client).to eq(
|
24
|
+
expect(a.client).to eq(AppOptics::Metrics.client)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -342,8 +342,8 @@ module Appoptics
|
|
342
342
|
|
343
343
|
describe "#submit" do
|
344
344
|
before(:all) do
|
345
|
-
|
346
|
-
|
345
|
+
AppOptics::Metrics.authenticate 'me@AppOptics.com', 'foo'
|
346
|
+
AppOptics::Metrics.persistence = :test
|
347
347
|
end
|
348
348
|
|
349
349
|
context "when successful" do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
module Metrics
|
5
5
|
|
6
6
|
describe Client do
|
@@ -64,7 +64,7 @@ module Appoptics
|
|
64
64
|
describe "#connection" do
|
65
65
|
it "raises exception without authentication" do
|
66
66
|
subject.flush_authentication
|
67
|
-
expect { subject.connection }.to raise_error(
|
67
|
+
expect { subject.connection }.to raise_error(AppOptics::Metrics::CredentialsMissing)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
module Metrics
|
5
5
|
|
6
6
|
describe Queue do
|
@@ -26,9 +26,9 @@ module Appoptics
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "without specified client" do
|
29
|
-
it "uses
|
29
|
+
it "uses AppOptics::Metrics client" do
|
30
30
|
queue = Queue.new
|
31
|
-
expect(queue.client).to eq(
|
31
|
+
expect(queue.client).to eq(AppOptics::Metrics.client)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -303,7 +303,7 @@ module Appoptics
|
|
303
303
|
end
|
304
304
|
|
305
305
|
it "returns true when nothing merged" do
|
306
|
-
subject.merge!(
|
306
|
+
subject.merge!(AppOptics::Metrics::Aggregator.new)
|
307
307
|
expect(subject.empty?).to be true
|
308
308
|
end
|
309
309
|
end
|
@@ -321,7 +321,7 @@ module Appoptics
|
|
321
321
|
|
322
322
|
context "when there are no metrics" do
|
323
323
|
it "it does not persist and returns true" do
|
324
|
-
subject.merge!(
|
324
|
+
subject.merge!(AppOptics::Metrics::Aggregator.new)
|
325
325
|
subject.persister.return_value(false)
|
326
326
|
expect(subject.submit).to be true
|
327
327
|
end
|
@@ -330,8 +330,8 @@ module Appoptics
|
|
330
330
|
|
331
331
|
describe "#last_submit_time" do
|
332
332
|
before(:all) do
|
333
|
-
|
334
|
-
|
333
|
+
AppOptics::Metrics.authenticate 'me@Appoptics.com', 'foo'
|
334
|
+
AppOptics::Metrics.persistence = :test
|
335
335
|
end
|
336
336
|
|
337
337
|
it "defaults to nil" do
|
@@ -537,8 +537,8 @@ module Appoptics
|
|
537
537
|
|
538
538
|
describe "#submit" do
|
539
539
|
before(:all) do
|
540
|
-
|
541
|
-
|
540
|
+
AppOptics::Metrics.authenticate 'me@Appoptics.com', 'foo'
|
541
|
+
AppOptics::Metrics.persistence = :test
|
542
542
|
end
|
543
543
|
|
544
544
|
context "when successful" do
|
data/spec/unit/metrics_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module AppOptics
|
4
4
|
|
5
5
|
describe Metrics do
|
6
6
|
|
@@ -40,10 +40,10 @@ module Appoptics
|
|
40
40
|
|
41
41
|
describe "#submit" do
|
42
42
|
before(:all) do
|
43
|
-
|
44
|
-
|
43
|
+
AppOptics::Metrics.persistence = :test
|
44
|
+
AppOptics::Metrics.authenticate 'me@AppOptics.com', 'foo'
|
45
45
|
end
|
46
|
-
after(:all) {
|
46
|
+
after(:all) { AppOptics::Metrics.client.flush_authentication }
|
47
47
|
|
48
48
|
it "persists metrics immediately" do
|
49
49
|
Metrics.persistence = :test
|
@@ -52,9 +52,9 @@ module Appoptics
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "tolerates multiple metrics" do
|
55
|
-
expect {
|
55
|
+
expect { AppOptics::Metrics.submit foo: 123, bar: 456 }.not_to raise_error
|
56
56
|
expected = {gauges: [{name: 'foo', value: 123}, {name: 'bar', value: 456}]}
|
57
|
-
expect(
|
57
|
+
expect(AppOptics::Metrics.persister.persisted).to equal_unordered(expected)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appoptics-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg McKeever
|
@@ -9,23 +9,23 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain:
|
12
|
-
- certs/
|
13
|
-
date: 2017-10-
|
12
|
+
- certs/librato-public.pem
|
13
|
+
date: 2017-10-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '0.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
28
|
+
version: '0.7'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: aggregate
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- spec/unit/metrics_spec.rb
|
96
96
|
homepage: https://github.com/AppOptics/appoptics-api-ruby
|
97
97
|
licenses:
|
98
|
-
- BSD
|
98
|
+
- BSD-3-Clause
|
99
99
|
metadata: {}
|
100
100
|
post_install_message:
|
101
101
|
rdoc_options: []
|