copperegg 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +19 -0
- data/README.md +79 -0
- data/Rakefile +2 -0
- data/copperegg.gemspec +26 -0
- data/examples/example.rb +19 -0
- data/lib/copperegg.rb +16 -0
- data/lib/copperegg/metrics.rb +79 -0
- data/lib/copperegg/util.rb +62 -0
- data/lib/copperegg/ver.rb +3 -0
- data/lib/test/test_copperegg.rb +0 -0
- data/pkg/copperegg-0.0.0.gem +0 -0
- data/pkg/copperegg-0.5.0.gem +0 -0
- metadata +98 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 CopperEgg Corporation.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# CopperEgg Gem
|
2
|
+
The CopperEgg gem allows programmatic access to the CopperEgg API.
|
3
|
+
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### Requirements
|
8
|
+
|
9
|
+
## Install
|
10
|
+
|
11
|
+
Via rubygems.org:
|
12
|
+
|
13
|
+
```
|
14
|
+
$ gem install copperegg-ruby
|
15
|
+
```
|
16
|
+
|
17
|
+
To build and install the development branch yourself from the latest source:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ git clone git@github.com:copperegg/copperegg-ruby.git
|
21
|
+
$ cd copperegg-ruby
|
22
|
+
$ git checkout develop
|
23
|
+
$ gem build copperegg.gemspec
|
24
|
+
$ gem install copperegg-{version}.gem
|
25
|
+
```
|
26
|
+
|
27
|
+
## Getting Started
|
28
|
+
|
29
|
+
### Setup
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
|
33
|
+
require 'copperegg'
|
34
|
+
|
35
|
+
# Get a Metrics object:
|
36
|
+
apikey = 'sdf87xxxxxxxxxxxxxxxxxxxxx' # from the web UI
|
37
|
+
metrics = CopperEgg::Metrics.new(apikey)
|
38
|
+
```
|
39
|
+
|
40
|
+
### Get a metrics group:
|
41
|
+
|
42
|
+
``` ruby
|
43
|
+
group_name = "my_new_metrics_group"
|
44
|
+
mg = metrics.metric_group(group_name)
|
45
|
+
```
|
46
|
+
|
47
|
+
### Create a metric group:
|
48
|
+
|
49
|
+
``` ruby
|
50
|
+
group_name = "this_is_a_new_group"
|
51
|
+
groupcfg = {}
|
52
|
+
groupcfg["name"] = group_name
|
53
|
+
groupcfg["label"] = "Cool New Group Visible Name"
|
54
|
+
groupcfg["frequency"] = "60" # data is sent every 60s
|
55
|
+
groupcfg["metrics"] = [{"type"=>"ce_gauge", "name"=>"active_connections", "unit"=>"Connections"},
|
56
|
+
{"type"=>"ce_gauge", "name"=>"connections_accepts", "unit"=>"Connections"},
|
57
|
+
{"type"=>"ce_gauge", "name"=>"connections_handled", "unit"=>"Connections"},
|
58
|
+
{"type"=>"ce_gauge", "name"=>"connections_requested", "unit"=>"Connections"},
|
59
|
+
{"type"=>"ce_gauge", "name"=>"reading", "unit"=>"Connections"},
|
60
|
+
{"type"=>"ce_gauge", "name"=>"writing", "unit"=>"Connections"},
|
61
|
+
{"type"=>"ce_gauge", "name"=>"waiting", "unit"=>"Connections"}
|
62
|
+
]
|
63
|
+
|
64
|
+
res = metrics.create_metric_group(group_name, groupcfg)
|
65
|
+
```
|
66
|
+
|
67
|
+
## Questions / Problems?
|
68
|
+
|
69
|
+
|
70
|
+
There are more detailed examples in the included [examples][examples]
|
71
|
+
directory.
|
72
|
+
|
73
|
+
Full [API docs][docs] are available.
|
74
|
+
|
75
|
+
[examples]:https://github.com/copperegg/copperegg-ruby/blob/master/examples
|
76
|
+
[docs]:http://dev.copperegg.com
|
77
|
+
|
78
|
+
## Copyright
|
79
|
+
Copyright 2012 CopperEgg - See LICENSE for details.
|
data/Rakefile
ADDED
data/copperegg.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require './lib/copperegg/ver'
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'copperegg'
|
5
|
+
s.version = CopperEgg::GEM_VERSION
|
6
|
+
s.author = 'Eric Anderson'
|
7
|
+
s.email = 'anderson@copperegg.com'
|
8
|
+
|
9
|
+
s.description = 'Library for using the CopperEgg REST API'
|
10
|
+
s.summary = 'Library for using the CopperEgg REST API'
|
11
|
+
s.homepage = 'http://github.com/copperegg/copperegg-ruby'
|
12
|
+
s.license = '???'
|
13
|
+
|
14
|
+
s.platform = Gem::Platform::RUBY
|
15
|
+
s.require_paths = %w[lib]
|
16
|
+
s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
|
17
|
+
s.test_files = Dir.glob("{test,spec,features}/*")
|
18
|
+
s.executables = Dir.glob("bin/*")
|
19
|
+
s.add_dependency('multi_json', '>= 1.3.0')
|
20
|
+
#...
|
21
|
+
|
22
|
+
#s.add_development_dependency 'rake', '~> 0.9.0'
|
23
|
+
|
24
|
+
#s.extra_rdoc_files = ['README.md', 'LICENSE']
|
25
|
+
s.rdoc_options = ['--line-numbers', '--inline-source', '--title', 'copperegg-ruby', '--main', 'README.md']
|
26
|
+
end
|
data/examples/example.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'copperegg'
|
4
|
+
require 'redis'
|
5
|
+
require 'getoptlong'
|
6
|
+
|
7
|
+
apikey = "asdadasdasd"
|
8
|
+
|
9
|
+
rm = CopperEgg::Metrics.new(apikey)
|
10
|
+
|
11
|
+
puts rm.apikey
|
12
|
+
|
13
|
+
metrics = {}
|
14
|
+
time = Time.now.to_i
|
15
|
+
|
16
|
+
rm.store(metrics, time, "my_group_name")
|
17
|
+
|
18
|
+
data = rm.samples(time-300, time, "my_group_name", "metric_foo")
|
19
|
+
|
data/lib/copperegg.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'copperegg/metrics'
|
2
|
+
require 'copperegg/util'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
API_VERSION = 'v2'
|
7
|
+
DEFAULTS = {
|
8
|
+
:apihost => 'https://api.copperegg.com',
|
9
|
+
:ssl_verify_peer => false,
|
10
|
+
#:ssl_ca_file => File.dirname(__FILE__) + '/../../../conf/cacert.pem',
|
11
|
+
:timeout => 10
|
12
|
+
}
|
13
|
+
|
14
|
+
module CopperEgg
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module CopperEgg
|
2
|
+
class Metrics
|
3
|
+
|
4
|
+
attr_accessor :apikey
|
5
|
+
|
6
|
+
def initialize(apikey, apihost=nil)
|
7
|
+
@apikey = apikey
|
8
|
+
@util = CopperEgg::Util.new(@apikey, "revealmetrics", apihost)
|
9
|
+
end
|
10
|
+
|
11
|
+
def store_sample(group_name, identifier, timestamp, metric_data)
|
12
|
+
return if identifier.nil?
|
13
|
+
return if group_name.nil?
|
14
|
+
return if timestamp.nil? || timestamp == 0
|
15
|
+
return if metric_data.nil?
|
16
|
+
|
17
|
+
payload = {}
|
18
|
+
payload["timestamp"] = timestamp
|
19
|
+
payload["identifier"] = identifier
|
20
|
+
payload["values"] = metric_data
|
21
|
+
|
22
|
+
response = @util.make_api_post_request("/samples/#{group_name}.json", @apikey, payload)
|
23
|
+
return
|
24
|
+
end
|
25
|
+
|
26
|
+
def samples(starttime, endtime, group_name, metricname)
|
27
|
+
samples = @util.make_api_get_request("/samples.json", @apikey, nil)
|
28
|
+
return samples
|
29
|
+
end
|
30
|
+
|
31
|
+
def metric_groups
|
32
|
+
# return an array of metric groups
|
33
|
+
mgroup = @util.make_api_get_request("/metric_groups.json", @apikey, nil)
|
34
|
+
return mgroup
|
35
|
+
end
|
36
|
+
|
37
|
+
def metric_group(group_name)
|
38
|
+
mgroup = @util.make_api_get_request("/metric_groups/#{group_name}.json", @apikey, nil)
|
39
|
+
return mgroup
|
40
|
+
end
|
41
|
+
|
42
|
+
def metric_names(group_name)
|
43
|
+
# return an array of metric names in a metric group
|
44
|
+
mgroup = self.metric_group(group_name)
|
45
|
+
if !mgroup.nil?
|
46
|
+
# go through each and add to array
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
puts "NOT YET IMPLEMENTED"
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_metric_group(group_name, group_definition)
|
54
|
+
response = @util.make_api_post_request("/metric_groups.json", @apikey, group_definition)
|
55
|
+
end
|
56
|
+
|
57
|
+
def dashboard(dashboard_name)
|
58
|
+
dashes = @util.make_api_get_request("/dashboards.json", @apikey, nil)
|
59
|
+
return nil if dashes.nil?
|
60
|
+
|
61
|
+
dashboards = JSON.parse(dashes.body)
|
62
|
+
dashboards.each do |dash|
|
63
|
+
if dash["name"] == dashboard_name
|
64
|
+
return dash
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def create_dashboard(dashcfg)
|
72
|
+
response = @util.make_api_post_request("/dashboards.json", @apikey, dashcfg)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module CopperEgg
|
4
|
+
class Util
|
5
|
+
|
6
|
+
attr_accessor :apikey
|
7
|
+
|
8
|
+
def initialize(apikey, product, apihost=nil)
|
9
|
+
@apikey = apikey
|
10
|
+
@product = product
|
11
|
+
if apihost
|
12
|
+
@apihost = apihost
|
13
|
+
else
|
14
|
+
@apihost = DEFAULTS[:apihost]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def make_api_get_request(api_cmd, apikey, params)
|
19
|
+
response = make_api_request("get", api_cmd, apikey, params)
|
20
|
+
return response
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_api_post_request(api_cmd, apikey, body)
|
24
|
+
response = make_api_request("post", api_cmd, apikey, body)
|
25
|
+
return response
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def make_uri(api_cmd)
|
31
|
+
return URI.parse("#{@apihost}/#{API_VERSION}/#{@product}#{api_cmd}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def make_api_request(type, api_cmd, apikey, params)
|
35
|
+
request = nil
|
36
|
+
uri = make_uri(api_cmd)
|
37
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
38
|
+
|
39
|
+
http.use_ssl = uri.scheme == 'https'
|
40
|
+
if !DEFAULTS[:ssl_verify_peer]
|
41
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
42
|
+
end
|
43
|
+
|
44
|
+
if type == "get"
|
45
|
+
uri.query = URI.encode_www_form(params) if !params.nil?
|
46
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
47
|
+
else
|
48
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
49
|
+
request.body = MultiJson.dump(params)
|
50
|
+
end
|
51
|
+
|
52
|
+
request.basic_auth(apikey, "U")
|
53
|
+
request["Content-Type"] = "application/json"
|
54
|
+
response = http.request(request)
|
55
|
+
if response.code != "200"
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
return response
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
File without changes
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: copperegg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Eric Anderson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-11-15 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: multi_json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Library for using the CopperEgg REST API
|
37
|
+
email: anderson@copperegg.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- ./copperegg.gemspec
|
46
|
+
- ./examples/example.rb
|
47
|
+
- ./Gemfile
|
48
|
+
- ./Gemfile.lock
|
49
|
+
- ./lib/copperegg/metrics.rb
|
50
|
+
- ./lib/copperegg/util.rb
|
51
|
+
- ./lib/copperegg/ver.rb
|
52
|
+
- ./lib/copperegg.rb
|
53
|
+
- ./lib/test/test_copperegg.rb
|
54
|
+
- ./LICENSE
|
55
|
+
- ./pkg/copperegg-0.0.0.gem
|
56
|
+
- ./pkg/copperegg-0.5.0.gem
|
57
|
+
- ./Rakefile
|
58
|
+
- ./README.md
|
59
|
+
homepage: http://github.com/copperegg/copperegg-ruby
|
60
|
+
licenses:
|
61
|
+
- ???
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --line-numbers
|
65
|
+
- --inline-source
|
66
|
+
- --title
|
67
|
+
- copperegg-ruby
|
68
|
+
- --main
|
69
|
+
- README.md
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.24
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Library for using the CopperEgg REST API
|
97
|
+
test_files: []
|
98
|
+
|