newrelic-metrics 0.1.1 → 0.1.02
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/newrelic-metrics.rb +22 -30
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTVmYzIzNDc3NjgzY2YxMDUwYjEwMTExYzZlY2ZhMDk4OWQwNzE3Zg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1e93d230f6d6a209733c69528a2e5120b8902c50
|
4
|
+
data.tar.gz: a5937f809e815d91de92db1061a735c446a6c0e6
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MTQ2ZmFlNjkwMDdhN2I5N2M1ZDM4NjVkYzczZDZlMjc0NGRiYzU2MjlkYzRh
|
11
|
-
MDljZjE2Y2Q1OTk0NGFlNGZkYWEyNzM5MTk5NDE2ODYzYmUyNDU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NGI2M2E0MjExZTBiOTk1ZmIyOTM1ZWU1N2FkNzY3NjNhZGYyY2ZkYjFiMDM4
|
14
|
-
Y2ZjY2EwNGNkMjhlZmVhZWVlODQxOThlNTViNDQxZDU5ZjI1ZjljMDlhMWI2
|
15
|
-
MzFkZDE3ZGNkOTUzYzQ3Y2VkZGYzMGQ4ODQ1NTgxZDEyN2UwYWM=
|
6
|
+
metadata.gz: 599c589e7f4e854dabc8f47986cf1d086dc921f69d69a06ad5fe597d045815d700e65ad617e486dfbac5ebd659e65ae2587a412ea1907c8df66f09b14001cc8f
|
7
|
+
data.tar.gz: 5a84bc09a75b113f0227002e5236050b45e500e89daa27a1283721062e443baa37c17f4fe6191aae863d87fada046569333a11523264167953fb2348d064f225
|
data/lib/newrelic-metrics.rb
CHANGED
@@ -6,8 +6,8 @@ require 'chronic'
|
|
6
6
|
module NewRelicMetrics
|
7
7
|
class Configuration
|
8
8
|
attr_accessor :api_key
|
9
|
-
def initialize(
|
10
|
-
@api_key=
|
9
|
+
def initialize(api_key:nil,&block)
|
10
|
+
@api_key=api_key
|
11
11
|
yield(self) if block
|
12
12
|
end
|
13
13
|
end
|
@@ -30,41 +30,33 @@ module NewRelicMetrics
|
|
30
30
|
def initialize(config=nil)
|
31
31
|
@config = config || NewRelicMetrics.configuration
|
32
32
|
|
33
|
-
raise ArgumentError
|
33
|
+
raise ArgumentError, "No API Key is configured" unless @config && @config.api_key
|
34
34
|
end
|
35
35
|
|
36
|
-
def names(
|
37
|
-
application
|
38
|
-
server
|
39
|
-
raise ArgumentError.new("Need to define either an application or server id") unless application || server
|
40
|
-
raise ArgumentError.new("Need to define either an application or server id, but not both") if application && server
|
36
|
+
def names(application:nil, server:nil)
|
37
|
+
raise ArgumentError, "Need to define either an application or server id" unless application || server
|
38
|
+
raise ArgumentError, "Need to define either an application or server id, but not both" if application && server
|
41
39
|
resource = application ? 'applications' : 'servers'
|
42
40
|
resource_id = application || server
|
43
41
|
get(resource, resource_id, "metrics")['metrics']
|
44
42
|
end
|
45
43
|
|
46
|
-
def metrics(
|
47
|
-
application = options[:application]
|
48
|
-
server = options[:server]
|
49
|
-
metrics = options[:metrics]
|
50
|
-
range = options[:range] || {}
|
51
|
-
summarize = options[:summarize] || false
|
52
|
-
|
53
|
-
raise ArgumentError.new("missing keyword: metrics") unless metrics
|
54
|
-
|
44
|
+
def metrics(application:nil, server:nil, metrics:, range:{}, summarize: false)
|
55
45
|
if range && range!={}
|
56
|
-
raise ArgumentError
|
57
|
-
raise ArgumentError
|
46
|
+
raise ArgumentError, "Range must only contain a :to and :from time" unless range.keys.all?{|k| k==:to || k==:from }
|
47
|
+
raise ArgumentError, "Range must contain a :from time" unless range.keys.include?(:from)
|
58
48
|
end
|
59
49
|
|
60
|
-
raise ArgumentError
|
61
|
-
raise ArgumentError
|
50
|
+
raise ArgumentError, "Need to define either an application or server id" unless application || server
|
51
|
+
raise ArgumentError, "Need to define either an application or server id, but not both" if application && server
|
52
|
+
|
53
|
+
raise ArgumentError, "Metrics must be set" if !metrics || metrics=={}
|
54
|
+
raise ArgumentError, "Metrics must be an hash" unless metrics.is_a?(Hash)
|
55
|
+
raise ArgumentError, "Metric keys must be string" unless metrics.keys.all?{|k| k.is_a?(String)}
|
56
|
+
raise ArgumentError, "Metric values must be arrays" unless metrics.values.all?{|k| k.is_a?(Array)}
|
57
|
+
raise ArgumentError, "Metric values must be an array of strings" unless metrics.values.all?{|k| k.all?{|v| v.is_a?(String)} }
|
58
|
+
|
62
59
|
|
63
|
-
raise ArgumentError.new("Metrics must be set") if !metrics || metrics=={}
|
64
|
-
raise ArgumentError.new("Metrics must be an hash") unless metrics.is_a?(Hash)
|
65
|
-
raise ArgumentError.new("Metric keys must be string") unless metrics.keys.all?{|k| k.is_a?(String)}
|
66
|
-
raise ArgumentError.new("Metric values must be arrays") unless metrics.values.all?{|k| k.is_a?(Array)}
|
67
|
-
raise ArgumentError.new("Metric values must be an array of strings") unless metrics.values.all?{|k| k.all?{|v| v.is_a?(String)} }
|
68
60
|
|
69
61
|
resource = application ? 'applications' : 'servers'
|
70
62
|
resource_id = application || server
|
@@ -75,8 +67,8 @@ module NewRelicMetrics
|
|
75
67
|
metrics.values.flatten.each {|val| conditions << "values[]=#{URI.encode(val)}" }
|
76
68
|
|
77
69
|
if range[:from]
|
78
|
-
from_time =
|
79
|
-
to_time =
|
70
|
+
from_time = Chronic.parse(range[:from], context: :past)
|
71
|
+
to_time = Chronic.parse(range[:to]) if range[:to]
|
80
72
|
to_time ||= Time.now
|
81
73
|
if from_time
|
82
74
|
conditions << "from=#{from_time.getlocal('+00:00').iso8601}"
|
@@ -93,8 +85,8 @@ module NewRelicMetrics
|
|
93
85
|
private
|
94
86
|
|
95
87
|
def get(resource, resource_id, path, query=nil)
|
96
|
-
uri
|
97
|
-
uri.path
|
88
|
+
uri = URI.parse('https://api.newrelic.com/')
|
89
|
+
uri.path = "/v2/#{resource}/#{resource_id}/#{path}.json"
|
98
90
|
uri.query = query if query && query != ""
|
99
91
|
|
100
92
|
begin
|
metadata
CHANGED
@@ -1,99 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.02
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Skierkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.7.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.7.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: chronic
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.10.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.10.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.8.
|
47
|
+
version: 1.8.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.8.
|
54
|
+
version: 1.8.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: codeclimate-test-reporter
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.3.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.3.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.1.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.1.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 10.
|
89
|
+
version: 10.3.2
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 10.
|
96
|
+
version: 10.3.2
|
97
97
|
description:
|
98
98
|
email:
|
99
99
|
- maciej@factor.io
|
@@ -111,17 +111,17 @@ require_paths:
|
|
111
111
|
- lib
|
112
112
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- -
|
114
|
+
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
118
|
requirements:
|
119
|
-
- -
|
119
|
+
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.2.2
|
125
125
|
signing_key:
|
126
126
|
specification_version: 4
|
127
127
|
summary: Easily get metrics out of New Relic for your application or servers
|