panoptimon-collector-mysql_status 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE +29 -0
- data/README.md +11 -0
- data/bin/pancollect-mysql_status +53 -0
- data/example_configs/localhost.json +3 -0
- data/example_configs/remote.json +7 -0
- data/panoptimon-collector-mysql_status.gemspec +15 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 483190bb891141489d94cbf036b1c231945486dd
|
4
|
+
data.tar.gz: 5f0049416ad44ec2b72e0428cbc2cd7009d4c85c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0561e6be297f5e68e0e9d348d5ab04ec4c71df820e285a570d219f94d74c8ffc2af3702f76ad2efe38823dd106475e9acf56e9fb1131d50fba5813bca663985
|
7
|
+
data.tar.gz: 7ed5704fcb2d29402ff528d7f9c94b1f48cf8cbf0f4b3d1f9d70eb6b43e650930725118f32b6a9d6af707f6c531e872cc0aabed84583a021f17da7dc334af732
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Copyright (C) 2012 Sourcefire, Inc.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are
|
6
|
+
met:
|
7
|
+
|
8
|
+
* Redistributions of source code must retain the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
13
|
+
documentation and/or other materials provided with the distribution.
|
14
|
+
|
15
|
+
* Neither the name of *Sourcefire, Inc.* nor the names of its
|
16
|
+
contributors may be used to endorse or promote products derived from
|
17
|
+
this software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
panoptimon-collector-mysql_status
|
2
|
+
=================================
|
3
|
+
|
4
|
+
A MySQL metrics collector for panoptimon
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
* `gem install panoptimon`
|
10
|
+
* `gem install panoptimon-collector-mysql_status`
|
11
|
+
* Copy an example configuration and place it in your pan collectors folder (typically */etc/panoptimon/collectors/*) as *mysql_status.json*
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mysql';
|
4
|
+
require 'json';
|
5
|
+
|
6
|
+
class String; def as_number # from perlfaq4
|
7
|
+
self =~ %r{\A[+-]?(?=\.?\d)\d*\.?\d*(?:[Ee][+-]?\d+)?\z} \
|
8
|
+
? (self =~ %r{[\.Ee]} ? self.to_f : self.to_i)
|
9
|
+
: nil
|
10
|
+
end; end
|
11
|
+
|
12
|
+
class Mysql_status
|
13
|
+
|
14
|
+
def self.get_status (db)
|
15
|
+
rs = db.query("SHOW STATUS")
|
16
|
+
h = {}
|
17
|
+
while( r = rs.fetch_row )
|
18
|
+
h[r[0].downcase] = r[1]
|
19
|
+
end
|
20
|
+
return h
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_slave_status (db)
|
24
|
+
rs = db.query('SHOW SLAVE STATUS')
|
25
|
+
h = rs.fetch_hash or return {}
|
26
|
+
raise "too many results" if rs.num_rows > 1
|
27
|
+
return Hash[* h.keys.map {|k| [k.downcase, h[k]]}.flatten]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.run (config)
|
31
|
+
db = Mysql.new(*
|
32
|
+
%w{hostname username password database port socket}.
|
33
|
+
map {|k| config[k]})
|
34
|
+
|
35
|
+
m = get_status(db)
|
36
|
+
m.merge(get_slave_status(db))
|
37
|
+
info = {}
|
38
|
+
m.keys.each {|k|
|
39
|
+
n = m[k].as_number
|
40
|
+
if n
|
41
|
+
m[k] = n
|
42
|
+
else
|
43
|
+
info[k] = m.delete(k)
|
44
|
+
end
|
45
|
+
}
|
46
|
+
m[:_info] = info if info.length > 0
|
47
|
+
puts JSON::generate(m)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
config = JSON::parse(ARGV[0])
|
53
|
+
Mysql_status.run(config)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new { |gem|
|
2
|
+
gem.name = 'panoptimon-collector-mysql_status'
|
3
|
+
gem.version = '0.1.0'
|
4
|
+
gem.summary = 'collect information from MySQL'
|
5
|
+
gem.description = 'collect information from MySQL for use by panoptimon'
|
6
|
+
gem.authors = ['Eric Wilhelm']
|
7
|
+
gem.email = "sysops@sourcefire.com"
|
8
|
+
gem.homepage = "https://github.com/synthesist/panoptimon"
|
9
|
+
gem.license = 'bsd' # The (three-clause) BSD License
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
|
13
|
+
gem.add_dependency 'panoptimon', '~> 0.1.0'
|
14
|
+
gem.add_dependency 'mysql'
|
15
|
+
}
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: panoptimon-collector-mysql_status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Wilhelm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: panoptimon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mysql
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: collect information from MySQL for use by panoptimon
|
42
|
+
email: sysops@sourcefire.com
|
43
|
+
executables:
|
44
|
+
- pancollect-mysql_status
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- bin/pancollect-mysql_status
|
53
|
+
- example_configs/localhost.json
|
54
|
+
- example_configs/remote.json
|
55
|
+
- panoptimon-collector-mysql_status.gemspec
|
56
|
+
homepage: https://github.com/synthesist/panoptimon
|
57
|
+
licenses:
|
58
|
+
- bsd
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: collect information from MySQL
|
80
|
+
test_files: []
|