spoonsix-dognotgod 0.1.4 → 0.1.5
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.
- data/app/models/disk.rb +0 -1
 - data/app/models/file_system.rb +1 -1
 - data/client.rb +15 -33
 - data/server.rb +1 -1
 - data/views/layout.haml +1 -4
 - data/views/main.haml +0 -2
 - metadata +4 -2
 
    
        data/app/models/disk.rb
    CHANGED
    
    
    
        data/app/models/file_system.rb
    CHANGED
    
    | 
         @@ -21,7 +21,7 @@ class FileSystem < Sequel::Model 
     | 
|
| 
       21 
21 
     | 
    
         
             
            	def size_in_Gb
         
     | 
| 
       22 
22 
     | 
    
         
             
            	  last_entry = DB[:disks].filter(:file_system_id => self.id).reverse_order(:created_at).last
         
     | 
| 
       23 
23 
     | 
    
         
             
            	  if last_entry
         
     | 
| 
       24 
     | 
    
         
            -
                  (last_entry[:available] + last_entry[:used]) / 1024 / 1024
         
     | 
| 
      
 24 
     | 
    
         
            +
                  (last_entry[:available].to_i + last_entry[:used].to_i) / 1024 / 1024
         
     | 
| 
       25 
25 
     | 
    
         
             
                else
         
     | 
| 
       26 
26 
     | 
    
         
             
                  0
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
    
        data/client.rb
    CHANGED
    
    | 
         @@ -1,24 +1,29 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'restclient'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'lib/base.rb'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'lib/client_commands.rb'
         
     | 
| 
       4 
6 
     | 
    
         | 
| 
       5 
7 
     | 
    
         
             
            module DogNotGod
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
              class Client
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
                
         
     | 
| 
      
 11 
     | 
    
         
            +
                capture [:load_stats, :disk_stats, :memory_stats]
         
     | 
| 
      
 12 
     | 
    
         
            +
                
         
     | 
| 
       9 
13 
     | 
    
         
             
                def initialize(argv)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  
         
     | 
| 
       10 
15 
     | 
    
         
             
                  @argv = argv
         
     | 
| 
       11 
16 
     | 
    
         | 
| 
       12 
17 
     | 
    
         
             
                  # Default options values
         
     | 
| 
       13 
18 
     | 
    
         
             
                  @options = {
         
     | 
| 
       14 
19 
     | 
    
         
             
                    :server_addr                => "127.0.0.1",
         
     | 
| 
       15 
20 
     | 
    
         
             
                    :server_port                => "4567",
         
     | 
| 
       16 
     | 
    
         
            -
                    :timeout                    =>  
     | 
| 
      
 21 
     | 
    
         
            +
                    :timeout                    => 10
         
     | 
| 
       17 
22 
     | 
    
         
             
                  }
         
     | 
| 
       18 
23 
     | 
    
         | 
| 
       19 
24 
     | 
    
         
             
                  parse!
         
     | 
| 
       20 
25 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                  @ 
     | 
| 
      
 26 
     | 
    
         
            +
                  @resource = RestClient::Resource.new("http://#{@options[:server_addr]}:#{@options[:server_port]}")
         
     | 
| 
       22 
27 
     | 
    
         
             
                end
         
     | 
| 
       23 
28 
     | 
    
         | 
| 
       24 
29 
     | 
    
         
             
                def parser
         
     | 
| 
         @@ -45,39 +50,16 @@ module DogNotGod 
     | 
|
| 
       45 
50 
     | 
    
         
             
                end
         
     | 
| 
       46 
51 
     | 
    
         | 
| 
       47 
52 
     | 
    
         
             
                def run!
         
     | 
| 
       48 
     | 
    
         
            -
                  hostname = %x[hostname].split("\n")[0]
         
     | 
| 
       49 
     | 
    
         
            -
                  uptime = %x[uptime]
         
     | 
| 
       50 
     | 
    
         
            -
                  avgs = uptime.scan(/(\d+\.\d\d)/)
         
     | 
| 
       51 
     | 
    
         
            -
                  
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       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)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  @@command_symbols.each do |command_name_symbol|
         
     | 
| 
      
 55 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 56 
     | 
    
         
            +
                      command = DogNotGod::Commands.factory(command_name_symbol)
         
     | 
| 
      
 57 
     | 
    
         
            +
                      command.run!(@resource)
         
     | 
| 
      
 58 
     | 
    
         
            +
                    rescue
         
     | 
| 
      
 59 
     | 
    
         
            +
                      raise
         
     | 
| 
       72 
60 
     | 
    
         
             
                    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 
61 
     | 
    
         
             
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                  
         
     | 
| 
       81 
63 
     | 
    
         
             
                end
         
     | 
| 
       82 
64 
     | 
    
         | 
| 
       83 
65 
     | 
    
         
             
              end
         
     | 
    
        data/server.rb
    CHANGED
    
    | 
         @@ -98,7 +98,7 @@ post "/file_system_stats" do 
     | 
|
| 
       98 
98 
     | 
    
         
             
                host = get_host_or_create_if_not_exist(params[:hostname])
         
     | 
| 
       99 
99 
     | 
    
         
             
                fs   = get_fs_or_create_if_not_exist(host[:id], params[:file_system_name], params[:mounted_on])
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
     | 
    
         
            -
                disk_stats = Disk.new({:file_system_id => fs[:id], : 
     | 
| 
      
 101 
     | 
    
         
            +
                disk_stats = Disk.new({:file_system_id => fs[:id], :used => params[:used], :available => params[:available]})
         
     | 
| 
       102 
102 
     | 
    
         
             
                disk_stats.save
         
     | 
| 
       103 
103 
     | 
    
         
             
                status(201)
         
     | 
| 
       104 
104 
     | 
    
         
             
              rescue
         
     | 
    
        data/views/layout.haml
    CHANGED
    
    | 
         @@ -3,9 +3,6 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
              %head
         
     | 
| 
       4 
4 
     | 
    
         
             
                %title dog not god
         
     | 
| 
       5 
5 
     | 
    
         
             
                %link{:rel=>'stylesheet', :href=>'/stylesheets/style.css', :type => "text/css"}
         
     | 
| 
       6 
     | 
    
         
            -
                %script{:src => "http://www.google.com/jsapi"}
         
     | 
| 
       7 
     | 
    
         
            -
                %script google.load("jquery", "1");
         
     | 
| 
       8 
     | 
    
         
            -
                %script{:src => "/javascripts/flot/jquery.flot.pack.js"}
         
     | 
| 
       9 
6 
     | 
    
         | 
| 
       10 
7 
     | 
    
         | 
| 
       11 
8 
     | 
    
         
             
              %body
         
     | 
| 
         @@ -15,7 +12,7 @@ 
     | 
|
| 
       15 
12 
     | 
    
         
             
                  =yield
         
     | 
| 
       16 
13 
     | 
    
         
             
                #footer
         
     | 
| 
       17 
14 
     | 
    
         
             
                  %p 
         
     | 
| 
       18 
     | 
    
         
            -
                    %a{ :href => "http://github.com/ 
     | 
| 
      
 15 
     | 
    
         
            +
                    %a{ :href => "http://github.com/spoosix/dognotgod" } dog not god
         
     | 
| 
       19 
16 
     | 
    
         
             
                    is released under the 
         
     | 
| 
       20 
17 
     | 
    
         
             
                    %a{ :href => "http://www.gnu.org/licenses/gpl.html" } GPL license
         
     | 
| 
       21 
18 
     | 
    
         | 
    
        data/views/main.haml
    CHANGED
    
    | 
         @@ -20,8 +20,6 @@ 
     | 
|
| 
       20 
20 
     | 
    
         
             
                    %td= "#{host.available_disk_space_in_Gb}Gb out of #{host.total_disk_space_in_Gb}Gb (#{sprintf('%.2f', (host.available_disk_space_in_Gb.to_f / host.total_disk_space_in_Gb) * 100)}%)" if host.total_disk_space_in_Gb > 0
         
     | 
| 
       21 
21 
     | 
    
         
             
                    %td= "#{host.available_memory_in_Mb}Mb out of #{host.total_memory_in_Mb}Mb (#{sprintf('%.2f', (host.available_memory_in_Mb.to_f / host.total_memory_in_Mb) * 100)}%)" if host.total_memory_in_Mb > 0
         
     | 
| 
       22 
22 
     | 
    
         
             
                    %td= "#{host.available_swap_in_Mb}Mb out of #{host.total_swap_in_Mb}Mb (#{sprintf('%.2f', (host.available_swap_in_Mb.to_f / host.total_swap_in_Mb) * 100)}%)" if host.total_swap_in_Mb > 0
         
     | 
| 
       23 
     | 
    
         
            -
                  
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
23 
     | 
    
         | 
| 
       26 
24 
     | 
    
         
             
            %table{:id => "section-table"}
         
     | 
| 
       27 
25 
     | 
    
         
             
              %tr
         
     | 
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.5
         
     | 
| 
       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- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-03-03 00:00:00 -08:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -88,6 +88,8 @@ files: 
     | 
|
| 
       88 
88 
     | 
    
         
             
            - app/models/host.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            - app/models/load.rb
         
     | 
| 
       90 
90 
     | 
    
         
             
            - app/models/memory.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - lib/base.rb
         
     | 
| 
      
 92 
     | 
    
         
            +
            - lib/client_commands.rb
         
     | 
| 
       91 
93 
     | 
    
         
             
            - config.ru
         
     | 
| 
       92 
94 
     | 
    
         
             
            - README.md
         
     | 
| 
       93 
95 
     | 
    
         
             
            - views/layout.haml
         
     |