#!/usr/bin/env ruby #------------------------------------------------------------------------------ # will look in dirname for the request files, for each request file # will call root script to do the concatenation # last check: 2004-08-01 # # example: # -------- # cdfopr/scripts/parse_encp_log.rb --input filename [--output=output_file] #------------------------------------------------------------------------------ require 'find' require 'fileutils' require 'getoptlong' require 'date' def usage puts "usage: concatenate.rb dirname pattern s1 s2 [debug]" exit(-1) end usage if ARGV.length < 1 opts = GetoptLong.new( [ "--input" , "-i", GetoptLong::REQUIRED_ARGUMENT ], [ "--output" , "-o", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose" , "-v", GetoptLong::NO_ARGUMENT ] ) $input_file = '' $output_file = '' $verbose = 0 #----------------------------- process the parsed options opts.each do |opt, arg| if (opt == "--input" ) ; $input_file = arg elsif (opt == "--output" ) ; $output_file = arg elsif (opt == "--verbose" ) ; $verbose = 1 else puts "hmmm .. unknown #{opt}" end if ($verbose != 0) ; puts "Option: #{opt}, arg #{arg.inspect}" ; end end #---------------------------------------------------------------------- class Record attr_reader :drive, :label, :server, :infile, :outfile, :pnfs_path, :filesize; attr_reader :rc, :mount_time, :time2now, :status, :location ; attr_reader :qwait_time, :seek_time, :transfer_time ; attr_reader :date, :disk_rate, :drive_rate, :network_rate, :overall_rate, :transfer_rate; attr_reader :nusers, :load[3], :nconcat, :nencp; attr_writer :drive, :label, :server, :infile, :outfile, :pnfs_path, :filesize; attr_writer :rc, :mount_time, :time2now, :status, :location ; attr_writer :qwait_time, :seek_time, :transfer_time ; attr_writer :date, :disk_rate, :drive_rate, :network_rate, :overall_rate, :transfer_rate; attr_writer :nusers, :load[3], :nconcat, :nencp; def initialize() @date = 0 @drive = '' @label = '' @location = 0; @infile = '' @filesize = 0; @seek_time = 0; @mount_time = 0 @pnfs_path = '' @qwait_time = 0 @seek_time = 0; @server = '' @time2now = 0; @transfer_time = 0 @rc = 0 @status = 0 @disk_rate = 0; @drive_rate = 0 @network_rate = 0 @transfer_rate = 0 @overall_rate = 0 @nusers = 0 @load[0] = 0. @load[1] = 0. @load[2] = 0. @nconcat = 0; @nencp = 0; end def clean() initialize(); end def print(opt) # to be modified to include nusers etc if (opt.upcase() == 'DATA') ; then # puts "r.print called, opt = #{opt.upcase}" printf("%12i %-20s %10i %-12s %6s %3i %8.2f %8.2f %8.2f %8.2f %2i %6.2f %6.2f %6.2f %6.2f %6.2f\n", @date, File.basename(@infile.strip), @filesize, @drive, @label, @location, @qwait_time, @transfer_time, @seek_time, @time2now, @rc, @disk_rate, @drive_rate, @network_rate, @transfer_rate, @overall_rate); end end end #---------------------------------------------------------------------- class ERecord attr_reader :filename, :nusers, :load[3], :nconcat, :nencp; attr_writer :filename, :nusers, :load[3], :nconcat, :nencp; def initialize() @filename = '' @nusers = 0 @load[0] = 0. @load[1] = 0. @load[2] = 0. @nconcat = 0; @nencp = 0; end def clean() initialize(); end def print(opt) # to be modified... if (opt.upcase() == 'DATA') ; then # puts "r.print called, opt = #{opt.upcase}" printf("%12i %-20s %10i %-12s %6s %3i %8.2f %8.2f %8.2f %8.2f %2i %6.2f %6.2f %6.2f %6.2f %6.2f\n", @date, File.basename(@infile.strip), @filesize, @drive, @label, @location, @qwait_time, @transfer_time, @seek_time, @time2now, @rc, @disk_rate, @drive_rate, @network_rate, @transfer_rate, @overall_rate); end end end #------------------------------------------------------------------------------ # #------------------------------------------------------------------------------ puts "input file = #{$input_file}" f = File.new($input_file) r = Record.new() ler = Array.new(); start = 0; f.each { |line| # puts "#{f.lineno}: #{line}" words = line.split(); x = line.split('='); if (x[0] == 'INFILE') start = 1; r.clean() end if (line.index('done with encp copy') != nil) ; then #------------------------------------------------------------------------------ # #------------------------------------------------------------------------------ # puts line r.rc = line.split('rc=')[1].to_i(); start = 0; y = line.split(' '); w = y[0]+' '+y[1]; # puts "w = #{w}" dt = DateTime.strptime(y[0]+' '+y[1],'%Y/%m/%d %H:%M:%S'); t = Time.mktime( dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec, 0) r.date = t.to_i; # puts t, r.date r.print('data') elsif (line.index('starting encp copy') != nil) ; then #----------------------------------------------------------------------- # Elena's printout , extract the filename ... the next 2 lines belong to # the same data block #----------------------------------------------------------------------- start = 2 end if (start == 1) ; then if (x.length() == 2) ; then # puts "0002: line= #{line}" if (x[0] == 'INFILE' ) ; then r.infile = x[1].strip ; end if (x[0] == 'FILESIZE' ) ; then r.filesize = x[1].strip.to_i ; end if (x[0] == 'OUTFILE' ) ; then r.outfile = x[1].strip ; end if (x[0] == 'MOUNT_TIME' ) ; then r.mount_time = x[1].strip.to_f() ; end if (x[0] == 'TRANSFER_TIME') ; then r.transfer_time = x[1].strip.to_f() ; end if (x[0] == 'SEEK_TIME' ) ; then r.seek_time = x[1].strip.to_f() ; end if (x[0] == 'QWAIT_TIME' ) ; then r.qwait_time = x[1].strip.to_f() ; end if (x[0] == 'STATUS' ) ; then r.status = x[1].strip.to_i() ; end if (x[0] == 'LABEL' ) ; then r.label = x[1].strip() ; end if (x[0] == 'DRIVE' ) ; then r.drive = x[1].strip().split(':')[0] ; end if (x[0] == 'LOCATION' ) ; then len = x[1].split('_').length(); if (len >= 2) then r.location = x[1].split('_')[2].strip.to_i() ; else puts "ERROR: #{x[1]}" puts "ERROR:" , line end end if (x[0] == 'TIME2NOW') ; then r.time2now = x[1].strip.to_f() ; end elsif (x.length() == 3) ; then #------------------------------------------------------------------------------ # lines after 'completed... #------------------------------------------------------------------------------ if (words[0] == 'Overall') then r.overall_rate = words[3].to_f() r.transfer_rate = words[8].to_f() elsif(words[0] == 'Network') then r.network_rate = words[3].to_f() r.drive_rate = words[8].to_f() elsif(words[0] == 'Disk') then r.disk_rate = words[3].to_f() end end elsif (start == 2) ; then #------------------------------------------------------------------------------ # parse ERecord - it contains just 2 lines #------------------------------------------------------------------------------ if (line.index('load average:') != nil) ; then # the first line er = ERecord.new(); # parse the line .... else # the 2nd line # parse the line... ler.push(er); start = 0; end end }