memcache-client-stats 1.0.0 → 1.1.0
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/CHANGELOG +6 -2
- data/README +38 -2
- data/Rakefile +1 -1
- data/lib/memcache_server.rb +9 -3
- data/lib/memcache_stats.rb +26 -6
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -76,8 +76,39 @@ You can then query the cluster for the stats. You can request all the stats for
|
|
76
76
|
|
77
77
|
Or you can request a single stat from all servers:
|
78
78
|
|
79
|
-
>> CACHE.stats('bytes')
|
79
|
+
>> CACHE.stats(:key => 'bytes')
|
80
80
|
=> {"192.168.0.53:11211" = >"211985845", "192.168.0.50:11211" => "210776435"}
|
81
|
+
|
82
|
+
You can also specify which type of stats you'd like to receive:
|
83
|
+
|
84
|
+
>> CACHE.stats(:type => 'items')
|
85
|
+
=> {"192.168.0.100:11211" =>
|
86
|
+
{"fastbin_space"=>"0",
|
87
|
+
"mmapped_space"=>"233046016",
|
88
|
+
"releasable_space"=>"1504",
|
89
|
+
"arena_size"=>"1724416",
|
90
|
+
"mmapped_regions"=>"224",
|
91
|
+
"fastbin_blocks"=>"0",
|
92
|
+
"total_free"=>"446832",
|
93
|
+
"free_chunks"=>"33",
|
94
|
+
"total_alloc"=>"1277584",
|
95
|
+
"max_total_alloc"=>"0"
|
96
|
+
},
|
97
|
+
"192.168.0.101:11211" =>
|
98
|
+
{"fastbin_space"=>"0",
|
99
|
+
"mmapped_space"=>"215797760",
|
100
|
+
"releasable_space"=>"3920",
|
101
|
+
"arena_size"=>"1781760",
|
102
|
+
"mmapped_regions"=>"205",
|
103
|
+
"fastbin_blocks"=>"0",
|
104
|
+
"total_free"=>"209200",
|
105
|
+
"free_chunks"=>"28",
|
106
|
+
"total_alloc"=>"1572560",
|
107
|
+
"max_total_alloc"=>"0"
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
Valid stat types (besides the default): slabs malloc items
|
81
112
|
|
82
113
|
You can also have the client summarize the statistic across the cluster:
|
83
114
|
|
@@ -85,6 +116,11 @@ You can also have the client summarize the statistic across the cluster:
|
|
85
116
|
=> 2114039
|
86
117
|
>> CACHE.summed_stat('bytes') / 1.megabyte
|
87
118
|
=> 403
|
119
|
+
|
120
|
+
This works with an optional second parameter specifying the type, as well:
|
121
|
+
|
122
|
+
>> CACHE.summed_stat('arena_size', 'malloc')
|
123
|
+
=> 5177344
|
88
124
|
|
89
125
|
=== Using memcache-client-stats with Rails
|
90
126
|
|
@@ -96,4 +132,4 @@ You can configure Rails to use memcache-client by adding the following to config
|
|
96
132
|
require 'memcache_client_stats'
|
97
133
|
CACHE = MemCache.load_config("#{RAILS_ROOT}/config/memcache.yml")
|
98
134
|
config.action_controller.session_store = :mem_cache_store
|
99
|
-
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.merge! :cache => CACHE
|
135
|
+
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.merge! :cache => CACHE
|
data/Rakefile
CHANGED
data/lib/memcache_server.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class MemCache
|
2
|
+
STAT_TYPES = %w[items malloc slabs]
|
3
|
+
|
2
4
|
# Extends the MemCache::Server object so that is is able to request stats.
|
3
5
|
class Server
|
4
6
|
# Returns a unique key for the server.
|
@@ -12,12 +14,16 @@ class MemCache
|
|
12
14
|
end
|
13
15
|
|
14
16
|
# Returns a hash of <tt>{stat_key => value, ...}</tt> for all of the Server stats.
|
15
|
-
def stats
|
17
|
+
def stats(type = nil)
|
18
|
+
unless type.nil? || STAT_TYPES.include?(type)
|
19
|
+
raise MemCacheError, "Not a valid stat type. Valid stat types are: #{STAT_TYPES * ', '}"
|
20
|
+
end
|
21
|
+
|
16
22
|
sock = socket!
|
17
23
|
|
18
24
|
stats = {}
|
19
25
|
begin
|
20
|
-
sock.write "stats\r\n"
|
26
|
+
sock.write "stats#{type ? ' ' + type : nil}\r\n"
|
21
27
|
|
22
28
|
# Loop through the status which are sent back in the format of:
|
23
29
|
# STAT <name> <value>\r\n
|
@@ -37,4 +43,4 @@ class MemCache
|
|
37
43
|
stats
|
38
44
|
end
|
39
45
|
end
|
40
|
-
end
|
46
|
+
end
|
data/lib/memcache_stats.rb
CHANGED
@@ -1,18 +1,36 @@
|
|
1
1
|
class MemCache
|
2
2
|
# Creates a hash for the stat(s) for all of the active servers.
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# By default, the returned hash will be in the form of
|
5
5
|
# <tt>{server1 => {stat_key => value, ...}, server2 => {stat_key => value, ...}, ...}</tt>
|
6
6
|
# for all of the servers and stats.
|
7
7
|
#
|
8
|
-
#
|
8
|
+
# Stats accepts a hash of optional arguments:
|
9
|
+
#
|
10
|
+
# If <tt>:key</tt> is not <tt>nil</tt> then the returned hash will be in the form of
|
9
11
|
# <tt>{server1 => value, server2 => value, ...}</tt> for all servers for the single requested stat.
|
10
|
-
|
12
|
+
#
|
13
|
+
# i.e. <tt>CACHE.stats(:key => 'bytes')</tt>
|
14
|
+
#
|
15
|
+
# If <tt>:type</tt> is not <tt>nil</tt>, the passed <tt>stats</tt> type will be returned as a hash.
|
16
|
+
#
|
17
|
+
# i.e. <tt>CACHE.stats(:type => 'slabs')</tt>
|
18
|
+
#
|
19
|
+
# Valid <tt>:type</tt> options are: slabs malloc items
|
20
|
+
#
|
21
|
+
# _Deprecation_ _notice_: if <tt>options</tt> is not a hash then it will be used as the key.
|
22
|
+
# Please note that this usage is considered deprecated and will possibily be removed in future versions.
|
23
|
+
#
|
24
|
+
# i.e. <tt>CACHE.stats('bytes')</tt>
|
25
|
+
def stats(options = {})
|
11
26
|
stats = {}
|
12
27
|
|
28
|
+
key = options.is_a?(Hash) ? options[:key] : options
|
29
|
+
type = options[:type] if options.is_a?(Hash)
|
30
|
+
|
13
31
|
@mutex.synchronize do
|
14
32
|
raise MemCacheError, "No active servers" unless self.active?
|
15
|
-
@servers.each {|server| stats[server.key] = server.stats}
|
33
|
+
@servers.each {|server| stats[server.key] = server.stats(type)}
|
16
34
|
end
|
17
35
|
|
18
36
|
unless key.nil?
|
@@ -26,7 +44,9 @@ class MemCache
|
|
26
44
|
|
27
45
|
# Returns a summed value for the requested stat. This is useful for determining things such
|
28
46
|
# as the global number of <tt>curr_items</tt> or <tt>bytes</tt>.
|
29
|
-
|
30
|
-
|
47
|
+
#
|
48
|
+
# Can optionally be passed a <tt>type</tt> as a second parameter.
|
49
|
+
def summed_stat(key, type = nil)
|
50
|
+
stats({:key => key, :type => type}).values.inject(0) {|sum, value| sum + value.to_i}
|
31
51
|
end
|
32
52
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: memcache-client-stats
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2006-07-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2006-07-06 00:00:00 -07:00
|
8
8
|
summary: Query MemCache server stats through memcache-client
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -31,10 +31,10 @@ files:
|
|
31
31
|
- COPYING
|
32
32
|
- README
|
33
33
|
- Rakefile
|
34
|
-
- lib/memcache_stats.rb
|
35
|
-
- lib/memcache_client_stats.rb
|
36
34
|
- lib/memcache_config.rb
|
37
35
|
- lib/memcache_server.rb
|
36
|
+
- lib/memcache_stats.rb
|
37
|
+
- lib/memcache_client_stats.rb
|
38
38
|
- CHANGELOG
|
39
39
|
test_files: []
|
40
40
|
|