munin_rake_processes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +37 -0
- data/Rakefile +12 -0
- data/bin/munin_rake_processes_count +26 -0
- data/bin/munin_rake_processes_cpu +24 -0
- data/bin/munin_rake_processes_cpu_time +24 -0
- data/bin/munin_rake_processes_installer +7 -0
- data/bin/munin_rake_processes_memory +24 -0
- data/lib/munin/rake_processes/count.rb +20 -0
- data/lib/munin/rake_processes/cpu.rb +24 -0
- data/lib/munin/rake_processes/cpu_time.rb +24 -0
- data/lib/munin/rake_processes/installer.rb +34 -0
- data/lib/munin/rake_processes/memory.rb +24 -0
- data/lib/munin/rake_processes/plugin.rb +57 -0
- data/lib/munin/rake_processes/version.rb +5 -0
- data/lib/munin_rake_processes.rb +10 -0
- data/license.txt +19 -0
- data/munin_rake_processes.gemspec +21 -0
- data/spec/munin/rake_processes/count_spec.rb +38 -0
- data/spec/munin/rake_processes/cpu_spec.rb +42 -0
- data/spec/munin/rake_processes/cpu_time_spec.rb +42 -0
- data/spec/munin/rake_processes/memory_spec.rb +42 -0
- data/spec/munin/rake_processes/plugin_spec.rb +33 -0
- data/spec/spec_helper.rb +36 -0
- metadata +128 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Munin Rake Processes [![Build Status](https://secure.travis-ci.org/alexrothenberg/munin_rake_processes.png)](http://travis-ci.org/alexrothenberg/munin_rake_processes)
|
2
|
+
|
3
|
+
Some Munin plugins to monitor running rake tasks.
|
4
|
+
|
5
|
+
Rake tasks are often run on the server using cron or some other scheduler. This gem lets you monitor so you can tell
|
6
|
+
|
7
|
+
* how many are running
|
8
|
+
* how long they've been running
|
9
|
+
* how much cpu they are using
|
10
|
+
* how much memory they are using
|
11
|
+
|
12
|
+
# Usage
|
13
|
+
|
14
|
+
gem install munin_rake_processes
|
15
|
+
|
16
|
+
munin_rake_processes_installer
|
17
|
+
# will install all 4 munin plugins
|
18
|
+
|
19
|
+
munin_rake_processes_installer count
|
20
|
+
# will install just the count munin plugin
|
21
|
+
|
22
|
+
munin_rake_processes_installer count cpu_time
|
23
|
+
# will install just the count and cpu_time munin plugins (any combination will work)
|
24
|
+
|
25
|
+
# Contributing
|
26
|
+
|
27
|
+
* Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
|
28
|
+
* Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
|
29
|
+
* Fork the project
|
30
|
+
* Start a feature/bugfix branch
|
31
|
+
* Commit and push until you are happy with your contribution
|
32
|
+
* Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
|
33
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
34
|
+
|
35
|
+
# Copyright
|
36
|
+
|
37
|
+
Copyright © 2011 Alex Rothenberg. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'munin_rake_processes'
|
4
|
+
|
5
|
+
pod=<<-POD
|
6
|
+
|
7
|
+
=head1 NAME
|
8
|
+
rake_processes_count - Munin plugin to monitor number of rake processes currently running
|
9
|
+
|
10
|
+
=head1 VERSION
|
11
|
+
#{Munin::RakeProcesses::VERSION}
|
12
|
+
|
13
|
+
=head1 BUGS
|
14
|
+
None known
|
15
|
+
|
16
|
+
=head1 AUTHOR
|
17
|
+
Alex Rothenberg
|
18
|
+
|
19
|
+
=head1 LICENSE
|
20
|
+
MIT
|
21
|
+
|
22
|
+
POD
|
23
|
+
|
24
|
+
puts ['count 1', __FILE__, __LINE__].inspect
|
25
|
+
Munin::RakeProcesses::Count.new(ARGV, ENV)
|
26
|
+
puts ['count 2', __FILE__, __LINE__].inspect
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'munin_rake_processes'
|
4
|
+
|
5
|
+
pod=<<-POD
|
6
|
+
|
7
|
+
=head1 NAME
|
8
|
+
rake_processes_cpu - Munin plugin to monitor cpu consumed by currently running rake processes
|
9
|
+
|
10
|
+
=head1 VERSION
|
11
|
+
#{Munin::RakeProcesses::VERSION}
|
12
|
+
|
13
|
+
=head1 BUGS
|
14
|
+
None known
|
15
|
+
|
16
|
+
=head1 AUTHOR
|
17
|
+
Alex Rothenberg
|
18
|
+
|
19
|
+
=head1 LICENSE
|
20
|
+
MIT
|
21
|
+
|
22
|
+
POD
|
23
|
+
|
24
|
+
Munin::RakeProcesses::Cpu.new(ARGV, ENV)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'munin_rake_processes'
|
4
|
+
|
5
|
+
pod=<<-POD
|
6
|
+
|
7
|
+
=head1 NAME
|
8
|
+
rake_processes_cpu_time - Munin plugin to monitor cumulative cpu time spent by currently running rake processes
|
9
|
+
|
10
|
+
=head1 VERSION
|
11
|
+
#{Munin::RakeProcesses::VERSION}
|
12
|
+
|
13
|
+
=head1 BUGS
|
14
|
+
None known
|
15
|
+
|
16
|
+
=head1 AUTHOR
|
17
|
+
Alex Rothenberg
|
18
|
+
|
19
|
+
=head1 LICENSE
|
20
|
+
MIT
|
21
|
+
|
22
|
+
POD
|
23
|
+
|
24
|
+
Munin::RakeProcesses::CpuTime.new(ARGV, ENV)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'munin_rake_processes'
|
4
|
+
|
5
|
+
pod=<<-POD
|
6
|
+
|
7
|
+
=head1 NAME
|
8
|
+
rake_processes_cpu - Munin plugin to monitor memory consumed by currently running rake processes
|
9
|
+
|
10
|
+
=head1 VERSION
|
11
|
+
#{Munin::RakeProcesses::VERSION}
|
12
|
+
|
13
|
+
=head1 BUGS
|
14
|
+
None known
|
15
|
+
|
16
|
+
=head1 AUTHOR
|
17
|
+
Alex Rothenberg
|
18
|
+
|
19
|
+
=head1 LICENSE
|
20
|
+
MIT
|
21
|
+
|
22
|
+
POD
|
23
|
+
|
24
|
+
Munin::RakeProcesses::Memory.new(ARGV, ENV)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Munin
|
2
|
+
module RakeProcesses
|
3
|
+
class Count < Plugin
|
4
|
+
|
5
|
+
def config
|
6
|
+
puts <<-CONFIG
|
7
|
+
graph_category #{graph_category}
|
8
|
+
graph_title Number of Rake Processes
|
9
|
+
graph_vlabel Count of Rake Processes
|
10
|
+
graph_info The Rake processes running - (possibly from cron)
|
11
|
+
rake_processes.label rake_processes
|
12
|
+
CONFIG
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
puts "rake_processes.value #{rake_processes.size}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Munin
|
2
|
+
module RakeProcesses
|
3
|
+
class Cpu < Plugin
|
4
|
+
|
5
|
+
def config
|
6
|
+
puts <<-CONFIG
|
7
|
+
graph_category #{graph_category}
|
8
|
+
graph_info The CPU usage of Rake processes currently running - (possibly from cron)
|
9
|
+
graph_title CPU usage of Rake Processes
|
10
|
+
graph_vlabel CPU usage of Rake Processes
|
11
|
+
CONFIG
|
12
|
+
rake_processes.each_key do |key|
|
13
|
+
puts "#{key}_CPU.label #{key}_CPU"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
rake_processes.each do |cmd, values|
|
19
|
+
puts "#{cmd}_CPU.value #{values[:cpu]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Munin
|
2
|
+
module RakeProcesses
|
3
|
+
class CpuTime < Plugin
|
4
|
+
|
5
|
+
def config
|
6
|
+
puts <<-CONFIG
|
7
|
+
graph_category #{graph_category}
|
8
|
+
graph_info The CPU time consumed of Rake processes currently running - (possibly from cron)
|
9
|
+
graph_title CPU Time of Rake Processes
|
10
|
+
graph_vlabel CPU Time of Rake Processes
|
11
|
+
CONFIG
|
12
|
+
rake_processes.each_key do |key|
|
13
|
+
puts "#{key}_TIME.label #{key}_TIME"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
rake_processes.each do |cmd, values|
|
19
|
+
puts "#{cmd}_TIME.value #{values[:time]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Munin
|
3
|
+
module RakeProcesses
|
4
|
+
class Installer
|
5
|
+
def initialize(args)
|
6
|
+
if args.empty?
|
7
|
+
add_all_plugins
|
8
|
+
else
|
9
|
+
args.each do |plugin|
|
10
|
+
add_plugin(plugin)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_all_plugins
|
16
|
+
[:count, :cpu, :cpu_time, :memory].each do |plugin|
|
17
|
+
add_plugin(plugin)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_plugin(plugin)
|
22
|
+
plugin_filename = "munin_rake_processes_#{plugin}"
|
23
|
+
plugin_path = `which #{plugin_filename}`.strip
|
24
|
+
FileUtils.mkdir_p(munin_plugins_path)
|
25
|
+
`ln -nsf "#{plugin_path}" "#{munin_plugins_path}/#{plugin_filename}"`
|
26
|
+
puts "Installing Munin plugin #{plugin_filename}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def munin_plugins_path
|
30
|
+
"/etc/munin/plugins"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Munin
|
2
|
+
module RakeProcesses
|
3
|
+
class Memory < Plugin
|
4
|
+
|
5
|
+
def config
|
6
|
+
puts <<-CONFIG
|
7
|
+
graph_category #{graph_category}
|
8
|
+
graph_info The Memory usage of Rake processes currently running - (possibly from cron)
|
9
|
+
graph_title Memory usage of Rake Processes
|
10
|
+
graph_vlabel Memory usage of Rake Processes
|
11
|
+
CONFIG
|
12
|
+
rake_processes.each_key do |key|
|
13
|
+
puts "#{key}_Memory.label #{key}_Memory"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
rake_processes.each do |cmd, values|
|
19
|
+
puts "#{cmd}_Memory.value #{values[:memory]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Munin
|
2
|
+
module RakeProcesses
|
3
|
+
class Plugin
|
4
|
+
attr_accessor :debug
|
5
|
+
attr_accessor :graph_category
|
6
|
+
|
7
|
+
def initialize(args, environment={})
|
8
|
+
self.graph_category = environment['graph_category'] || 'RakeProcesses'
|
9
|
+
|
10
|
+
case args[0]
|
11
|
+
when "config"
|
12
|
+
config
|
13
|
+
when "autoconf"
|
14
|
+
autoconf
|
15
|
+
else
|
16
|
+
run
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.rake_ps_string
|
21
|
+
`ps -eo user,pid,%cpu,%mem,cputime,command | grep -v -e grep -e munin | grep rake`
|
22
|
+
end
|
23
|
+
|
24
|
+
def rake_processes
|
25
|
+
@rake_processes ||= begin
|
26
|
+
_rake_processes = {}
|
27
|
+
rake_ps_lines = self.class.rake_ps_string.split("\n")
|
28
|
+
rake_ps_lines.each do |ps_line|
|
29
|
+
user, pid, cpu, memory, cpu_time, cmd = ps_line.split ' ', 6
|
30
|
+
cmd =~ /rake([^-]+)/
|
31
|
+
rake_cmd = $1.split('-').first.strip.gsub(/[^\w]/, '_')
|
32
|
+
label = "#{user}_#{pid}_#{rake_cmd}"
|
33
|
+
time_in_seconds = ps_time_to_seconds(cpu_time)
|
34
|
+
_rake_processes[label] = {:cpu => cpu, :memory => memory, :time => time_in_seconds}
|
35
|
+
end
|
36
|
+
_rake_processes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def autoconf
|
41
|
+
puts "yes"
|
42
|
+
end
|
43
|
+
|
44
|
+
def run
|
45
|
+
# overridden in subclasses but left here for rspec plugin_spec.rb
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def ps_time_to_seconds(time_string)
|
50
|
+
seconds = 0
|
51
|
+
time_elements = time_string.split(':').reverse
|
52
|
+
time_elements.each_with_index {|element,index| seconds += element.to_f*(60**index)}
|
53
|
+
seconds
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
require "munin/rake_processes/version"
|
4
|
+
require "munin/rake_processes/installer"
|
5
|
+
require "munin/rake_processes/plugin"
|
6
|
+
require "munin/rake_processes/count"
|
7
|
+
require "munin/rake_processes/cpu"
|
8
|
+
require "munin/rake_processes/cpu_time"
|
9
|
+
require "munin/rake_processes/memory"
|
10
|
+
|
data/license.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 Alex Rothenberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/munin/rake_processes/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alex Rothenberg"]
|
6
|
+
gem.email = ["alex@alexrothenberg.com"]
|
7
|
+
gem.description = %q{Munin tasks for monitoring rake processes}
|
8
|
+
gem.summary = %q{Munin tasks for monitoring rake processes}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "munin_rake_processes"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Munin::RakeProcesses::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec', '>= 2.2'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe Munin::RakeProcesses::Count do
|
5
|
+
before { stub_ps }
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
capture_output(&example)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#config' do
|
12
|
+
before do
|
13
|
+
Munin::RakeProcesses::Count.new(['config'],{})
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { $stdout.string }
|
17
|
+
it { should == <<-OUTPUT
|
18
|
+
graph_category RakeProcesses
|
19
|
+
graph_title Number of Rake Processes
|
20
|
+
graph_vlabel Count of Rake Processes
|
21
|
+
graph_info The Rake processes running - (possibly from cron)
|
22
|
+
rake_processes.label rake_processes
|
23
|
+
OUTPUT
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#run' do
|
28
|
+
before do
|
29
|
+
Munin::RakeProcesses::Count.new([],{})
|
30
|
+
end
|
31
|
+
|
32
|
+
subject { $stdout.string }
|
33
|
+
it { should == <<-OUTPUT
|
34
|
+
rake_processes.value 3
|
35
|
+
OUTPUT
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe Munin::RakeProcesses::Cpu do
|
5
|
+
before { stub_ps }
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
capture_output(&example)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#config' do
|
12
|
+
before do
|
13
|
+
Munin::RakeProcesses::Cpu.new(['config'],{})
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { captured_output }
|
17
|
+
it { should == <<-OUTPUT
|
18
|
+
graph_category RakeProcesses
|
19
|
+
graph_info The CPU usage of Rake processes currently running - (possibly from cron)
|
20
|
+
graph_title CPU usage of Rake Processes
|
21
|
+
graph_vlabel CPU usage of Rake Processes
|
22
|
+
some_user_25963_load_users_CPU.label some_user_25963_load_users_CPU
|
23
|
+
some_user_27461_load_users_CPU.label some_user_27461_load_users_CPU
|
24
|
+
some_user_27499_cron_CPU.label some_user_27499_cron_CPU
|
25
|
+
OUTPUT
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#run' do
|
30
|
+
before do
|
31
|
+
Munin::RakeProcesses::Cpu.new([],{})
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { captured_output }
|
35
|
+
it { should == <<-OUTPUT
|
36
|
+
some_user_25963_load_users_CPU.value 5.0
|
37
|
+
some_user_27461_load_users_CPU.value 0.0
|
38
|
+
some_user_27499_cron_CPU.value 90.0
|
39
|
+
OUTPUT
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe Munin::RakeProcesses::CpuTime do
|
5
|
+
before { stub_ps }
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
capture_output(&example)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#config' do
|
12
|
+
before do
|
13
|
+
Munin::RakeProcesses::CpuTime.new(['config'],{})
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { captured_output }
|
17
|
+
it { should == <<-OUTPUT
|
18
|
+
graph_category RakeProcesses
|
19
|
+
graph_info The CPU time consumed of Rake processes currently running - (possibly from cron)
|
20
|
+
graph_title CPU Time of Rake Processes
|
21
|
+
graph_vlabel CPU Time of Rake Processes
|
22
|
+
some_user_25963_load_users_TIME.label some_user_25963_load_users_TIME
|
23
|
+
some_user_27461_load_users_TIME.label some_user_27461_load_users_TIME
|
24
|
+
some_user_27499_cron_TIME.label some_user_27499_cron_TIME
|
25
|
+
OUTPUT
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#run' do
|
30
|
+
before do
|
31
|
+
Munin::RakeProcesses::CpuTime.new([],{})
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { captured_output }
|
35
|
+
it { should == <<-OUTPUT
|
36
|
+
some_user_25963_load_users_TIME.value 8448.69
|
37
|
+
some_user_27461_load_users_TIME.value 0.0
|
38
|
+
some_user_27499_cron_TIME.value 2.3
|
39
|
+
OUTPUT
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
describe Munin::RakeProcesses::Memory do
|
5
|
+
before { stub_ps }
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
capture_output(&example)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#config' do
|
12
|
+
before do
|
13
|
+
Munin::RakeProcesses::Memory.new(['config'],{})
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { captured_output }
|
17
|
+
it { should == <<-OUTPUT
|
18
|
+
graph_category RakeProcesses
|
19
|
+
graph_info The Memory usage of Rake processes currently running - (possibly from cron)
|
20
|
+
graph_title Memory usage of Rake Processes
|
21
|
+
graph_vlabel Memory usage of Rake Processes
|
22
|
+
some_user_25963_load_users_Memory.label some_user_25963_load_users_Memory
|
23
|
+
some_user_27461_load_users_Memory.label some_user_27461_load_users_Memory
|
24
|
+
some_user_27499_cron_Memory.label some_user_27499_cron_Memory
|
25
|
+
OUTPUT
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#run' do
|
30
|
+
before do
|
31
|
+
Munin::RakeProcesses::Memory.new([],{})
|
32
|
+
end
|
33
|
+
|
34
|
+
subject { captured_output }
|
35
|
+
it { should == <<-OUTPUT
|
36
|
+
some_user_25963_load_users_Memory.value 0.2
|
37
|
+
some_user_27461_load_users_Memory.value 0.1
|
38
|
+
some_user_27499_cron_Memory.value 0.3
|
39
|
+
OUTPUT
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Munin::RakeProcesses::Plugin do
|
4
|
+
describe '#rake_processes' do
|
5
|
+
before do
|
6
|
+
stub_ps
|
7
|
+
end
|
8
|
+
let(:rake_processes) { Munin::RakeProcesses::Plugin.new([],{}).rake_processes }
|
9
|
+
subject { rake_processes }
|
10
|
+
its(:size) { should == 3 }
|
11
|
+
|
12
|
+
describe 'old load_users' do
|
13
|
+
subject { rake_processes['some_user_25963_load_users'] }
|
14
|
+
its([:cpu ]) { should == '5.0' }
|
15
|
+
its([:memory]) { should == '0.2' }
|
16
|
+
its([:time ]) { should == 8448.69 }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'hung old load_users' do
|
20
|
+
subject { rake_processes['some_user_27461_load_users'] }
|
21
|
+
its([:cpu ]) { should == '0.0' }
|
22
|
+
its([:memory]) { should == '0.1' }
|
23
|
+
its([:time ]) { should == 0.0 }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'hung old load_users' do
|
27
|
+
subject { rake_processes['some_user_27499_cron'] }
|
28
|
+
its([:cpu ]) { should == '90.0' }
|
29
|
+
its([:memory]) { should == '0.3' }
|
30
|
+
its([:time ]) { should == 2.3 }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'munin_rake_processes'
|
2
|
+
|
3
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
4
|
+
|
5
|
+
RSpec.configure do |c|
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def stub_ps
|
10
|
+
Munin::RakeProcesses::Plugin.stub(:'`').and_return <<-PS_STRING
|
11
|
+
some_user 25963 5.0 0.2 140:48.69 ruby /Users/alex/.rvm/gems/ruby-1.8.7-p334/bin/rake load_users
|
12
|
+
some_user 27461 0.0 0.1 00:00:00 ruby /Users/alex/.rvm/gems/ruby-1.8.7-p334/bin/rake load_users
|
13
|
+
some_user 27499 90.0 0.3 0:02.30 ruby /Users/alex/.rvm/gems/ruby-1.8.7-p334/bin/rake cron
|
14
|
+
PS_STRING
|
15
|
+
end
|
16
|
+
|
17
|
+
def capture_output
|
18
|
+
$o_stdin, $o_stdout, $o_stderr = $stdin, $stdout, $stderr
|
19
|
+
$stdin, $stdout, $stderr = StringIO.new, StringIO.new, StringIO.new
|
20
|
+
|
21
|
+
yield
|
22
|
+
|
23
|
+
ensure
|
24
|
+
$stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr
|
25
|
+
end
|
26
|
+
|
27
|
+
def captured_output
|
28
|
+
sort_stdout_if_ruby_18
|
29
|
+
$stdout.string
|
30
|
+
end
|
31
|
+
|
32
|
+
def sort_stdout_if_ruby_18
|
33
|
+
if RUBY_VERSION < '1.9'
|
34
|
+
$stdout.string = $stdout.string.split("\n").sort.join("\n") + "\n"
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: munin_rake_processes
|
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
|
+
- Alex Rothenberg
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-05 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: 7
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 2
|
32
|
+
version: "2.2"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Munin tasks for monitoring rake processes
|
50
|
+
email:
|
51
|
+
- alex@alexrothenberg.com
|
52
|
+
executables:
|
53
|
+
- munin_rake_processes_count
|
54
|
+
- munin_rake_processes_cpu
|
55
|
+
- munin_rake_processes_cpu_time
|
56
|
+
- munin_rake_processes_installer
|
57
|
+
- munin_rake_processes_memory
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/munin_rake_processes_count
|
69
|
+
- bin/munin_rake_processes_cpu
|
70
|
+
- bin/munin_rake_processes_cpu_time
|
71
|
+
- bin/munin_rake_processes_installer
|
72
|
+
- bin/munin_rake_processes_memory
|
73
|
+
- lib/munin/rake_processes/count.rb
|
74
|
+
- lib/munin/rake_processes/cpu.rb
|
75
|
+
- lib/munin/rake_processes/cpu_time.rb
|
76
|
+
- lib/munin/rake_processes/installer.rb
|
77
|
+
- lib/munin/rake_processes/memory.rb
|
78
|
+
- lib/munin/rake_processes/plugin.rb
|
79
|
+
- lib/munin/rake_processes/version.rb
|
80
|
+
- lib/munin_rake_processes.rb
|
81
|
+
- license.txt
|
82
|
+
- munin_rake_processes.gemspec
|
83
|
+
- spec/munin/rake_processes/count_spec.rb
|
84
|
+
- spec/munin/rake_processes/cpu_spec.rb
|
85
|
+
- spec/munin/rake_processes/cpu_time_spec.rb
|
86
|
+
- spec/munin/rake_processes/memory_spec.rb
|
87
|
+
- spec/munin/rake_processes/plugin_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ""
|
90
|
+
licenses: []
|
91
|
+
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.11
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Munin tasks for monitoring rake processes
|
122
|
+
test_files:
|
123
|
+
- spec/munin/rake_processes/count_spec.rb
|
124
|
+
- spec/munin/rake_processes/cpu_spec.rb
|
125
|
+
- spec/munin/rake_processes/cpu_time_spec.rb
|
126
|
+
- spec/munin/rake_processes/memory_spec.rb
|
127
|
+
- spec/munin/rake_processes/plugin_spec.rb
|
128
|
+
- spec/spec_helper.rb
|