Class: Fluent::Plugin::PerfTools::Base
- Inherits:
-
Object
- Object
- Fluent::Plugin::PerfTools::Base
- Defined in:
- lib/fluent/plugin/perf_tools/base.rb
Overview
base class for all perf-tools command
provides common behavior for all command
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_INTERVAL =
30
- DEFAULT_COMMAND_ARGS =
""
- DEFAULT_TIME_KEY =
"TIME"
Class Attribute Summary collapse
-
.command ⇒ Object
readonly
Returns the value of attribute command.
-
.discard_regexp ⇒ Object
readonly
Returns the value of attribute discard_regexp.
-
.location ⇒ Object
readonly
Returns the value of attribute location.
Instance Attribute Summary collapse
-
#command_args ⇒ Object
readonly
Returns the value of attribute command_args.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#time_key ⇒ Object
readonly
Returns the value of attribute time_key.
Class Method Summary collapse
- .command_path ⇒ Object
- .set_command(command) ⇒ Object
- .set_discard_regexp(regexp) ⇒ Object
- .set_location(location) ⇒ Object
- .set_time_key(key) ⇒ Object
- .time_key ⇒ Object
Instance Method Summary collapse
- #command_path ⇒ Object
- #discard_regexp ⇒ Object
-
#initialize(command_args:, interval:) ⇒ Base
constructor
A new instance of Base.
- #parse_time(record) ⇒ Object
- #stream ⇒ Object
Constructor Details
#initialize(command_args:, interval:) ⇒ Base
Returns a new instance of Base.
43 44 45 46 47 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 43 def initialize(command_args:, interval:) @command_args = command_args || DEFAULT_COMMAND_ARGS @interval = interval || DEFAULT_INTERVAL @time_key = DEFAULT_TIME_KEY end |
Class Attribute Details
.command ⇒ Object (readonly)
Returns the value of attribute command.
14 15 16 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 14 def command @command end |
.discard_regexp ⇒ Object (readonly)
Returns the value of attribute discard_regexp.
14 15 16 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 14 def discard_regexp @discard_regexp end |
.location ⇒ Object (readonly)
Returns the value of attribute location.
14 15 16 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 14 def location @location end |
Instance Attribute Details
#command_args ⇒ Object (readonly)
Returns the value of attribute command_args.
41 42 43 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 41 def command_args @command_args end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
41 42 43 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 41 def interval @interval end |
#time_key ⇒ Object (readonly)
Returns the value of attribute time_key.
41 42 43 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 41 def time_key @time_key end |
Class Method Details
.command_path ⇒ Object
36 37 38 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 36 def command_path File.(File.join(File.(__dir__), "../../../../perf-tools/#{location}/#{command}")) end |
.set_command(command) ⇒ Object
16 17 18 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 16 def set_command(command) @command = command end |
.set_discard_regexp(regexp) ⇒ Object
20 21 22 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 20 def set_discard_regexp(regexp) @discard_regexp = regexp end |
.set_location(location) ⇒ Object
24 25 26 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 24 def set_location(location) @location = location end |
.set_time_key(key) ⇒ Object
32 33 34 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 32 def set_time_key(key) @time_key = key end |
.time_key ⇒ Object
28 29 30 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 28 def time_key @time_key ||= DEFAULT_TIME_KEY end |
Instance Method Details
#command_path ⇒ Object
74 75 76 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 74 def command_path self.class.command_path end |
#discard_regexp ⇒ Object
78 79 80 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 78 def discard_regexp self.class.discard_regexp end |
#parse_time(record) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 66 def parse_time(record) if time_key && record.respond_to?(:has_key?) && record.key?(time_key) Fluent::EventTime.from_time(Time.parse(record[time_key])) else Fluent::EventTime.now end end |
#stream ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fluent/plugin/perf_tools/base.rb', line 49 def stream headers = nil IO.popen("sudo #{command_path} #{command_args} #{interval}").each do |line| next if discard_regexp && line.match(discard_regexp) unless headers headers = line.split next end record = headers.zip(line.split).to_h time = parse_time(record) yield time, record end end |