memcache_stat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Joel Watson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # MemcacheStat
2
+
3
+ This is Ruby library that fetches and wraps memcached stats output.
4
+
5
+ ## Usage
6
+
7
+ Usage is simple:
8
+
9
+ mcs = MemcacheStat.new
10
+ mcs.get_hits # => 2
11
+ mcs.total_connections # => 34
12
+
13
+ To refresh the statistics:
14
+
15
+ mcs.refresh!
16
+
17
+ By default, it connects to localhost:11211. If you need a different host or port:
18
+
19
+ mcs = MemcacheStat.new("1.2.3.4", "11222")
20
+
21
+ ## Copyright
22
+
23
+ Copyright (c) 2010 Joel Watson. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "memcache_stat"
8
+ gem.summary = %Q{Ruby library that fetches and wraps memcached stats output.}
9
+ gem.description = %Q{Ruby library that fetches and wraps memcached stats output.}
10
+ gem.email = "watsonian@gmail.com"
11
+ gem.homepage = "http://github.com/watsonian/memcache_stat"
12
+ gem.authors = ["watsonian"]
13
+ gem.add_dependency "memcache_do", ">= 0.1.1"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "memcache_stat #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'memcache_do'
3
+
4
+ class MemcacheStat
5
+ attr_accessor :hostname, # Hostname to connect with
6
+ :port, # Port to connect with
7
+ :raw, # Raw stats output from memcache
8
+ :pid, # 32u Process id of this server process
9
+ :uptime, # 32u Number of seconds this server has been running
10
+ :time, # 32u current UNIX time according to the server
11
+ :version, # string Version string of this server
12
+ :pointer_size, # 32 Default size of pointers on the host OS (generally 32 or 64)
13
+ :rusage_user, # 32u:32u Accumulated user time for this process (seconds:microseconds)
14
+ :rusage_system, # 32u:32u Accumulated system time for this process (seconds:microseconds)
15
+ :curr_items, # 32u Current number of items stored by the server
16
+ :total_items, # 32u Total number of items stored by this server ever since it started
17
+ :bytes, # 64u Current number of bytes used by this server to store items
18
+ :curr_connections, # 32u Number of open connections
19
+ :total_connections, # 32u Total number of connections opened since the server started running
20
+ :connection_structures, # 32u Number of connection structures allocated by the server
21
+ :cmd_get, # 64u Cumulative number of retrieval requests
22
+ :cmd_set, # 64u Cumulative number of storage requests
23
+ :get_hits, # 64u Number of keys that have been requested and found present
24
+ :get_misses, # 64u Number of items that have been requested and not found
25
+ :evictions, # 64u Number of valid items removed from cache to free memory for new items
26
+ :bytes_read, # 64u Total number of bytes read by this server from network
27
+ :bytes_written, # 64u Total number of bytes sent by this server to network
28
+ :limit_maxbytes, # 32u Number of bytes this server is allowed to use for storage.
29
+ :threads # 32u Number of worker threads requested. (see doc/threads.txt)
30
+
31
+ def initialize(hostname="localhost", port="11211")
32
+ @hostname, @port = hostname, port
33
+ refresh_raw_stats!
34
+ parse_stats(@raw)
35
+ end
36
+
37
+ def refresh!
38
+ refresh_raw_stats!
39
+ parse_stats(@raw)
40
+ true
41
+ end
42
+
43
+ private
44
+ def refresh_raw_stats!
45
+ @raw = MemcacheDo.exec("stats", @hostname, @port)
46
+ end
47
+
48
+ def parse_stats(raw_stats)
49
+ raw_stats.split("\r\n").each do |line|
50
+ begin
51
+ elements = line.split(" ")
52
+ unless elements.first == "END"
53
+ case elements[2]
54
+ when /[0-9]+\.[0-9]+$/
55
+ instance_variable_set("@#{elements[1]}".to_sym, elements[2].to_f)
56
+ when /[0-9]+$/
57
+ instance_variable_set("@#{elements[1]}".to_sym, elements[2].to_i)
58
+ else
59
+ instance_variable_set("@#{elements[1]}".to_sym, elements[2])
60
+ end
61
+ end
62
+ rescue => e
63
+ puts e
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{memcache_stat}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["watsonian"]
12
+ s.date = %q{2010-07-25}
13
+ s.description = %q{Ruby library that fetches and wraps memcached stats output.}
14
+ s.email = %q{watsonian@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/memcache_stat.rb",
27
+ "memcache_stat.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_memcache_stat.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/watsonian/memcache_stat}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{Ruby library that fetches and wraps memcached stats output.}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_memcache_stat.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<memcache_do>, [">= 0.1.1"])
47
+ else
48
+ s.add_dependency(%q<memcache_do>, [">= 0.1.1"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<memcache_do>, [">= 0.1.1"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ require 'memcache_stat'
7
+
8
+ class Test::Unit::TestCase
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMemcacheStat < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memcache_stat
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - watsonian
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-25 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: memcache_do
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 1
34
+ version: 0.1.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Ruby library that fetches and wraps memcached stats output.
38
+ email: watsonian@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.md
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/memcache_stat.rb
54
+ - memcache_stat.gemspec
55
+ - test/helper.rb
56
+ - test/test_memcache_stat.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/watsonian/memcache_stat
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Ruby library that fetches and wraps memcached stats output.
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/test_memcache_stat.rb