spoonsix-dognotgod 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/dognotgod-client +6 -0
  2. data/client.rb +87 -0
  3. metadata +14 -2
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+
4
+ DOGNOTGOD_DIR = "#{File.dirname(__FILE__)}/.."
5
+ Dir.chdir(DOGNOTGOD_DIR)
6
+ load 'client.rb'
data/client.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'restclient'
4
+
5
+ module DogNotGod
6
+
7
+ class Client
8
+
9
+ def initialize(argv)
10
+ @argv = argv
11
+
12
+ # Default options values
13
+ @options = {
14
+ :server_addr => "127.0.0.1",
15
+ :server_port => "4567",
16
+ :timeout => 5
17
+ }
18
+
19
+ parse!
20
+
21
+ @endpoint = "http://#{@options[:server_addr]}:#{@options[:server_port]}"
22
+ end
23
+
24
+ def parser
25
+ # NOTE: If you add an option here make sure the key in the +options+ hash is the
26
+ # same as the name of the command line option.
27
+ # +option+ keys are used to build the command line to launch other processes,
28
+ # see <tt>lib/thin/command.rb</tt>.
29
+ @parser ||= OptionParser.new do |opts|
30
+ opts.banner = "Usage: dognotgod-client [options]"
31
+ opts.separator ""
32
+ opts.separator "Server options:"
33
+
34
+ opts.on("-a", "--server-addr HOST", "HOST address to call (default: #{@options[:server_addr]})") { |host| @options[:server_addr] = host }
35
+ opts.on("-p", "--server-port PORT", "use PORT (default: #{@options[:server_port]})") { |port| @options[:server_port] = port.to_i }
36
+ #opts.on("-t", "--timeout SECONDS", "timeout after SECONDS (default: #{@options[:timeout]})") { |port| @options[:timeout] = port.to_i }
37
+ opts.separator ""
38
+ end
39
+ end
40
+
41
+ # Parse the options.
42
+ def parse!
43
+ parser.parse! @argv
44
+ @arguments = @argv
45
+ end
46
+
47
+ def run!
48
+ hostname = %x[hostname].split("\n")[0]
49
+ uptime = %x[uptime]
50
+ avgs = uptime.scan(/(\d+\.\d\d)/)
51
+
52
+
53
+ # the 'free' command is not available on Mac OSX
54
+ mem = %x[free].split("\n")
55
+ mem.shift # lose column headers
56
+ mem_available = mem[0].split(" ")[3]
57
+ mem_used = mem[0].split(" ")[2]
58
+ swap_available = mem[2].split(" ")[3]
59
+ swap_used = mem[2].split(" ")[2]
60
+
61
+
62
+ df = %x[df -ak].split("\n")
63
+ df.shift # lose column headers
64
+
65
+ begin
66
+ RestClient.post("#{@endpoint}/load_stats", :load_5_min => avgs[0], :load_10_min => avgs[1], :load_15_min => avgs[2], :hostname => hostname)
67
+ puts "Load info sent successfully."
68
+
69
+ df.each do |line|
70
+ info = line.split(" ")
71
+ RestClient.post("#{@endpoint}/file_system_stats", :file_system_name => info[0], :mounted_on => info[-1], :used => info[2], :available => info[3], :hostname => hostname)
72
+ end
73
+ puts "Filesystem info sent successfully."
74
+
75
+ RestClient.post("#{@endpoint}/mem_stats", :hostname => hostname, :mem_available => mem_available, :mem_used => mem_used, :swap_available => swap_available, :swap_used => swap_used)
76
+ puts "Memory and swap info sent successfully."
77
+
78
+ rescue
79
+ puts "There was a problem connecting to the server on #{@endpoint}."
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ DogNotGod::Client.new(ARGV).run!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoonsix-dognotgod
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
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-01 00:00:00 -08:00
12
+ date: 2009-03-02 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -62,10 +62,21 @@ dependencies:
62
62
  - !ruby/object:Gem::Version
63
63
  version: 1.2.4
64
64
  version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: rest-client
67
+ type: :runtime
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0.9"
74
+ version:
65
75
  description: dog not god is a performance monitoring tool.
66
76
  email: luis.ca@gmail.com
67
77
  executables:
68
78
  - dognotgod
79
+ - dognotgod-client
69
80
  extensions: []
70
81
 
71
82
  extra_rdoc_files: []
@@ -84,6 +95,7 @@ files:
84
95
  - views/style.sass
85
96
  - config/thin.yml
86
97
  - server.rb
98
+ - client.rb
87
99
  has_rdoc: false
88
100
  homepage: http://github.com/spoonsix/dognotgod
89
101
  post_install_message: