graphiterb 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
data/graphiterb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{graphiterb}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philip (flip) Kromer (@mrflip)"]
12
- s.date = %q{2010-08-17}
12
+ s.date = %q{2010-08-18}
13
13
  s.description = %q{Uses http://github.com/mrflip/configliere and http://graphite.wikidot.com}
14
14
  s.email = %q{info@infochimps.org}
15
15
  s.extra_rdoc_files = [
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/graphiterb/monitors.rb",
36
36
  "lib/graphiterb/monitors/directory_tree.rb",
37
37
  "lib/graphiterb/monitors/disk_space.rb",
38
+ "lib/graphiterb/monitors/system.rb",
38
39
  "lib/graphiterb/script.rb",
39
40
  "lib/graphiterb/sender.rb",
40
41
  "lib/graphiterb/utils.rb",
@@ -0,0 +1,74 @@
1
+ module Graphiterb
2
+ module Monitors
3
+ class System < Graphiterb::Monitors::PeriodicMonitor
4
+
5
+ def top
6
+ `top -b -n3`.chomp.split(/^top -/).last.split("\n") rescue []
7
+ end
8
+
9
+ def df
10
+ `/bin/df`.chomp.split("\n").
11
+ grep(%r{^/dev/}).
12
+ map{|line| line.split(/\s+/) } rescue []
13
+ end
14
+
15
+ def cpu lines
16
+ cpus = 0.0
17
+ total_percentage = 0.0
18
+ lines.each do |line|
19
+ next unless line =~ /^Cpu.* *: *([\d\.]+)%us/
20
+ cpus += 1.0
21
+ total_percentage += $1.to_f
22
+ end
23
+ total_percentage / cpus rescue 0.0
24
+ end
25
+
26
+ def processes lines
27
+ lines.each do |line|
28
+ next unless line =~ /^Tasks: *(\d+) *total, *(\d+) *running/
29
+ return [$1, $2].map(&:to_i)
30
+ end
31
+ [0, 0]
32
+ end
33
+
34
+ def memory lines
35
+ lines.each do |line|
36
+ next unless line =~ /^Mem: *\d+k *total, *(\d+)k *used, *(\d+)k *free/
37
+ return [$1, $2].map(&:to_i)
38
+ end
39
+ [0,0]
40
+ end
41
+
42
+ def swap lines
43
+ lines.each do |line|
44
+ next unless line =~ /^Swap: *\d+k *total, *(\d+)k *used, *(\d+)k *free/
45
+ return [$1, $2].map(&:to_i)
46
+ end
47
+ [0,0]
48
+ end
49
+
50
+
51
+ def get_metrics metrics, since
52
+ puts '=' * 80
53
+ df.each do |handle, size, spaceused, spacefree, percentfree, location|
54
+ disk_name = handle.gsub(/^\//, '').split('/')
55
+ metrics << [scope(hostname, disk_name, 'available'), spacefree.to_i]
56
+ end
57
+
58
+ lines = top
59
+
60
+ metrics << [scope(hostname, 'cpu', 'avg_usage'), cpu(lines)]
61
+ metrics << [scope(hostname, 'processes', 'count'), processes(lines)]
62
+
63
+ mem_used, mem_free = memory(lines)
64
+ swap_used, swap_free = swap(lines)
65
+
66
+ metrics << [scope(hostname, 'memory', 'used'), mem_used ]
67
+ metrics << [scope(hostname, 'memory', 'free'), mem_free ]
68
+ metrics << [scope(hostname, 'swap', 'used'), swap_used]
69
+ metrics << [scope(hostname, 'swap', 'free'), swap_free]
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -2,6 +2,7 @@ module Graphiterb
2
2
  module Monitors
3
3
 
4
4
  autoload :DiskSpace, 'graphiterb/monitors/disk_space'
5
+ autoload :System, 'graphiterb/monitors/system'
5
6
  autoload :DirectoryTree, 'graphiterb/monitors/directory_tree'
6
7
 
7
8
  # Accepts a lightweight call every iteration.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiterb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philip (flip) Kromer (@mrflip)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-17 00:00:00 -05:00
18
+ date: 2010-08-18 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,7 @@ files:
90
90
  - lib/graphiterb/monitors.rb
91
91
  - lib/graphiterb/monitors/directory_tree.rb
92
92
  - lib/graphiterb/monitors/disk_space.rb
93
+ - lib/graphiterb/monitors/system.rb
93
94
  - lib/graphiterb/script.rb
94
95
  - lib/graphiterb/sender.rb
95
96
  - lib/graphiterb/utils.rb