Class: Embulk::InputJstat

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input_jstat.rb

Constant Summary collapse

JSTAT_COLUMNS =

output columns of jstat (JDK8)

{
  class: {
    Loaded: 'int',
    Bytes: 'double',
    Unloader: 'int',
    Bytes: 'double',
    Time: 'double'
  },
  compiler: {
    Compiled: 'int',
    Failed: 'int',
    Invalid: 'int',
    Time: 'double',
    FailedType: 'int',
    FailedMethod: 'string'
  },
  gc: {
    S0C: 'double',
    S1C: 'double',
    S0U: 'double',
    S1U: 'double',
    EC: 'double',
    EU: 'double',
    OC: 'double',
    MC: 'double',
    MU: 'double',
    CCSC: 'double',
    CCSU: 'double',
    YGC: 'int',
    YGCT: 'double',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double'
  },
  gccause: {
    S0: 'double',
    S1: 'double',
    E: 'double',
    O: 'double',
    M: 'double',
    CCS: 'double',
    YGC: 'int',
    YGCT: 'double',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double',
    LGCC: 'string',
    GCC: 'string'
  },
  gcnew: {
    S0C: 'double',
    S1C: 'double',
    S0U: 'double',
    S1U: 'double',
    TT: 'int',
    MTT: 'double',
    DSS: 'double',
    EC: 'double',
    EU: 'double',
    YGC: 'int',
    YGCT: 'double'
  },
  gcnewcapacity: {
    NGCMN: 'double',
    NGCMX: 'double',
    NGC: 'double',
    S0CMX: 'double',
    S0C: 'double',
    S1CMX: 'double',
    S1C: 'double',
    ECMX: 'double',
    EC: 'double',
    YGC: 'int',
    FGC: 'int'
  },
  gcold: {
    MC: 'double',
    MU: 'double',
    CCSC: 'double',
    CCSU: 'double',
    OC: 'double',
    OU: 'double',
    YGC: 'int',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double'
  },
  gcoldcapacity: {
    OGCMN: 'double',
    OGCMX: 'double',
    OGC: 'double',
    OC: 'double',
    YGC: 'int',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double'
  },
  gcmetacapacity: {
    MCMN: 'double',
    MCMX: 'double',
    MC: 'double',
    CCSMN: 'double',
    CCSMX: 'double',
    CCSC: 'double',
    YGC: 'int',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double'
  },
  gcutil: {
    S0: 'double',
    S1: 'double',
    E: 'double',
    O: 'double',
    M: 'double',
    CCS: 'double',
    YGC: 'int',
    YGCT: 'double',
    FGC: 'int',
    FGCT: 'double',
    GCT: 'double'
  },
  printcompilation: {
    Compiled: 'int',
    Size: 'int',
    Type: 'int',
    Method: 'string'
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, schema, index, page_builder) ⇒ InputJstat

Returns a new instance of InputJstat.



184
185
186
# File 'lib/embulk/input_jstat.rb', line 184

def initialize(task, schema, index, page_builder)
  super
end

Class Method Details

.transaction(config, &control) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/embulk/input_jstat.rb', line 138

def self.transaction(config, &control)
  # find jstat files and push to "task".
  paths = config.param('paths', :array, default: ['/tmp']).map { |path|
    next [] unless Dir.exists?(path)
    Dir.entries(path).sort.select{|f| f.match(/^.+\.log$/)}.map do |file|
      File.expand_path(File.join(path, file))
    end
  }.flatten
  # remove checked jstat files by other threads.
  paths = paths - config.param('done', :array, default: [])
  task = {'paths' => paths}

  # generate schema by parsing a given options of jstat.
  option = config.param('option', :string, default: 'gcutil')
  option[0] = '' if option =~ /^\-/
  if !JSTAT_COLUMNS.has_key?(option.to_sym)
    raise "Wrong configuration: \"option: #{option}\". Specify a stat option of jstat correctly."
  end

  timestamp = config.param('timestamp', :bool, default: false)

  i = timestamp ? 1 : 0
  columns = JSTAT_COLUMNS[option.to_sym].each.with_index(i).map do |column, index|
    stat, type = column
    case type
    when "string"
      Column.new(index, stat.to_s, :string)
    when "int", "long"
      Column.new(index, stat.to_s, :long)
    when "double", "float"
      Column.new(index, stat.to_s, :double)
    end
  end

  if timestamp
    columns.unshift(Column.new(0, "Timestamp", :double))
  end

  #TODO: Now, force to set threads as amount of found files. Need a better idea.
  report = yield(task, columns, paths.length)

  config.merge( report['done'].flatten.compact )

  return {}
end

Instance Method Details

#runObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/embulk/input_jstat.rb', line 188

def run
  unless path = @task['paths'][@index]
    return { 'done' => [] }
  end

  File.read(path).each_line.with_index(0) do |line, i|
    stats = line.strip.split(/\s+/)

    # maybe not jstat file if a number of column is not match.
    if stats.size != @schema.size
      # if not header, maybe injected other log, e.g. console.
      i == 0 ? break : next
    end

    # ignore column heading line
    next if i == 0 && stats[0] == @schema[0]['name']

    page = []
    @schema.each_with_index do |s, i|
      case s['type']
      when :string
        page << stats[i]
      # TODO: If not numeric, raise error.
      when :long
        page << stats[i].to_i
      when :double
        page << stats[i].to_f
      else
        raise "unknown type: #{s['type']}"
      end
    end
    @page_builder.add(page)
  end
  @page_builder.finish

  {  # commit report
    'done' => path
  }
end