spoonsix-dognotgod-client 0.1.7 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/base.rb +7 -0
  2. data/lib/client_commands.rb +121 -0
  3. metadata +4 -2
data/lib/base.rb ADDED
@@ -0,0 +1,7 @@
1
+ class String
2
+
3
+ def camelize
4
+ self.split('_').map {|w| w.capitalize}.join
5
+ end
6
+
7
+ end
@@ -0,0 +1,121 @@
1
+ module DogNotGod
2
+
3
+ class Shell
4
+
5
+ def initialize
6
+ raise "StaticClass"
7
+ end
8
+
9
+ def self.call(command)
10
+ `#{command}`
11
+ end
12
+ end
13
+
14
+ class Client
15
+
16
+ def self.capture(array_of_command_symbols)
17
+ @@command_symbols = array_of_command_symbols
18
+ end
19
+
20
+ end
21
+
22
+ #
23
+ #
24
+ #
25
+ module Commands
26
+
27
+ def self.factory(command_name_symbol)
28
+ class_name = command_name_symbol.to_s.camelize
29
+ klass = self.const_get class_name
30
+ klass.new
31
+ end
32
+
33
+
34
+ class ClientCommand
35
+
36
+ def run!(resource)
37
+ @resource = resource
38
+ _prepare
39
+ _execute
40
+ end
41
+
42
+ def get_hostname_from_shell
43
+ DogNotGod::Shell.call("hostname").split("\n")[0]
44
+ end
45
+
46
+ end
47
+
48
+ #
49
+ # Load average statistics
50
+ #
51
+ class LoadStats < ClientCommand
52
+
53
+ def _prepare
54
+ @hostname = get_hostname_from_shell
55
+ @load_averages = get_load_averages_from_shell
56
+ end
57
+
58
+ def _execute
59
+ @resource["/load_stats"].post({:load_5_min => @load_averages[0], :load_10_min => @load_averages[1], :load_15_min => @load_averages[2], :hostname => @hostname})
60
+ end
61
+
62
+ def get_load_averages_from_shell
63
+ DogNotGod::Shell.call("uptime").scan(/(\d+\.\d\d)/)
64
+ end
65
+
66
+ end
67
+
68
+ #
69
+ # Disk statistics
70
+ #
71
+ class DiskStats < ClientCommand
72
+
73
+ def _prepare
74
+ @hostname = get_hostname_from_shell
75
+ @disk_stats = get_disk_statistics_from_shell
76
+ end
77
+
78
+ def _execute
79
+ @disk_stats.each do |line|
80
+ @resource["/file_system_stats"].post({:file_system_name => line[0], :mounted_on => line[-1], :used => line[2], :available => line[3], :hostname => @hostname})
81
+ end
82
+ end
83
+
84
+ #
85
+ # Extract disk data from df call
86
+ #
87
+ # - Only extract entries for filesystems starting with a /
88
+ # - Ignore capacity % column
89
+ #
90
+ def get_disk_statistics_from_shell
91
+ DogNotGod::Shell.call("df -ak").scan(/^(\/[\w+\/-]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+\%\s+(\/.*)\n/)
92
+ end
93
+
94
+ end
95
+
96
+ #
97
+ # Memory statistics, including swap
98
+ #
99
+ class MemoryStats < ClientCommand
100
+
101
+ def _prepare
102
+ @hostname = get_hostname_from_shell
103
+ @memory_stats = get_memory_and_swap_statistics_from_shell
104
+ end
105
+
106
+ def _execute
107
+ @resource["/mem_stats"].post({:hostname => @hostname, :mem_available => @memory_stats[:mem_available], :mem_used => @memory_stats[:mem_used], :swap_available => @memory_stats[:swap_available], :swap_used => @memory_stats[:swap_used]})
108
+ end
109
+
110
+ def get_memory_and_swap_statistics_from_shell
111
+ # Note: the 'free' command is not available on Mac OSX
112
+ mem = DogNotGod::Shell.call("free").split("\n")
113
+ mem.shift # lose column headers
114
+
115
+ {:mem_available => mem[0].split(" ")[3], :mem_used => mem[0].split(" ")[2], :swap_available => mem[2].split(" ")[3], :swap_used => mem[2].split(" ")[2] }
116
+ end
117
+
118
+ end
119
+ end
120
+
121
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoonsix-dognotgod-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Correa d'Almeida
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-04 00:00:00 -08:00
12
+ date: 2009-03-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,8 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - client.rb
35
35
  - bin/dognotgod-client
36
+ - lib/base.rb
37
+ - lib/client_commands.rb
36
38
  has_rdoc: false
37
39
  homepage: http://github.com/spoonsix/dognotgod
38
40
  post_install_message: