activeslave 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --colour
3
+ --fail-fast
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-p194@activeslave --create
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeslave.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sreehari B
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.
@@ -0,0 +1,40 @@
1
+ # Activeslave
2
+
3
+ monitor mysql-slave, sends an email notification when slave stop working
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activeslave'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activeslave
18
+
19
+ ## Usage
20
+
21
+ Create Slave object
22
+ slave = Activeslave::Slave.new( "host" => "xxx.xxx.xx.xx",
23
+ "username" => "xxxxxx",
24
+ "password" => "xxxxxx",
25
+ "database" => "slavedb",
26
+ "socket" => "/var/run/mysqld/mysqld.sock",
27
+ "receiver_email" => "sreehari@activesphere.com")
28
+ Start monitor
29
+ slave.start_monitor
30
+
31
+ Stop monitor
32
+ slave.stop_monitor
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/activeslave/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sreehari B"]
6
+ gem.email = ["sreehari@activesphere.com"]
7
+ gem.description = %q{monitor mysql slave}
8
+ gem.summary = %q{monitor mysql slave}
9
+ gem.homepage = "https://github.com/sreehari/activeslave"
10
+
11
+ gem.add_development_dependency "rspec"
12
+ gem.add_development_dependency "mysql2"
13
+ gem.add_development_dependency "pony"
14
+ gem.add_development_dependency "rufus-scheduler"
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.name = "activeslave"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = Activeslave::VERSION
22
+ end
@@ -0,0 +1,9 @@
1
+ require "activeslave/version"
2
+ require "activeslave/slave"
3
+ require "mysql2"
4
+ require "pony"
5
+ require "rufus/scheduler"
6
+
7
+ module Activeslave
8
+
9
+ end
@@ -0,0 +1,60 @@
1
+ module Activeslave
2
+ class Slave
3
+ attr_reader :host, :username, :password, :reconnect, :database, :socket,
4
+ :slave_io_running, :slave_sql_running, :read_only, :scheduler
5
+
6
+ def initialize(options)
7
+ @receiver_email = options['receiver_email']
8
+ @host = options['host']
9
+ @username = options['username']
10
+ @password = options['password']
11
+ @database = options['database']
12
+ @reconnect = options['reconnect'] || true
13
+ @socket = options[socket] || '/var/run/mysqld/mysqld.sock'
14
+ end
15
+
16
+ def capture_status_values
17
+ slave_client = Mysql2::Client.new({
18
+ :host => @host,
19
+ :username => @username,
20
+ :password => @password,
21
+ :database => @database,
22
+ :reconnect => @reconnect,
23
+ :socket => @socket
24
+ })
25
+
26
+ data = slave_client.query("show slave status").first
27
+ @slave_io_running = data['Slave_IO_Running']
28
+ @slave_sql_running = data['Slave_SQL_Running']
29
+
30
+ global_variables = slave_client.query("show variables")
31
+ @read_only = global_variables.select{|variable| variable['Variable_name'] == 'read_only'}.first['Value']
32
+
33
+ {slave_io_running: slave_io_running, slave_sql_running: slave_sql_running, read_only: read_only}
34
+ end
35
+
36
+ def send_notification
37
+ Pony.mail :to => @receiver_email,
38
+ :subject => "Your Slave Not Working!",
39
+ :via => :sendmail
40
+ end
41
+
42
+ def not_working
43
+ @slave_io_running != "Yes" || @slave_sql_running != "Yes" || @read_only != "ON"
44
+ end
45
+
46
+ def start_monitor
47
+ @scheduler = Rufus::Scheduler.start_new
48
+
49
+ @scheduler.every '5m' do
50
+ capture_status_values
51
+
52
+ send_notification if not_working
53
+ end
54
+ end
55
+
56
+ def stop_monitor
57
+ @scheduler.stop
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Activeslave
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Activeslave::Slave do
5
+ before(:each) do
6
+ @slave = Activeslave::Slave.new DatabaseCredentials['slave']
7
+ end
8
+
9
+ it 'should capture the slave status' do
10
+ @slave.capture_status_values.should == {slave_io_running: 'No', slave_sql_running: 'Yes', read_only: 'OFF'}
11
+ end
12
+
13
+ describe 'start_monitor' do
14
+ it 'should notification when slave stop working' do
15
+ Pony.should_receive(:mail)
16
+ @slave.send_notification
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ slave:
2
+ host: 192.168.2.42
3
+ username: xxxxxx
4
+ password: xxxxxx
5
+ reconnect: true
6
+ database: slavedb
7
+ socket: /var/run/mysqld/mysqld.sock
8
+ receiver_email: sreehari@activesphere.com
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+ require 'activeslave'
5
+
6
+ DatabaseCredentials = YAML.load_file('spec/configuration.yml')
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeslave
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sreehari B
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2152161380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2152161380
25
+ - !ruby/object:Gem::Dependency
26
+ name: mysql2
27
+ requirement: &2152158580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2152158580
36
+ - !ruby/object:Gem::Dependency
37
+ name: pony
38
+ requirement: &2152157620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152157620
47
+ - !ruby/object:Gem::Dependency
48
+ name: rufus-scheduler
49
+ requirement: &2152156580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152156580
58
+ description: monitor mysql slave
59
+ email:
60
+ - sreehari@activesphere.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - .rvmrc
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - activeslave.gemspec
73
+ - lib/activeslave.rb
74
+ - lib/activeslave/slave.rb
75
+ - lib/activeslave/version.rb
76
+ - spec/activeslave/slave_spec.rb
77
+ - spec/configuration.yml
78
+ - spec/spec_helper.rb
79
+ homepage: https://github.com/sreehari/activeslave
80
+ licenses: []
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.10
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: monitor mysql slave
103
+ test_files:
104
+ - spec/activeslave/slave_spec.rb
105
+ - spec/configuration.yml
106
+ - spec/spec_helper.rb