Class: Chef::Knife::HadoopHdfsUsage
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::HadoopHdfsUsage
- Includes:
- HadoopBase
- Defined in:
- lib/chef/knife/hadoop_hdfs_usage.rb
Instance Method Summary collapse
Methods included from HadoopBase
#db_connection, #hdfs_connection, included, #locate_config_value, #msg_pair
Instance Method Details
#run ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/chef/knife/hadoop_hdfs_usage.rb', line 60 def run $stdout.sync = true hdfs_usage_summary_list = [ ui.color('Configured Capacity', :bold), ui.color('Present Capacity', :bold), ui.color('DFS Remaining', :bold), ui.color('DFS Used', :bold), ui.color('DFS Used%', :bold), ui.color('Under replicated blocks', :bold), ui.color('Blocks with corrupt replicas', :bold), ui.color('Missing blocks', :bold), ui.color('Datanodes available', :bold) ] hdfs_usage_node_list = [ ui.color('Data Node', :bold), ui.color('Decommission Status', :bold), ui.color('Configured Capacity', :bold), ui.color('DFS Used', :bold), ui.color('Non DFS Used', :bold), ui.color('DFS Remaining', :bold), ui.color('DFS Used%', :bold), ui.color('DFS Remaining%', :bold), ui.color('Last contact', :bold) ] type = "#{Chef::Config[:knife][:type]}".downcase case type when 'summary' Net::SSH.start( "#{Chef::Config[:knife][:namenode_host]}", "#{Chef::Config[:knife][:ssh_user]}", :password => "#{Chef::Config[:knife][:ssh_password]}" ) do|ssh| result = ssh.exec!('hadoop dfsadmin -report') hdfs_usage_summary_list << result.match(/Configured Capacity: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/Present Capacity: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/DFS Remaining: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/DFS Used: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/DFS Used%: \d+(.*?).*/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/Under replicated blocks: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/Blocks with corrupt replicas: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/Missing blocks: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_summary_list << result.match(/Datanodes available: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") end puts ui.list(hdfs_usage_summary_list, :uneven_columns_across, 9) when 'detail' Net::SSH.start( "#{Chef::Config[:knife][:namenode_host]}", "#{Chef::Config[:knife][:ssh_user]}", :password => "#{Chef::Config[:knife][:ssh_password]}" ) do|ssh| result = ssh.exec!('hadoop dfsadmin -report') hdfs_usage_node_list << result.match(/Name: \d+(.*?).*/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/Decommission Status : \w+(.*?).*/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/Configured Capacity: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/DFS Used: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/Non DFS Used: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/DFS Remaining: \d+(.*?)/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/DFS Used%: \d+(.*?).*/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/DFS Remaining%: \d+(.*?).*/).to_s.split(':')[1].gsub(/\s+/, "") hdfs_usage_node_list << result.match(/Last contact: \w+(.*?) .*/).to_s.split(':')[1] end puts ui.list(hdfs_usage_node_list, :uneven_columns_across, 9) when 'report' Net::SSH.start( "#{Chef::Config[:knife][:namenode_host]}", "#{Chef::Config[:knife][:ssh_user]}", :password => "#{Chef::Config[:knife][:ssh_password]}" ) do|ssh| result = ssh.exec!('hadoop dfsadmin -report') file = "hdfs_usage_report_created_on_#{Time.now}.txt" File.open("/tmp/#{file}", 'w') do |f| f.write(result) f.close end hdfs_connection.create("#{Chef::Config[:knife][:dir]}/#{file}", result) end end end |