lib/fluent/plugin/in_sadf.rb in fluent-plugin-sadf-0.0.1 vs lib/fluent/plugin/in_sadf.rb in fluent-plugin-sadf-0.0.2

- old
+ new

@@ -1,5 +1,7 @@ +require 'tempfile' + class SadfInput < Fluent::Input Fluent::Plugin.register_input('sadf', self) config_param :sar_option, :string, default: '' config_param :tag, :string, default: 'sadf_result.tag' @@ -39,15 +41,18 @@ end def sadf_execute(opt) rec = Hash.new - `LANG=C sadf -- #{opt} 1 1`.split("\n").each {| line | - array = line.split("\t") - if !rec.has_key?(array[3]) then - rec[array[3]] = Hash.new - end - rec[array[3]][array[4]] = array[5] + Tempfile.open('sar') {|tmpfile| + `LANG=C sar -o #{tmpfile.path} 1 1` + `LANG=C sadf -- #{opt} 1 1 #{tmpfile.path}`.split("\n").each {| line | + array = line.split("\t") + if !rec.has_key?(array[3]) then + rec[array[3]] = Hash.new + end + rec[array[3]][array[4]] = array[5] + } } rec end end