copperegg-revealmetrics 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Users/reto/Projects/copperegg-revealmetrics/CHANGELOG.md +4 -0
- data/Users/reto/Projects/copperegg-revealmetrics/README.md +49 -14
- data/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg.rb +1 -0
- data/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/mixins/persistence.rb +11 -1
- data/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/tag.rb +94 -0
- data/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/ver.rb +1 -1
- data/Users/reto/Projects/copperegg-revealmetrics/pkg/copperegg-revealmetrics-0.6.2.gem +0 -0
- data/Users/reto/Projects/copperegg-revealmetrics/pkg/copperegg-revealmetrics-0.7.0.gem +0 -0
- data/Users/reto/Projects/copperegg-revealmetrics/test/tag_test.rb +59 -0
- data/test/tag_test.rb +59 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46b48e05cc03369a33465d7a7bf15b5d0c5ad2f6
|
4
|
+
data.tar.gz: b0e7abe6d5914abeac84f090125ef2d84df7d48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0d773616060d88966044830bbce56ac47cb487be77fe7c017d545bc34b6599a34651f0f7fad12cbcb8fa87915e1393e9df779dec4b579f14434d4adfd7ef61f
|
7
|
+
data.tar.gz: e9521b6fef6bf58a6e8ba41d974dcf18c7ac039b453ceb90ac98bebb8b3a95187ec436ae3d215037d9944b2bb7690ea7c853cf4c20710a6e963f74d03f03cf8f
|
@@ -4,22 +4,22 @@ This gem allows programmatic access to the CopperEgg Revealmetrics API.
|
|
4
4
|
|
5
5
|
This is a fork of the [official client](https://github.com/CopperEgg/copperegg-ruby), adding additional functionality.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Getting Started
|
8
8
|
|
9
|
+
Install with ruby gems:
|
9
10
|
```
|
10
11
|
gem install copperegg-revealmetrics
|
11
12
|
```
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
### Setup
|
16
|
-
|
14
|
+
Set up your API key:
|
17
15
|
``` ruby
|
18
16
|
require 'copperegg-revealmetrics'
|
19
17
|
CopperEgg::Api.apikey = "sdf87xxxxxxxxxxxxxxxxxxxxx" # from the web UI
|
20
18
|
```
|
21
19
|
|
22
|
-
|
20
|
+
## Metric Groups
|
21
|
+
|
22
|
+
#### Get a metric group:
|
23
23
|
|
24
24
|
``` ruby
|
25
25
|
metric_group = CopperEgg::MetricGroup.find("my_metric_group")
|
@@ -31,7 +31,7 @@ metric_group.metrics
|
|
31
31
|
# => [#<CopperEgg::MetricGroup::Metric:0x007fb43aab2570 @position=0, @type="ce_gauge", @name="metric1", @label="Metric 1", @unit="b">]
|
32
32
|
```
|
33
33
|
|
34
|
-
|
34
|
+
#### Create a metric group:
|
35
35
|
|
36
36
|
``` ruby
|
37
37
|
metric_group = CopperEgg::MetricGroup.new(:name => "my_new_metric_group", :label => "Cool New Group Visible Name", :frequency => 60) # data is sent every 60 seconds
|
@@ -56,7 +56,7 @@ metric_group2.name
|
|
56
56
|
# => "my_metric_group"
|
57
57
|
```
|
58
58
|
|
59
|
-
|
59
|
+
#### Update a metric group:
|
60
60
|
|
61
61
|
Labels, frequency, metric types and metric units can be updated and additional metrics can be added. Changes to the metric group name or names of metrics within will be ignored.
|
62
62
|
|
@@ -75,20 +75,21 @@ metric_group.frequency
|
|
75
75
|
# => 5
|
76
76
|
```
|
77
77
|
|
78
|
-
|
78
|
+
#### Delete a metric group
|
79
79
|
|
80
80
|
```ruby
|
81
81
|
metric_group.delete
|
82
82
|
```
|
83
83
|
|
84
|
+
## Samples
|
84
85
|
|
85
|
-
|
86
|
+
#### Post samples for a metric group
|
86
87
|
|
87
88
|
```ruby
|
88
89
|
CopperEgg::MetricSample.save(metric_group.name, "custom_identifier1", Time.now.to_i, "active_connections" => 2601, "connections_accepts" => 154, "connections_handled" => 128, "connections_requested" => 1342, ...)
|
89
90
|
```
|
90
91
|
|
91
|
-
|
92
|
+
#### Get samples
|
92
93
|
|
93
94
|
```ruby
|
94
95
|
# Get the most recent samples for a single metric
|
@@ -103,7 +104,9 @@ CopperEgg::MetricSample.samples(metric_group.name, ["connections_accepts", "conn
|
|
103
104
|
|
104
105
|
The raw JSON response is returned as specified in the [API docs][sample_docs].
|
105
106
|
|
106
|
-
|
107
|
+
## Dashboards
|
108
|
+
|
109
|
+
#### Create a dashboard from a metric group
|
107
110
|
|
108
111
|
By default, the dashboard created will be named "_MetricGroupLabel_ Dashboard" and will have one timeline widget per metric matching all sources.
|
109
112
|
|
@@ -136,13 +139,13 @@ You can limit the widgets created by metric.
|
|
136
139
|
dashboard = CopperEgg::CustomDashboard.create(metric_group, :name => "Cloud Servers", :identifiers => ["custom_identifier1", "custom_identifier2"], :metrics => ["reading", "writing", "waiting"])
|
137
140
|
```
|
138
141
|
|
139
|
-
|
142
|
+
#### Get a dashboard
|
140
143
|
|
141
144
|
```ruby
|
142
145
|
dashboard = CopperEgg::CustomDashboard.find_by_name("My Metric Group Dashboard")
|
143
146
|
```
|
144
147
|
|
145
|
-
|
148
|
+
#### Delete a dashboard
|
146
149
|
|
147
150
|
Dashboards can be deleted like metric groups:
|
148
151
|
|
@@ -150,6 +153,38 @@ Dashboards can be deleted like metric groups:
|
|
150
153
|
dashboard.delete
|
151
154
|
```
|
152
155
|
|
156
|
+
## Tags
|
157
|
+
|
158
|
+
#### Get all or specific tags
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
tags_list = CopperEgg::Tag.find
|
162
|
+
tag = CopperEgg::Tag.find_by_name("my-tag")
|
163
|
+
```
|
164
|
+
|
165
|
+
#### Create a tag
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
tag = CopperEgg::Tag.new({:name => "my-tag"})
|
169
|
+
tag.objects = ["object-identifier-1", "object-identifier-2"]
|
170
|
+
tag.save
|
171
|
+
```
|
172
|
+
|
173
|
+
#### Update a tag
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
tag.objects = ["object-identifier-1", "object-identifier-2", "object-identifier-3"]
|
177
|
+
tag.save
|
178
|
+
```
|
179
|
+
|
180
|
+
#### Delete a tag
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
tag.delete
|
184
|
+
```
|
185
|
+
|
186
|
+
|
187
|
+
|
153
188
|
## Questions / Problems?
|
154
189
|
|
155
190
|
There are more detailed examples in the [test classes][test_classes].
|
@@ -6,6 +6,7 @@ require File.dirname(__FILE__) + "/copperegg/mixins/persistence"
|
|
6
6
|
require File.dirname(__FILE__) + "/copperegg/metric_group"
|
7
7
|
require File.dirname(__FILE__) + "/copperegg/custom_dashboard"
|
8
8
|
require File.dirname(__FILE__) + "/copperegg/metric_sample"
|
9
|
+
require File.dirname(__FILE__) + "/copperegg/tag"
|
9
10
|
require File.dirname(__FILE__) + "/copperegg/api"
|
10
11
|
|
11
12
|
module CopperEgg
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module CopperEgg
|
2
2
|
class ValidationError < Exception; end
|
3
3
|
|
4
|
+
class HttpError < Exception; end
|
5
|
+
|
4
6
|
module Mixins
|
5
7
|
module Persistence
|
6
8
|
def self.included(klass)
|
@@ -34,7 +36,7 @@ module CopperEgg
|
|
34
36
|
|
35
37
|
def request(params={})
|
36
38
|
request_type = params.delete(:request_type)
|
37
|
-
raise "invalid type" if !%w(get post put delete).include?(request_type)
|
39
|
+
raise "invalid type `#{request_type}`" if !%w(get post put delete).include?(request_type)
|
38
40
|
id = params.delete(:id)
|
39
41
|
|
40
42
|
uri = id ? URI.parse("#{Api.uri}/#{self.resource_name}/#{id}.json") : URI.parse("#{Api.uri}/#{self.resource_name}.json")
|
@@ -57,6 +59,14 @@ module CopperEgg
|
|
57
59
|
response
|
58
60
|
end
|
59
61
|
|
62
|
+
def request_200(params={})
|
63
|
+
response = request(params)
|
64
|
+
unless response.code === "200"
|
65
|
+
raise HttpError.new("HTTP request failed with code `#{response.code}`: `#{response.body}`")
|
66
|
+
end
|
67
|
+
response
|
68
|
+
end
|
69
|
+
|
60
70
|
private
|
61
71
|
|
62
72
|
def resource(value)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module CopperEgg
|
2
|
+
class Tag
|
3
|
+
include CopperEgg::Mixins::Persistence
|
4
|
+
|
5
|
+
resource "tags"
|
6
|
+
|
7
|
+
attr_accessor :name, :objects
|
8
|
+
|
9
|
+
def load_attributes(attributes)
|
10
|
+
@objects_original = []
|
11
|
+
|
12
|
+
attributes.each do |name, value|
|
13
|
+
if name.to_s == "id"
|
14
|
+
@id = value
|
15
|
+
elsif !respond_to?("#{name}=")
|
16
|
+
next
|
17
|
+
elsif name.to_s == "objects"
|
18
|
+
@objects = value.map { |object| object["idv"].to_s.gsub(/\|$/, "") }
|
19
|
+
@objects_original = @objects.clone
|
20
|
+
else
|
21
|
+
send "#{name}=", value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
@name || @id
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
@error = nil
|
32
|
+
|
33
|
+
if self.name.nil? || self.name.to_s.strip.empty?
|
34
|
+
@error = "Name can't be blank."
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
38
|
+
if self.name.to_s.match(/[^\w-]/)
|
39
|
+
@error = "Name contains invalid characters."
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
|
43
|
+
if self.objects.nil? || self.objects.empty?
|
44
|
+
@error = "You must define at least one object."
|
45
|
+
return false
|
46
|
+
end
|
47
|
+
|
48
|
+
unless self.objects.kind_of?(Array)
|
49
|
+
@error = "Invalid objects field."
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
|
53
|
+
if self.objects.any? { |object| !object.kind_of?(String) }
|
54
|
+
@error = "Invalid object identifier."
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
def delete
|
62
|
+
self.class.request_200({:id => name, :request_type => "delete"})
|
63
|
+
end
|
64
|
+
|
65
|
+
def save
|
66
|
+
unless valid?
|
67
|
+
raise ValidationError.new(@error)
|
68
|
+
end
|
69
|
+
|
70
|
+
remove_objects(@objects_original - @objects)
|
71
|
+
add_objects(@objects - @objects_original)
|
72
|
+
@objects_original = @objects
|
73
|
+
end
|
74
|
+
|
75
|
+
def update
|
76
|
+
save
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_hash
|
80
|
+
{"tag" => name, "ids" => objects}
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def remove_objects(ids)
|
86
|
+
self.class.request_200({:id => name, :ids => ids, :request_type => "delete"}) unless ids.empty?
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_objects(ids)
|
90
|
+
self.class.request_200({:tag => name, :ids => ids, :request_type => "post"}) unless ids.empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "copperegg"
|
3
|
+
|
4
|
+
class TagTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_name_accessor_and_setter
|
7
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
8
|
+
|
9
|
+
assert_equal "my_tag", tag.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_save_should_fail_if_name_is_blank
|
13
|
+
tag = CopperEgg::Tag.new
|
14
|
+
|
15
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
16
|
+
assert_equal "Name can't be blank.", error.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_save_should_fail_if_name_contains_invalid_characters
|
20
|
+
tag = CopperEgg::Tag.new(:name => "my%%%tag")
|
21
|
+
|
22
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
23
|
+
assert_equal "Name contains invalid characters.", error.message
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_objects_accessor_and_setter
|
27
|
+
tag = CopperEgg::Tag.new(:name => "my_tag", :objects => [{"idv" => "obj1"}, {"idv" => "obj2"}])
|
28
|
+
|
29
|
+
assert_equal ["obj1", "obj2"], tag.objects
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_save_should_fail_if_no_objects_are_declared
|
33
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
34
|
+
|
35
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
36
|
+
assert_equal "You must define at least one object.", error.message
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_save_should_fail_if_objects_include_non_strings
|
40
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
41
|
+
tag.objects = ["obj1", 12323]
|
42
|
+
|
43
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
44
|
+
assert_equal "Invalid object identifier.", error.message
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_hash
|
48
|
+
tag = CopperEgg::Tag.new(:name => "test")
|
49
|
+
tag.objects = ["obj1", "obj2"]
|
50
|
+
|
51
|
+
assert tag.valid?
|
52
|
+
hash = tag.to_hash
|
53
|
+
|
54
|
+
assert_nil hash["id"]
|
55
|
+
assert_equal "test", hash["tag"]
|
56
|
+
assert_equal ["obj1", "obj2"], hash["ids"]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/test/tag_test.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "copperegg"
|
3
|
+
|
4
|
+
class TagTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_name_accessor_and_setter
|
7
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
8
|
+
|
9
|
+
assert_equal "my_tag", tag.name
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_save_should_fail_if_name_is_blank
|
13
|
+
tag = CopperEgg::Tag.new
|
14
|
+
|
15
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
16
|
+
assert_equal "Name can't be blank.", error.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_save_should_fail_if_name_contains_invalid_characters
|
20
|
+
tag = CopperEgg::Tag.new(:name => "my%%%tag")
|
21
|
+
|
22
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
23
|
+
assert_equal "Name contains invalid characters.", error.message
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_objects_accessor_and_setter
|
27
|
+
tag = CopperEgg::Tag.new(:name => "my_tag", :objects => [{"idv" => "obj1"}, {"idv" => "obj2"}])
|
28
|
+
|
29
|
+
assert_equal ["obj1", "obj2"], tag.objects
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_save_should_fail_if_no_objects_are_declared
|
33
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
34
|
+
|
35
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
36
|
+
assert_equal "You must define at least one object.", error.message
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_save_should_fail_if_objects_include_non_strings
|
40
|
+
tag = CopperEgg::Tag.new(:name => "my_tag")
|
41
|
+
tag.objects = ["obj1", 12323]
|
42
|
+
|
43
|
+
error = assert_raise(CopperEgg::ValidationError) { tag.save }
|
44
|
+
assert_equal "Invalid object identifier.", error.message
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_hash
|
48
|
+
tag = CopperEgg::Tag.new(:name => "test")
|
49
|
+
tag.objects = ["obj1", "obj2"]
|
50
|
+
|
51
|
+
assert tag.valid?
|
52
|
+
hash = tag.to_hash
|
53
|
+
|
54
|
+
assert_nil hash["id"]
|
55
|
+
assert_equal "test", hash["tag"]
|
56
|
+
assert_equal ["obj1", "obj2"], hash["ids"]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copperegg-revealmetrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Anderson
|
@@ -72,14 +72,19 @@ files:
|
|
72
72
|
- "/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/metric_group.rb"
|
73
73
|
- "/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/metric_sample.rb"
|
74
74
|
- "/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/mixins/persistence.rb"
|
75
|
+
- "/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/tag.rb"
|
75
76
|
- "/Users/reto/Projects/copperegg-revealmetrics/lib/copperegg/ver.rb"
|
76
77
|
- "/Users/reto/Projects/copperegg-revealmetrics/pkg/copperegg-revealmetrics-0.6.1.gem"
|
78
|
+
- "/Users/reto/Projects/copperegg-revealmetrics/pkg/copperegg-revealmetrics-0.6.2.gem"
|
79
|
+
- "/Users/reto/Projects/copperegg-revealmetrics/pkg/copperegg-revealmetrics-0.7.0.gem"
|
77
80
|
- "/Users/reto/Projects/copperegg-revealmetrics/test/custom_dashboard_test.rb"
|
78
81
|
- "/Users/reto/Projects/copperegg-revealmetrics/test/metric_group_test.rb"
|
79
82
|
- "/Users/reto/Projects/copperegg-revealmetrics/test/metric_sample_test.rb"
|
83
|
+
- "/Users/reto/Projects/copperegg-revealmetrics/test/tag_test.rb"
|
80
84
|
- test/custom_dashboard_test.rb
|
81
85
|
- test/metric_group_test.rb
|
82
86
|
- test/metric_sample_test.rb
|
87
|
+
- test/tag_test.rb
|
83
88
|
homepage: https://github.com/cargomedia/copperegg-revealmetrics
|
84
89
|
licenses:
|
85
90
|
- MIT
|
@@ -114,3 +119,4 @@ test_files:
|
|
114
119
|
- test/custom_dashboard_test.rb
|
115
120
|
- test/metric_group_test.rb
|
116
121
|
- test/metric_sample_test.rb
|
122
|
+
- test/tag_test.rb
|