Browse Source

dynamos now viewable as well

Chris Mague 7 years ago
parent
commit
6192c700b5

+ 25 - 3
lib/neoinfra/aws.rb

@@ -5,6 +5,7 @@ require 'regions'
 require 'mime-types'
 require 'fog-aws'
 require 's3'
+require 'date'
 require 'ipaddr'
 require 'neo4j'
 require 'rds'
@@ -55,8 +56,12 @@ module NeoInfra
         aws_secret_access_key: account[:secret],
         region: region
       }
-      conn = Fog::Compute.new(base_conf)
-      conn.describe_availability_zones.data[:body]['availabilityZoneInfo'].collect { |x| x['zoneName'] }
+      begin
+        conn = Fog::Compute.new(base_conf)
+        conn.describe_availability_zones.data[:body]['availabilityZoneInfo'].collect { |x| x['zoneName'] }
+      rescue Exception => e
+        puts "Zone couldn't load region #{region}: #{e.message}"
+      end
     end
 
     def load_regions
@@ -198,6 +203,23 @@ module NeoInfra
       end
     end
 
+
+    def list_dynamos
+      dynamos = []
+      Dynamo.all.order('n.sizebytes DESC').each do |d|
+        dynamos <<  {
+          'name'       => d.name,
+          'size'       => d.sizebytes,
+          'itemcount'  => d.itemcount,
+          'status'     => d.status,
+          'creation'   => d.creation,
+          'region'     => d.region.region,
+          'owner'      => d.owner.name
+        }
+      end
+      return dynamos
+    end
+
     def load_dynamo
       @cfg.accounts.each do |account|
         base_conf = {
@@ -214,7 +236,7 @@ module NeoInfra
               d = Dynamo.new(
                   tableid: 	tb['TableId'],
                   name: 	tb['TableName'],
-                  creation: 	tb['CreationDateTime'],
+                  creation: Time.at(tb['CreationDateTime']).to_datetime.strftime("%F %H:%M:%S %Z"),
                   arn: 		tb['TableArn'],
                   itemcount: 	tb['ItemCount'],
                   sizebytes: 	tb['TableSizeBytes'],

+ 1 - 1
tasks/load_data.rake

@@ -58,5 +58,5 @@ namespace :load_data do
   end
 
   desc 'Load Everything'
-  task all: %i[accounts regions vpcs buckets security_groups nodes rds]
+  task all: %i[accounts regions vpcs buckets security_groups nodes rds dynamo]
 end

+ 11 - 0
web/controllers/views.rb

@@ -37,4 +37,15 @@ class Views < Sinatra::Base
     end
   end
 
+  get '/dynamos' do
+    j = NeoInfra::Aws.new
+    respond_to do |wants|
+      wants.html {
+        erb :view_dynamos,
+        :layout => :base_layout,
+        :locals => {:dynamos => j.list_dynamos}
+      }
+    end
+  end
+
 end

+ 1 - 0
web/views/base_layout.html.erb

@@ -34,6 +34,7 @@
             <div class="dropdown-menu" aria-labelledby="dropdown01">
               <a class="dropdown-item" href="/view/vpcs">VPCs</a>
               <a class="dropdown-item" href="/view/buckets">S3 Buckets</a>
+              <a class="dropdown-item" href="/view/dynamos">Dyanmos</a>
               <a class="dropdown-item" href="/audit/tags">Tag Audit</a>
               <a class="dropdown-item" href="/load/all">Load Data</a>
             </div>

+ 32 - 0
web/views/view_dynamos.html.erb

@@ -0,0 +1,32 @@
+<h2 class="title"><br><br><center>Dynamo Tables</center></h2>
+
+<div class="container">
+  <table class="table table-hover">
+    <thead>
+      <tr>
+        <th>Name</th>
+        <th>Owner</th>
+        <th>Region</th>
+        <th>Size</th>
+        <th>Items</th>
+        <th>Creation</th>
+      </tr>
+    </thead>
+    <tbody>
+<% dynamos.each do |dynamo| %>
+<tr>
+<td><%= dynamo['name'] %></td>
+<td><%= dynamo['owner'] %></td>
+<td><%= dynamo['region'] %></td>
+<% if dynamo['size'] < 0 %>
+<td>Unknown</td>
+<% else %>
+<td><%= (dynamo['size']/1000000).round(2) %> Mb</td>
+<% end %>
+<td><%= dynamo['itemcount']%></td>
+<td><%= dynamo['creation'] %></td>
+</tr>
+<% end %>
+    </tbody>
+  </table>
+</div>