fluent-plugin-perf-tools 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6dd2ad9703a1b96567ec20ac385de14772969693
4
- data.tar.gz: 9c943fa001c678115eb59932a1b7097754f3d547
3
+ metadata.gz: 9ed0360305defb0ee3fc7b8ec534ee4b9ee18077
4
+ data.tar.gz: 477a32460779d05cab3052ce594001e1c7ba8df7
5
5
  SHA512:
6
- metadata.gz: 3e56e33e05540488735ea1d6e35ab863a47eba4803dac98757afd32d7c1b69ca6c458b0da25ee648c6018644133e8dcd1518dac4ba45cbe4a8033fd89282db8c
7
- data.tar.gz: 47cfe432dfa665345171756c5fbbaaa2e7562f80df741b06a752275602c3ecfc88e5f51ed275cc109186c4c535428bb8774ea4f388fe5468916a22e587b89a01
6
+ metadata.gz: 7103ad358638e785b7d226653e2df8a27a758b7b74abc39e59128825cbb36e7ebc590e51f9ebd5b7f7b8a2b11fb6eaac7347ba6a2b146fe4a16bcba556240c73
7
+ data.tar.gz: 306d4853ec6dbe06147daed8390f2c38c2749901aa6276c3cc31d7ec04615b2faa1b7ee81a25777a0a11183493b25978c21ced5928a647a5a9393743e5a546b8
@@ -17,7 +17,7 @@ module Fluent
17
17
  desc "Command args"
18
18
  config_param :command_args, :string, default: nil
19
19
  desc "Interval"
20
- config_param :interval, :time, default: 5
20
+ config_param :interval, :time, default: 30
21
21
 
22
22
  def configure(conf)
23
23
  super
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module PerfTools
6
+ # base class for all perf-tools command
7
+ # provides common behavior for all command
8
+ class Base
9
+ DEFAULT_INTERVAL = 30
10
+ DEFAULT_COMMAND_ARGS = ""
11
+ DEFAULT_TIME_KEY = "TIME"
12
+
13
+ class << self
14
+ attr_reader :command, :discard_regexp, :location
15
+
16
+ def set_command(command)
17
+ @command = command
18
+ end
19
+
20
+ def set_discard_regexp(regexp)
21
+ @discard_regexp = regexp
22
+ end
23
+
24
+ def set_location(location)
25
+ @location = location
26
+ end
27
+
28
+ def time_key
29
+ @time_key ||= DEFAULT_TIME_KEY
30
+ end
31
+
32
+ def set_time_key(key)
33
+ @time_key = key
34
+ end
35
+
36
+ def command_path
37
+ File.expand_path(File.join(File.expand_path(__dir__), "../../../../perf-tools/#{location}/#{command}"))
38
+ end
39
+ end
40
+
41
+ attr_reader :command_args, :interval, :time_key
42
+
43
+ def initialize(command_args:, interval:)
44
+ @command_args = command_args || DEFAULT_COMMAND_ARGS
45
+ @interval = interval || DEFAULT_INTERVAL
46
+ @time_key = DEFAULT_TIME_KEY
47
+ end
48
+
49
+ def stream
50
+ headers = nil
51
+ IO.popen("sudo #{command_path} #{command_args} #{interval}").each do |line|
52
+ next if discard_regexp && line.match(discard_regexp)
53
+
54
+ unless headers
55
+ headers = line.split
56
+ next
57
+ end
58
+
59
+ record = headers.zip(line.split).to_h
60
+ time = parse_time(record)
61
+
62
+ yield time, record
63
+ end
64
+ end
65
+
66
+ def parse_time(record)
67
+ if time_key && record.respond_to?(:has_key?) && record.key?(time_key)
68
+ Fluent::EventTime.from_time(Time.parse(record[time_key]))
69
+ else
70
+ Fluent::EventTime.now
71
+ end
72
+ end
73
+
74
+ def command_path
75
+ self.class.command_path
76
+ end
77
+
78
+ def discard_regexp
79
+ self.class.discard_regexp
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,62 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "base"
4
+
3
5
  module Fluent
4
6
  module Plugin
5
7
  module PerfTools
6
- class Cachestat
7
- COMMAND = "cachestat"
8
- DEFAULT_INTERVAL = 30
9
- DEFAULT_COMMAND_ARGS = "-t"
10
- EXTRA_INFO_REGEXP = /^Counting cache functions...|^Ending tracing.../
11
- TIME_KEY = 'TIME'
12
-
13
- def self.command
14
- COMMAND
15
- end
16
-
17
- def self.command_path
18
- File.expand_path(File.join(File.expand_path(__dir__), "../../../../perf-tools/fs/#{COMMAND}"))
19
- end
20
-
21
- attr_reader :command_args, :interval
22
-
23
- def initialize(command_args:, interval:)
24
- @command_args = command_args || DEFAULT_COMMAND_ARGS
25
- @interval = interval || DEFAULT_INTERVAL
26
- end
27
-
28
- def command_path
29
- self.class.command_path
30
- end
31
-
32
- def time_key
33
- TIME_KEY
34
- end
35
-
36
- def stream
37
- headers = nil
38
- IO.popen("sudo #{command_path} #{command_args} #{interval}").each do |line|
39
- next if line.match(EXTRA_INFO_REGEXP)
40
-
41
- unless headers
42
- headers = line.split
43
- next
44
- end
45
-
46
- record = headers.zip(line.split).to_h
47
- time = parse_time(record)
48
-
49
- yield time, record
50
- end
51
- end
52
-
53
- def parse_time(record)
54
- if time_key && record.respond_to?(:has_key?) && record.has_key?(time_key)
55
- Fluent::EventTime.from_time(Time.parse(record[time_key]))
56
- else
57
- Fluent::EventTime.now
58
- end
59
- end
8
+ class Cachestat < Base
9
+ set_command "cachestat"
10
+ set_location "fs"
11
+ set_discard_regexp /^Counting cache functions...|^Ending tracing.../
60
12
  end
61
13
 
62
14
  Command.reference(Cachestat)
@@ -3,7 +3,7 @@
3
3
  module Fluent
4
4
  module Plugin
5
5
  module PerfTools
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-perf-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Tych
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -237,6 +237,7 @@ files:
237
237
  - fluent-plugin-perf-tools.gemspec
238
238
  - lib/fluent/plugin/in_perf_tools.rb
239
239
  - lib/fluent/plugin/perf_tools.rb
240
+ - lib/fluent/plugin/perf_tools/base.rb
240
241
  - lib/fluent/plugin/perf_tools/cachestat.rb
241
242
  - lib/fluent/plugin/perf_tools/command.rb
242
243
  - lib/fluent/plugin/perf_tools/version.rb