memtrics 0.0.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/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +127 -0
- data/Rakefile +2 -0
- data/lib/memtrics.rb +5 -0
- data/lib/memtrics/version.rb +3 -0
- data/memtrics.gemspec +26 -0
- metadata +133 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3@memtrics --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,127 @@
|
|
1
|
+
# Memtrics
|
2
|
+
|
3
|
+
Accepts, summarizes, and stores continuous metrics updates to a
|
4
|
+
memcache-compatible service. Answers queries in constant time.
|
5
|
+
|
6
|
+
We assume that the cache is large, and data is only lost due to expiration.
|
7
|
+
Couchbase makes an ideal backing store.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Follow the instructions at https://github.com/couchbase/couchbase-ruby-client
|
12
|
+
to install the couchbase gem.
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'memtrics'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install memtrics
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
# Pick one...
|
29
|
+
m = Memtrics.dalli(['localhost:11211:10', 'cache-2.:11211:5'])
|
30
|
+
|
31
|
+
m = Memtrics.couchbase(:hostname => "localhost")
|
32
|
+
|
33
|
+
# Configure...
|
34
|
+
m.ttl_of_hours = 31_556_926 # 1 year, default
|
35
|
+
m.ttl_of_minutes = 86_400 # 24 hours, default
|
36
|
+
m.ttl_of_group_members = 7200 # 2 hours, default
|
37
|
+
m.list_threshold = 1000 # default
|
38
|
+
|
39
|
+
# (Suppose that the current time is 17:05 UTC on April 13, 2012.)
|
40
|
+
|
41
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
42
|
+
{:user => 'joe', :ip => '10.20.30.40'})
|
43
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
44
|
+
{:user => 'bob', :ip => '10.20.30.40'})
|
45
|
+
m.counter(:when => Time.now, :metric => "logins", :where =>
|
46
|
+
{:user => 'joe', :ip => '10.20.30.50'})
|
47
|
+
|
48
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 340, :where =>
|
49
|
+
{:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
|
50
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 501, :where =>
|
51
|
+
{:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
|
52
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 212, :where =>
|
53
|
+
{:page => '/welcome/', :session_id => "h0zhmb1c-u1xfgw305e"})
|
54
|
+
m.measure(:when => Time.now, :metric => "load_time", :value => 343, :where =>
|
55
|
+
{:page => '/welcome/', :session_id => "h0zhmb2q-643dotlcgd"})
|
56
|
+
|
57
|
+
# Now we can query...
|
58
|
+
|
59
|
+
m.count(:when => "2012-04-13-17", :metric => "logins")
|
60
|
+
=> 3
|
61
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :list => :user)
|
62
|
+
=> ['joe', 'bob']
|
63
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe'})
|
64
|
+
=> 2
|
65
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'bob'})
|
66
|
+
=> 1
|
67
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe'}, :list => :ip)
|
68
|
+
=> ['10.20.30.40', '10.20.30.50']
|
69
|
+
m.list(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'bob'}, :list => :ip)
|
70
|
+
=> ['10.20.30.40']
|
71
|
+
m.count(:when => "2012-04-13-17", :metric => "logins", :where => {:user => 'joe', :ip => '10.20.30.40'})
|
72
|
+
=> 1
|
73
|
+
|
74
|
+
m.count(:when => "2012-04-13-17", :metric => "load_time")
|
75
|
+
=> 4
|
76
|
+
m.sum(:when => "2012-04-13-17", :metric => "load_time")
|
77
|
+
=> 1396
|
78
|
+
m.average(:when => "2012-04-13-17", :metric => "load_time")
|
79
|
+
=> 349.0
|
80
|
+
m.maximum(:when => "2012-04-13-17", :metric => "load_time")
|
81
|
+
=> 501
|
82
|
+
m.minimum(:when => "2012-04-13-17", :metric => "load_time")
|
83
|
+
=> 212
|
84
|
+
m.stddev(:when => "2012-04-13-17", :metric => "load_time")
|
85
|
+
=> 102.45730818248154
|
86
|
+
m.list(:when => "2012-04-13-17", :metric => "load_time", :list => :page)
|
87
|
+
=> ['/welcome/']
|
88
|
+
|
89
|
+
# We can do queries related to groups as well, with some limitations.
|
90
|
+
# We only guarantee the accuracy of the result if all related data was
|
91
|
+
# loaded from start-to-finish within :ttl_of_group_members seconds.
|
92
|
+
# Note: a range is the difference between the minimum and maximum metric,
|
93
|
+
# for an individual group.
|
94
|
+
m.count_of_groups(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
95
|
+
=> 2
|
96
|
+
m.sum_of_ranges(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
97
|
+
=> 286
|
98
|
+
m.average_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
99
|
+
=> 143
|
100
|
+
m.maximum_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
101
|
+
=> 158
|
102
|
+
m.minimum_range(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
103
|
+
=> 128
|
104
|
+
m.stddev_of_ranges(:when => "2012-04-13-17", :metric => "load_time", :group => :session_id)
|
105
|
+
=> 15.0
|
106
|
+
|
107
|
+
|
108
|
+
# Supposing there were instead millions of counter and measure operations,
|
109
|
+
# Memtrics may reach its list_threshold. Some queries will fail.
|
110
|
+
|
111
|
+
m.list(:page, "2012-04-13-17", "load_time")
|
112
|
+
=> ['/welcome/', '/projects/']
|
113
|
+
|
114
|
+
m.list(:session_id, "2012-04-13-17", "load_time")
|
115
|
+
Memtrics::DataLossError: Too many session_id for "2012-04-13-17", "load_time".
|
116
|
+
|
117
|
+
m.estimated_list_size(:session_id, "2012-04-13-17", "load_time")
|
118
|
+
=> 3560831
|
119
|
+
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
1. Fork it
|
124
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
125
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
126
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
127
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/memtrics.rb
ADDED
data/memtrics.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/memtrics/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Chris Johnson"]
|
6
|
+
gem.email = ["chris@kindkid.com"]
|
7
|
+
gem.description = "Accepts, summarizes, and stores continuous metrics updates to a memcache-compatible service. Answers queries in constant time."
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "https://github.com/kindkid/memtrics"
|
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 = "memtrics"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Memtrics::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,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: memtrics
|
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: &70321533255540 !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: *70321533255540
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70321533254760 !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: *70321533254760
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: simplecov
|
38
|
+
requirement: &70321533254060 !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: *70321533254060
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rb-fsevent
|
49
|
+
requirement: &70321533253400 !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: *70321533253400
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard
|
60
|
+
requirement: &70321533252780 !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: *70321533252780
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-bundler
|
71
|
+
requirement: &70321533252100 !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: *70321533252100
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-rspec
|
82
|
+
requirement: &70321533251460 !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: *70321533251460
|
91
|
+
description: Accepts, summarizes, and stores continuous metrics updates to a memcache-compatible
|
92
|
+
service. Answers queries in constant time.
|
93
|
+
email:
|
94
|
+
- chris@kindkid.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- .rvmrc
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- lib/memtrics.rb
|
106
|
+
- lib/memtrics/version.rb
|
107
|
+
- memtrics.gemspec
|
108
|
+
homepage: https://github.com/kindkid/memtrics
|
109
|
+
licenses: []
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.8.10
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Accepts, summarizes, and stores continuous metrics updates to a memcache-compatible
|
132
|
+
service. Answers queries in constant time.
|
133
|
+
test_files: []
|