metricstore 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +126 -0
- data/Rakefile +2 -0
- data/lib/metricstore.rb +5 -0
- data/lib/metricstore/base_client.rb +24 -0
- data/lib/metricstore/couchbase_client.rb +16 -0
- data/lib/metricstore/version.rb +3 -0
- data/metricstore.gemspec +26 -0
- metadata +134 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3@metricstore --create
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Chris Johnson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
# Metricstore
|
2
|
+
|
3
|
+
Metrics in a key-value store.
|
4
|
+
|
5
|
+
Accepts, summarizes, and stores continuous metrics updates to a key-value store.
|
6
|
+
Answers queries in constant time.
|
7
|
+
|
8
|
+
We assume that the backing key-value store is fast, durable, and supports TTL.
|
9
|
+
Initial implementation will use Couchbase.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Follow the instructions at https://github.com/couchbase/couchbase-ruby-client
|
14
|
+
to install the couchbase gem.
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'metricstore'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install metricstore
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
m = Metricstore.couchbase(:hostname => "localhost")
|
31
|
+
|
32
|
+
# Configure...
|
33
|
+
m.ttl_of_hours = 31_556_926 # 1 year, default
|
34
|
+
m.ttl_of_minutes = 86_400 # 24 hours, default
|
35
|
+
m.ttl_of_group_members = 7200 # 2 hours, default
|
36
|
+
m.list_threshold = 1000 # default
|
37
|
+
|
38
|
+
# (Suppose that the current time is 17:05 UTC on April 13, 2012.)
|
39
|
+
|
40
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
41
|
+
{:user => 'joe', :ip => '10.20.30.40'})
|
42
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
43
|
+
{:user => 'bob', :ip => '10.20.30.40'})
|
44
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
45
|
+
{:user => 'joe', :ip => '10.20.30.50'})
|
46
|
+
|
47
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 340, :where =>
|
48
|
+
{:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
|
49
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 501, :where =>
|
50
|
+
{:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
|
51
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 212, :where =>
|
52
|
+
{:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
|
53
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 343, :where =>
|
54
|
+
{:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
|
55
|
+
|
56
|
+
# Now we can query...
|
57
|
+
|
58
|
+
m.count(:when => "2012-04-13-17", :metric => "logins")
|
59
|
+
=> 3
|
60
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :list => :user)
|
61
|
+
=> ['joe', 'bob']
|
62
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe'})
|
63
|
+
=> 2
|
64
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'bob'})
|
65
|
+
=> 1
|
66
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe'}, :list => :ip)
|
67
|
+
=> ['10.20.30.40', '10.20.30.50']
|
68
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'bob'}, :list => :ip)
|
69
|
+
=> ['10.20.30.40']
|
70
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe', :ip => '10.20.30.40'})
|
71
|
+
=> 1
|
72
|
+
|
73
|
+
m.count(:when => "2012-04-13-17", :metric => "load_time")
|
74
|
+
=> 4
|
75
|
+
m.sum(:when => "2012-04-13-17", :metric => "load_time")
|
76
|
+
=> 1396
|
77
|
+
m.average(:when => "2012-04-13-17", :metric => "load_time")
|
78
|
+
=> 349.0
|
79
|
+
m.maximum(:when => "2012-04-13-17", :metric => "load_time")
|
80
|
+
=> 501
|
81
|
+
m.minimum(:when => "2012-04-13-17", :metric => "load_time")
|
82
|
+
=> 212
|
83
|
+
m.stddev(:when => "2012-04-13-17", :metric => "load_time")
|
84
|
+
=> 102.45730818248154
|
85
|
+
m.list(:when => "2012-04-13-17", :metric => "load_time", :list => :page)
|
86
|
+
=> ['/welcome/']
|
87
|
+
|
88
|
+
# We can do queries related to groups as well, with some limitations.
|
89
|
+
# We only guarantee the accuracy of the result if all related data was
|
90
|
+
# loaded from start-to-finish within :ttl_of_group_members seconds.
|
91
|
+
# Note: a range is the difference between the minimum and maximum metric,
|
92
|
+
# for an individual group.
|
93
|
+
m.count_of_groups(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
94
|
+
=> 2
|
95
|
+
m.sum_of_ranges(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
96
|
+
=> 286
|
97
|
+
m.average_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
98
|
+
=> 143
|
99
|
+
m.maximum_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
100
|
+
=> 158
|
101
|
+
m.minimum_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
102
|
+
=> 128
|
103
|
+
m.stddev_of_ranges(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
104
|
+
=> 15.0
|
105
|
+
|
106
|
+
|
107
|
+
# Supposing there were instead millions of counter and measure operations,
|
108
|
+
# metricstore may reach its list_threshold. Some queries will fail.
|
109
|
+
|
110
|
+
m.list(:page, "2012-04-13-17", "load_time")
|
111
|
+
=> ['/welcome/', '/projects/']
|
112
|
+
|
113
|
+
m.list(:session_id, "2012-04-13-17", "load_time")
|
114
|
+
metricstore::DataLossError: Too many session_id for "2012-04-13-17", "load_time".
|
115
|
+
|
116
|
+
m.estimated_list_size(:session_id, "2012-04-13-17", "load_time")
|
117
|
+
=> 3560831
|
118
|
+
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
1. Fork it
|
123
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
125
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
126
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/metricstore.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Metricstore
|
2
|
+
module BaseClient
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@ttl_of_hours = 31_556_926 # 1 year
|
6
|
+
@ttl_of_minutes = 86_400 # 24 hours
|
7
|
+
@ttl_of_group_members = 7200 # 2 hours
|
8
|
+
@list_threshold = 1000
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :ttl_of_hours
|
12
|
+
attr_accessor :ttl_of_minutes
|
13
|
+
attr_accessor :ttl_of_group_members
|
14
|
+
attr_accessor :list_threshold
|
15
|
+
|
16
|
+
def counter(args={})
|
17
|
+
#TODO
|
18
|
+
end
|
19
|
+
|
20
|
+
def measure(args={})
|
21
|
+
#TODO
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/metricstore.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/metricstore/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chris Johnson"]
|
6
|
+
gem.email = ["chris@kindkid.com"]
|
7
|
+
gem.description = "Metrics in a key-value store."
|
8
|
+
gem.summary = "Metrics in a key-value store. Accepts, summarizes, and stores continuous metrics updates to a key-value store. Answers queries in constant time."
|
9
|
+
gem.homepage = "https://github.com/kindkid/metricstore"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "metricstore"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Metricstore::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "couchbase", "~> 1.1.1"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", "~> 2.9.0"
|
21
|
+
gem.add_development_dependency "simplecov", "~> 0.6.1"
|
22
|
+
gem.add_development_dependency("rb-fsevent", "~> 0.9.1") if RUBY_PLATFORM =~ /darwin/i
|
23
|
+
gem.add_development_dependency "guard", "~> 1.0.1"
|
24
|
+
gem.add_development_dependency "guard-bundler", "~> 0.1.3"
|
25
|
+
gem.add_development_dependency "guard-rspec", "~> 0.7.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metricstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Johnson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: couchbase
|
16
|
+
requirement: &70120781282620 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70120781282620
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70120781281880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.9.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70120781281880
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: simplecov
|
38
|
+
requirement: &70120781281280 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70120781281280
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rb-fsevent
|
49
|
+
requirement: &70120781280640 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70120781280640
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard
|
60
|
+
requirement: &70120781279980 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.1
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70120781279980
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-bundler
|
71
|
+
requirement: &70120781279340 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.1.3
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70120781279340
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-rspec
|
82
|
+
requirement: &70120781278700 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.7.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70120781278700
|
91
|
+
description: Metrics in a key-value store.
|
92
|
+
email:
|
93
|
+
- chris@kindkid.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- .gitignore
|
99
|
+
- .rvmrc
|
100
|
+
- Gemfile
|
101
|
+
- LICENSE
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- lib/metricstore.rb
|
105
|
+
- lib/metricstore/base_client.rb
|
106
|
+
- lib/metricstore/couchbase_client.rb
|
107
|
+
- lib/metricstore/version.rb
|
108
|
+
- metricstore.gemspec
|
109
|
+
homepage: https://github.com/kindkid/metricstore
|
110
|
+
licenses: []
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 1.8.10
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Metrics in a key-value store. Accepts, summarizes, and stores continuous
|
133
|
+
metrics updates to a key-value store. Answers queries in constant time.
|
134
|
+
test_files: []
|