ciclope 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 ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ciclope.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,60 @@
1
+ Ciclope
2
+ =======
3
+
4
+ Simple utility to show the replication status for MySQL hots. Usefull to inspect seconds behind master status.
5
+
6
+ _NOTE: This gem depends on Rails and ActiveRecord as ORM._
7
+
8
+ Configuration
9
+ -------------
10
+
11
+ Only has to specify a array of two or more Rails database config names:
12
+
13
+ > Ciclope.connections = [:production, :production\_in\_aws, :production\_in\_other_location]
14
+
15
+ The ring will be auto-sorted guessing the master host for each connection, you could bypass this feature setting:
16
+
17
+ > Ciclope.auto\_sort\_connections = false
18
+
19
+ Use
20
+ ---
21
+
22
+ Actually there is one class methods to inspect replication data and one to show seconds behind master:
23
+
24
+ > Ciclope.replication\_status \# => returns a array of hashes with replication data
25
+
26
+ > Ciclope.replication\_seconds\_behind\_master # => returns a simple string with the host status like:
27
+
28
+ >> host1 ––– 0 seconds –––> host2 ––– 0 seconds –––> host3 ––– 0 seconds –––> host1
29
+
30
+ TODO
31
+ ----
32
+
33
+ Extend and refact in order to let work with others frameworks ruby based (Sinatra, Merb), and others ORMs (DataMapper).
34
+
35
+ Licence
36
+ -------
37
+
38
+ Copyright (c) 2011 Hugo Gerónimo Díaz
39
+
40
+ Permission is hereby granted, free of charge, to any
41
+ person obtaining a copy of this software and associated
42
+ documentation files (the "Software"), to deal in the
43
+ Software without restriction, including without limitation
44
+ the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the
46
+ Software, and to permit persons to whom the Software is
47
+ furnished to do so, subject to the following conditions:
48
+
49
+ The above copyright notice and this permission notice
50
+ shall be included in all copies or substantial portions of
51
+ the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
54
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
55
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
56
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
57
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
58
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
59
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/ciclope.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ciclope/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ciclope"
7
+ s.version = Ciclope::VERSION
8
+ s.authors = ["Hugo Geronimo Diaz"]
9
+ s.email = ["geronimod@gmail.com"]
10
+ s.homepage = "http://github.com/geronimod/ciclope"
11
+ s.summary = %q{Simple MySQL Replication Utility.}
12
+ s.description = %q{Simple utility to show the replication status for MySQL hots. Usefull to inspect sencond behind master status. This gem depends on Rails and ActiveRecord as ORM.}
13
+
14
+ s.rubyforge_project = "ciclope"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_dependency "rails"
24
+ s.add_dependency "activerecord"
25
+ # s.add_runtime_dependency "rest-client"
26
+ end
data/lib/ciclope.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "ciclope/ring"
2
+ require "ciclope/host"
3
+ require "ciclope/version"
4
+
5
+ module Ciclope
6
+
7
+ class << self
8
+ attr_accessor :connections, :auto_sort_connections
9
+ end
10
+ self.auto_sort_connections = true
11
+
12
+ def self.auto_sort?
13
+ auto_sort_connections
14
+ end
15
+
16
+ def self.ring
17
+ @ring ||= Ring.new(connections, :sort_hosts => auto_sort?)
18
+ end
19
+
20
+ def self.replication_status
21
+ ring.hosts.map &:status
22
+ end
23
+
24
+ def self.replication_seconds_behind_master
25
+ out = ring.hosts.map do |host|
26
+ host.name + " ––– #{host.seconds_behind_master} seconds –––> "
27
+ end
28
+ out << ring.hosts.first.name
29
+ out.join
30
+ end
31
+
32
+ end
@@ -0,0 +1,54 @@
1
+ module Ciclope
2
+ class Host
3
+ include Comparable
4
+
5
+ attr_reader :connection, :config
6
+
7
+ def initialize(connection)
8
+ @connection = connection
9
+ @config = @connection.instance_variable_get '@config'
10
+
11
+ # define every key as a method
12
+ status.keys.each do |m|
13
+ self.class.send :define_method, m.downcase do
14
+ status[m]
15
+ end
16
+ end
17
+ end
18
+
19
+ def name
20
+ @config[:host]
21
+ end
22
+
23
+ def status
24
+ @connection.select_one 'SHOW SLAVE STATUS'
25
+ end
26
+
27
+ def log_file
28
+ cleanfy_log_name relay_log_file.split('.').first
29
+ end
30
+
31
+ def master_log_file
32
+ cleanfy_log_name relay_master_log_file.split('.').first
33
+ end
34
+
35
+ # sort by log file names, there is no way to do this by host names, may be there is another way to do this more clean
36
+ # TODO: find the right sort
37
+ def <=>(other)
38
+ if log_file == other.master_log_file
39
+ 1
40
+ elsif other.log_file == master_log_file
41
+ -1
42
+ else
43
+ 0
44
+ end
45
+ end
46
+
47
+ private
48
+ def cleanfy_log_name(name)
49
+ name.gsub(/(binary|relay)log/i, '').
50
+ gsub(/[_\-\d]/, '')
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ module Ciclope
2
+ class Ring
3
+ class NotEnoughConnections < Exception
4
+ def message
5
+ "Connections must be more than once !"
6
+ end
7
+ end
8
+
9
+ attr_reader :hosts
10
+
11
+ def initialize(*args)
12
+ options = args.pop if args.last.is_a? Hash
13
+ options ||= {}
14
+ connections = Array(args).flatten.compact.uniq
15
+
16
+ raise NotEnoughConnections if connections.size < 2
17
+
18
+ @hosts = []
19
+
20
+ connections.each do |c|
21
+ config = Rails.configuration.database_configuration[c.to_s]
22
+ @hosts << Host.new(ActiveRecord::Base.mysql_connection(config)) if config
23
+ end
24
+
25
+ @hosts = @hosts.sort if options[:sort_hosts] && @hosts.count > 2
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Ciclope
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ciclope
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Hugo Geronimo Diaz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rails
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: activerecord
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :runtime
61
+ version_requirements: *id003
62
+ description: Simple utility to show the replication status for MySQL hots. Usefull to inspect sencond behind master status. This gem depends on Rails and ActiveRecord as ORM.
63
+ email:
64
+ - geronimod@gmail.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - Gemfile
74
+ - README.markdown
75
+ - Rakefile
76
+ - ciclope.gemspec
77
+ - lib/ciclope.rb
78
+ - lib/ciclope/host.rb
79
+ - lib/ciclope/ring.rb
80
+ - lib/ciclope/version.rb
81
+ homepage: http://github.com/geronimod/ciclope
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project: ciclope
110
+ rubygems_version: 1.8.12
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Simple MySQL Replication Utility.
114
+ test_files: []
115
+