pomelo-citrus-monitor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +20 -0
- data/Rakefile +0 -0
- data/citrus-monitor.gemspec +27 -0
- data/lib/citrus-monitor.rb +12 -0
- data/lib/citrus-monitor/process_monitor.rb +87 -0
- data/lib/citrus-monitor/system_monitor.rb +71 -0
- data/lib/citrus-monitor/util/utils.rb +17 -0
- data/lib/citrus-monitor/version.rb +7 -0
- data/test/test_process_monitor.rb +20 -0
- data/test/test_system_monitor.rb +15 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 506525d2d2b5ac97b58dfb10978f29ae547caaf3
|
4
|
+
data.tar.gz: ce7c89e555e7c6140c42b076433f4ff477e7dc14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 416210dfc445555ea5f4f38cb729af396296a8065d79b855147c37d26f3568ff8619e3b7d0f4fa0aa92d06a60e80cee63025c5acfc3ac0d752b4e27e5e7831ae
|
7
|
+
data.tar.gz: 6c70185ec9415ed47353d1430a5d52c00ee3dc37888e1b2e31d0f8c1a03c85ce343ab8ba267333881ed48ffe61f59375aa12bc7b576a0825b396ba31c7b1beb0
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
## Welcome to pomelo-citrus-monitor
|
2
|
+
|
3
|
+
pomelo-citrus-monitor is a simple clone of pomelo-monitor written in Ruby using EventMachine.
|
4
|
+
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Since NodeJS is influenced by Ruby EventMachine and Python's Twisted model, Ruby should also be able to have its own game server framework like pomelo.
|
8
|
+
|
9
|
+
Ruby is a very expressive and eloquent programming language. I was an RoR programmer before and I really like Ruby, When developing this project, I have used many skills like meta-programming and they give me the real pleasures.
|
10
|
+
|
11
|
+
Recently, I would focus on my daily work, so I open source this project and hope to have more people participate in this project.
|
12
|
+
|
13
|
+
## Todo
|
14
|
+
|
15
|
+
This gem is the very first gem I have done in my whole work, it needs to be improved but it already has the ablity to provide the basic infrastructure to other gems, other gems exist in my own repository.
|
16
|
+
|
17
|
+
## Links
|
18
|
+
|
19
|
+
* [EventMachine](https://github.com/eventmachine/eventmachine)
|
20
|
+
* [pomelo-monitor](https://github.com/NetEase/pomelo-monitor)
|
data/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 8 July 2014
|
4
|
+
|
5
|
+
$:.push File.expand_path('../lib', __FILE__)
|
6
|
+
|
7
|
+
require 'citrus-monitor/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = 'pomelo-citrus-monitor'
|
11
|
+
spec.version = CitrusMonitor::VERSION
|
12
|
+
spec.platform = Gem::Platform::RUBY
|
13
|
+
spec.authors = ['MinixLi']
|
14
|
+
spec.email = 'MinixLi1986@gmail.com'
|
15
|
+
spec.description = %q{pomelo-citrus-monitor is a simple clone of pomelo-monitor, it provides a simple, comprehensive monitoring tool for operating-system and process}
|
16
|
+
spec.summary = %q{pomelo-monitor clone written in Ruby using EventMachine}
|
17
|
+
spec.homepage = 'https://github.com/minixli/pomelo-citrus-monitor'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split($/)
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency('eventmachine', '~> 0')
|
26
|
+
spec.add_dependency('os', '~> 0')
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
6
|
+
|
7
|
+
require 'eventmachine'
|
8
|
+
require 'os'
|
9
|
+
|
10
|
+
require 'citrus-monitor/util/utils'
|
11
|
+
require 'citrus-monitor/process_monitor'
|
12
|
+
require 'citrus-monitor/system_monitor'
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
module CitrusMonitor
|
6
|
+
# ProcessMonitor
|
7
|
+
#
|
8
|
+
#
|
9
|
+
module ProcessMonitor
|
10
|
+
include Utils
|
11
|
+
|
12
|
+
# Get process information by command 'ps auxw | grep serverId | grep pid'
|
13
|
+
#
|
14
|
+
# @param [Hash] args Options
|
15
|
+
#
|
16
|
+
# @option args [Integer] :pid
|
17
|
+
# @option args [String] :server_id
|
18
|
+
def get_ps_info args={}, &block
|
19
|
+
return if OS.windows?
|
20
|
+
|
21
|
+
pid = args[:pid]
|
22
|
+
|
23
|
+
EM.system('sh', proc{ |process|
|
24
|
+
process.send_data "ps auxw | grep " + pid.to_s + " | grep -v 'grep'\n"
|
25
|
+
process.send_data "exit\n"
|
26
|
+
}) { |output, status|
|
27
|
+
if status.exitstatus == 0
|
28
|
+
format args, output, &block
|
29
|
+
else
|
30
|
+
block.call status, nil if block
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Convert process information into required format
|
38
|
+
#
|
39
|
+
# @param [Hash] args Options
|
40
|
+
#
|
41
|
+
# @option args [Integer] :pid
|
42
|
+
# @option args [String] :server_id
|
43
|
+
#
|
44
|
+
# @param [String] output
|
45
|
+
#
|
46
|
+
# @private
|
47
|
+
def format args, data
|
48
|
+
time = get_current_time
|
49
|
+
|
50
|
+
data = data.gsub(/^\s+|\s+$/, '')
|
51
|
+
data = data.split(/\s+/).select { |str|
|
52
|
+
Float str rescue nil
|
53
|
+
}
|
54
|
+
|
55
|
+
ps_info = {}
|
56
|
+
ps_info[:time] = time
|
57
|
+
ps_info[:server_id] = args[:server_id]
|
58
|
+
ps_info[:server_type] = args[:server_id].split('-')[0]
|
59
|
+
pid = ps_info[:pid] = args[:pid]
|
60
|
+
ps_info[:cpu_avg] = data[1]
|
61
|
+
ps_info[:mem_avg] = data[2]
|
62
|
+
ps_info[:vsz] = data[3]
|
63
|
+
ps_info[:rss] = data[4]
|
64
|
+
|
65
|
+
if OS.mac?
|
66
|
+
ps_info[:usr] = ps_info[:sys] = ps_info[:gue] = '0'
|
67
|
+
block_given? and yield nil, ps_info
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
EM.system('pidstat -p ' + pid) { |output,status|
|
72
|
+
if status.exitstatus == 0
|
73
|
+
data = output.gsub(/^\s+|\s+$/, '')
|
74
|
+
data = data.split(/\s+/).select { |str|
|
75
|
+
Float str rescue nil
|
76
|
+
}
|
77
|
+
ps_info[:usr] = data[1]
|
78
|
+
ps_info[:sys] = data[2]
|
79
|
+
ps_info[:gue] = data[3]
|
80
|
+
block_given? and yield nil, ps_info
|
81
|
+
else
|
82
|
+
block_given? and yield status, nil
|
83
|
+
end
|
84
|
+
}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
module CitrusMonitor
|
6
|
+
# SystemMonitor
|
7
|
+
#
|
8
|
+
#
|
9
|
+
module SystemMonitor
|
10
|
+
include Utils
|
11
|
+
|
12
|
+
# Get operating system's information
|
13
|
+
def get_sys_info &block
|
14
|
+
return if OS.windows?
|
15
|
+
|
16
|
+
sys_info = get_basic_info
|
17
|
+
|
18
|
+
EM.system('iostat') { |output, status|
|
19
|
+
if status.exitstatus == 0
|
20
|
+
sys_info[:iostat] = format output
|
21
|
+
block_given? and yield nil, sys_info
|
22
|
+
else
|
23
|
+
block_given? and yield status, sys_info
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Get operating system's basic info
|
31
|
+
#
|
32
|
+
# @private
|
33
|
+
def get_basic_info
|
34
|
+
info = {}
|
35
|
+
report = YAML.load OS.report
|
36
|
+
report.each_pair { |key, value| info[key.to_sym] = value }
|
37
|
+
return info
|
38
|
+
end
|
39
|
+
|
40
|
+
# Analyze the disk i/o data, return a map contains kb_read, kb_wrtn, etc
|
41
|
+
#
|
42
|
+
# @private
|
43
|
+
def format data
|
44
|
+
time = get_current_time
|
45
|
+
|
46
|
+
data = data.gsub(/^\s+|\s+$/, '')
|
47
|
+
data = data.split(/\s+/).select { |str|
|
48
|
+
Float str rescue nil
|
49
|
+
}
|
50
|
+
|
51
|
+
return {
|
52
|
+
:date => time,
|
53
|
+
:disk => {
|
54
|
+
:kb_read => data[9] || '',
|
55
|
+
:kb_wrtn => data[10] || '',
|
56
|
+
:kb_read_per => data[7] || '',
|
57
|
+
:kb_wrtn_per => data[8] || '',
|
58
|
+
:tps => data[6] || ''
|
59
|
+
},
|
60
|
+
:cpu => {
|
61
|
+
:cpu_user => data[0] || '',
|
62
|
+
:cpu_nice => data[1] || '',
|
63
|
+
:cpu_system => data[2] || '',
|
64
|
+
:cpu_iowait => data[3] || '',
|
65
|
+
:cpu_steal => data[4] || '',
|
66
|
+
:cpu_idle => data[5] || ''
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
module CitrusMonitor
|
6
|
+
# Utils
|
7
|
+
#
|
8
|
+
#
|
9
|
+
module Utils
|
10
|
+
# Get current time in yyyy-mm-dd hh:mm:ss format
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def get_current_time
|
14
|
+
Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/citrus-monitor', __FILE__)
|
6
|
+
|
7
|
+
include CitrusMonitor::ProcessMonitor
|
8
|
+
|
9
|
+
EM.run {
|
10
|
+
pid = 428
|
11
|
+
args = {
|
12
|
+
:pid => pid,
|
13
|
+
:server_id => 'auth-server-1'
|
14
|
+
}
|
15
|
+
|
16
|
+
get_ps_info(args) { |status, data|
|
17
|
+
puts data
|
18
|
+
EM.add_timer(0.1) { EM.stop_event_loop }
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Author:: MinixLi (gmail: MinixLi1986)
|
2
|
+
# Homepage:: http://citrus.inspawn.com
|
3
|
+
# Date:: 7 July 2014
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/citrus-monitor', __FILE__)
|
6
|
+
|
7
|
+
include CitrusMonitor::SystemMonitor
|
8
|
+
|
9
|
+
EM.run {
|
10
|
+
get_sys_info { |status, data|
|
11
|
+
puts data
|
12
|
+
|
13
|
+
EM.add_timer(0.1) { EM.stop_event_loop }
|
14
|
+
}
|
15
|
+
}
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pomelo-citrus-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MinixLi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: os
|
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: pomelo-citrus-monitor is a simple clone of pomelo-monitor, it provides
|
42
|
+
a simple, comprehensive monitoring tool for operating-system and process
|
43
|
+
email: MinixLi1986@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- citrus-monitor.gemspec
|
51
|
+
- lib/citrus-monitor.rb
|
52
|
+
- lib/citrus-monitor/process_monitor.rb
|
53
|
+
- lib/citrus-monitor/system_monitor.rb
|
54
|
+
- lib/citrus-monitor/util/utils.rb
|
55
|
+
- lib/citrus-monitor/version.rb
|
56
|
+
- test/test_process_monitor.rb
|
57
|
+
- test/test_system_monitor.rb
|
58
|
+
homepage: https://github.com/minixli/pomelo-citrus-monitor
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: pomelo-monitor clone written in Ruby using EventMachine
|
82
|
+
test_files:
|
83
|
+
- test/test_process_monitor.rb
|
84
|
+
- test/test_system_monitor.rb
|