logstash-core 5.6.16-java → 6.0.0.alpha1-java

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.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +4 -7
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/version.rb +4 -8
  5. data/lib/logstash-core_jars.rb +12 -26
  6. data/lib/logstash/agent.rb +261 -246
  7. data/lib/logstash/api/commands/default_metadata.rb +1 -1
  8. data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
  9. data/lib/logstash/api/commands/node.rb +3 -2
  10. data/lib/logstash/api/commands/stats.rb +3 -2
  11. data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
  12. data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
  13. data/lib/logstash/bootstrap_check/default_config.rb +17 -0
  14. data/lib/logstash/compiler.rb +38 -0
  15. data/lib/logstash/compiler/lscl.rb +566 -0
  16. data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
  17. data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
  18. data/lib/logstash/config/config_ast.rb +4 -82
  19. data/lib/logstash/config/mixin.rb +73 -41
  20. data/lib/logstash/config/pipeline_config.rb +48 -0
  21. data/lib/logstash/config/source/base.rb +16 -0
  22. data/lib/logstash/config/source/local.rb +215 -0
  23. data/lib/logstash/config/source_loader.rb +125 -0
  24. data/lib/logstash/converge_result.rb +103 -0
  25. data/lib/logstash/environment.rb +6 -19
  26. data/lib/logstash/errors.rb +2 -0
  27. data/lib/logstash/execution_context.rb +4 -7
  28. data/lib/logstash/filter_delegator.rb +6 -9
  29. data/lib/logstash/inputs/base.rb +0 -2
  30. data/lib/logstash/instrument/collector.rb +5 -7
  31. data/lib/logstash/instrument/metric_store.rb +12 -12
  32. data/lib/logstash/instrument/metric_type/mean.rb +0 -5
  33. data/lib/logstash/instrument/namespaced_metric.rb +0 -4
  34. data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
  35. data/lib/logstash/instrument/null_metric.rb +0 -10
  36. data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
  37. data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
  38. data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
  39. data/lib/logstash/instrument/periodic_pollers.rb +1 -3
  40. data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
  41. data/lib/logstash/logging/logger.rb +15 -47
  42. data/lib/logstash/namespace.rb +0 -1
  43. data/lib/logstash/output_delegator.rb +5 -7
  44. data/lib/logstash/outputs/base.rb +0 -2
  45. data/lib/logstash/pipeline.rb +159 -87
  46. data/lib/logstash/pipeline_action.rb +13 -0
  47. data/lib/logstash/pipeline_action/base.rb +29 -0
  48. data/lib/logstash/pipeline_action/create.rb +47 -0
  49. data/lib/logstash/pipeline_action/reload.rb +48 -0
  50. data/lib/logstash/pipeline_action/stop.rb +23 -0
  51. data/lib/logstash/plugin.rb +0 -1
  52. data/lib/logstash/plugins/hooks_registry.rb +6 -0
  53. data/lib/logstash/plugins/registry.rb +0 -1
  54. data/lib/logstash/program.rb +14 -0
  55. data/lib/logstash/queue_factory.rb +5 -1
  56. data/lib/logstash/runner.rb +58 -80
  57. data/lib/logstash/settings.rb +3 -27
  58. data/lib/logstash/state_resolver.rb +41 -0
  59. data/lib/logstash/util/java_version.rb +6 -0
  60. data/lib/logstash/util/safe_uri.rb +12 -148
  61. data/lib/logstash/util/thread_dump.rb +4 -7
  62. data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
  63. data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
  64. data/lib/logstash/version.rb +10 -8
  65. data/locales/en.yml +3 -54
  66. data/logstash-core.gemspec +8 -35
  67. data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
  68. data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
  69. data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
  70. data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
  71. data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
  72. data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
  73. data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
  74. data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
  75. data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
  76. data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
  77. data/spec/api/spec_helper.rb +106 -0
  78. data/spec/logstash/agent/converge_spec.rb +286 -0
  79. data/spec/logstash/agent/metrics_spec.rb +244 -0
  80. data/spec/logstash/agent_spec.rb +213 -225
  81. data/spec/logstash/compiler/compiler_spec.rb +584 -0
  82. data/spec/logstash/config/config_ast_spec.rb +8 -47
  83. data/spec/logstash/config/mixin_spec.rb +2 -42
  84. data/spec/logstash/config/pipeline_config_spec.rb +75 -0
  85. data/spec/logstash/config/source/local_spec.rb +395 -0
  86. data/spec/logstash/config/source_loader_spec.rb +122 -0
  87. data/spec/logstash/converge_result_spec.rb +179 -0
  88. data/spec/logstash/event_spec.rb +0 -66
  89. data/spec/logstash/execution_context_spec.rb +8 -12
  90. data/spec/logstash/filter_delegator_spec.rb +12 -24
  91. data/spec/logstash/inputs/base_spec.rb +7 -5
  92. data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
  93. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
  94. data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
  95. data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
  96. data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
  97. data/spec/logstash/output_delegator_spec.rb +11 -20
  98. data/spec/logstash/outputs/base_spec.rb +7 -5
  99. data/spec/logstash/pipeline_action/create_spec.rb +83 -0
  100. data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
  101. data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
  102. data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
  103. data/spec/logstash/pipeline_spec.rb +81 -137
  104. data/spec/logstash/plugin_spec.rb +2 -1
  105. data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
  106. data/spec/logstash/queue_factory_spec.rb +13 -1
  107. data/spec/logstash/runner_spec.rb +29 -140
  108. data/spec/logstash/settings/writable_directory_spec.rb +10 -13
  109. data/spec/logstash/settings_spec.rb +0 -91
  110. data/spec/logstash/state_resolver_spec.rb +156 -0
  111. data/spec/logstash/timestamp_spec.rb +2 -6
  112. data/spec/logstash/util/java_version_spec.rb +22 -0
  113. data/spec/logstash/util/safe_uri_spec.rb +0 -56
  114. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
  115. data/spec/support/helpers.rb +9 -11
  116. data/spec/support/matchers.rb +96 -6
  117. data/spec/support/mocks_classes.rb +80 -0
  118. data/spec/support/shared_contexts.rb +2 -27
  119. metadata +100 -149
  120. data/lib/logstash/config/loader.rb +0 -107
  121. data/lib/logstash/config/modules_common.rb +0 -103
  122. data/lib/logstash/config/source/modules.rb +0 -55
  123. data/lib/logstash/config/string_escape.rb +0 -27
  124. data/lib/logstash/dependency_report.rb +0 -131
  125. data/lib/logstash/dependency_report_runner.rb +0 -17
  126. data/lib/logstash/elasticsearch_client.rb +0 -142
  127. data/lib/logstash/instrument/global_metrics.rb +0 -13
  128. data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
  129. data/lib/logstash/modules/cli_parser.rb +0 -74
  130. data/lib/logstash/modules/elasticsearch_config.rb +0 -22
  131. data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
  132. data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
  133. data/lib/logstash/modules/file_reader.rb +0 -36
  134. data/lib/logstash/modules/kibana_base.rb +0 -24
  135. data/lib/logstash/modules/kibana_client.rb +0 -124
  136. data/lib/logstash/modules/kibana_config.rb +0 -105
  137. data/lib/logstash/modules/kibana_dashboards.rb +0 -36
  138. data/lib/logstash/modules/kibana_importer.rb +0 -17
  139. data/lib/logstash/modules/kibana_resource.rb +0 -10
  140. data/lib/logstash/modules/kibana_settings.rb +0 -40
  141. data/lib/logstash/modules/logstash_config.rb +0 -120
  142. data/lib/logstash/modules/resource_base.rb +0 -38
  143. data/lib/logstash/modules/scaffold.rb +0 -52
  144. data/lib/logstash/modules/settings_merger.rb +0 -23
  145. data/lib/logstash/modules/util.rb +0 -17
  146. data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
  147. data/lib/logstash/util/environment_variables.rb +0 -43
  148. data/spec/logstash/config/loader_spec.rb +0 -38
  149. data/spec/logstash/config/string_escape_spec.rb +0 -24
  150. data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
  151. data/spec/logstash/modules/logstash_config_spec.rb +0 -56
  152. data/spec/logstash/modules/scaffold_spec.rb +0 -234
  153. data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
  154. data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
  155. data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
  156. data/versions-gem-copy.yml +0 -12
@@ -4,12 +4,7 @@ require "concurrent"
4
4
 
5
5
  module LogStash module Instrument module MetricType
6
6
  class Mean < Base
7
- include ::LogStash::Util::Loggable
8
-
9
7
  def initialize(namespaces, key)
10
- logger.warn("Deprecated 'mean' metric type used! This will be removed in Logstash 6.0!",
11
- :namespaces => namespaces,
12
- :key => key)
13
8
  super(namespaces, key)
14
9
 
15
10
  @counter = Concurrent::AtomicFixnum.new
@@ -43,10 +43,6 @@ module LogStash module Instrument
43
43
  def collector
44
44
  @metric.collector
45
45
  end
46
-
47
- def counter(key)
48
- collector.get(@namespace_name, key, :counter)
49
- end
50
46
 
51
47
  def namespace(name)
52
48
  NamespacedMetric.new(metric, namespace_name + Array(name))
@@ -44,10 +44,6 @@ module LogStash module Instrument
44
44
  @metric.collector
45
45
  end
46
46
 
47
- def counter(_)
48
- ::LogStash::Instrument::NullMetric::NullGauge
49
- end
50
-
51
47
  def namespace(name)
52
48
  NamespacedNullMetric.new(metric, namespace_name + Array(name))
53
49
  end
@@ -39,10 +39,6 @@ module LogStash module Instrument
39
39
  end
40
40
  end
41
41
 
42
- def counter(_)
43
- NullGauge
44
- end
45
-
46
42
  def namespace(name)
47
43
  raise MetricNoNamespaceProvided if name.nil? || name.empty?
48
44
  NamespacedNullMetric.new(self, name)
@@ -53,12 +49,6 @@ module LogStash module Instrument
53
49
  end
54
50
 
55
51
  private
56
-
57
- class NullGauge
58
- def self.increment(_)
59
- end
60
- end
61
-
62
52
  # Null implementation of the internal timer class
63
53
  #
64
54
  # @see LogStash::Instrument::TimedExecution`
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require "pathname"
2
3
  require "logstash/util/loggable"
3
4
 
4
5
  # Logic from elasticsearch/core/src/main/java/org/elasticsearch/monitor/os/OsProbe.java
@@ -6,214 +7,130 @@ require "logstash/util/loggable"
6
7
  module LogStash module Instrument module PeriodicPoller
7
8
  class Cgroup
8
9
  include LogStash::Util::Loggable
9
- class Override
10
- attr_reader :key, :value
11
- def initialize(key)
12
- @key = key
13
- @value = java.lang.System.getProperty(@key)
14
- end
15
10
 
16
- def nil?
17
- value.nil?
18
- end
11
+ CONTROL_GROUP_RE = Regexp.compile("\\d+:([^:,]+(?:,[^:,]+)?):(/.*)");
12
+ CONTROLLER_SEPARATOR_RE = ","
19
13
 
20
- def override(other)
21
- nil? ? other : value
22
- end
23
- end
14
+ PROC_SELF_CGROUP_FILE = Pathname.new("/proc/self/cgroup")
15
+ PROC_CGROUP_CPU_DIR = Pathname.new("/sys/fs/cgroup/cpu")
16
+ PROC_CGROUP_CPUACCT_DIR = Pathname.new("/sys/fs/cgroup/cpuacct")
17
+
18
+ GROUP_CPUACCT = "cpuacct"
19
+ CPUACCT_USAGE_FILE = "cpuacct.usage"
20
+
21
+ GROUP_CPU = "cpu"
22
+ CPU_FS_PERIOD_US_FILE = "cpu.cfs_period_us"
23
+ CPU_FS_QUOTA_US_FILE = "cpu.cfs_quota_us"
24
24
 
25
- ## `/proc/self/cgroup` contents look like this
26
- # 5:cpu,cpuacct:/
27
- # 4:cpuset:/
28
- # 2:net_cls,net_prio:/
29
- # 0::/user.slice/user-1000.slice/session-932.scope
30
- ## e.g. N:controller:/path-to-info
31
- # we find the controller and path
32
- # we skip the line without a controller e.g. 0::/path
33
- # we assume there are these symlinks:
34
- # `/sys/fs/cgroup/cpu` -> `/sys/fs/cgroup/cpu,cpuacct
35
- # `/sys/fs/cgroup/cpuacct` -> `/sys/fs/cgroup/cpu,cpuacct
36
-
37
- CGROUP_FILE = "/proc/self/cgroup"
38
- CPUACCT_DIR = "/sys/fs/cgroup/cpuacct"
39
- CPU_DIR = "/sys/fs/cgroup/cpu"
40
- CRITICAL_PATHS = [CGROUP_FILE, CPUACCT_DIR, CPU_DIR]
41
-
42
- CONTROLLER_CPUACCT_LABEL = "cpuacct"
43
- CONTROLLER_CPU_LABEL = "cpu"
44
-
45
- class CGroupResources
46
- CONTROL_GROUP_RE = Regexp.compile("\\d+:([^:,]+(?:,[^:,]+)?):(/.*)")
47
- CONTROLLER_SEPARATOR_RE = ","
48
-
49
- def cgroup_available?
50
- # don't cache to ivar, in case the files are mounted after logstash starts??
51
- CRITICAL_PATHS.all?{|path| ::File.exist?(path)}
25
+ CPU_STATS_FILE = "cpu.stat"
26
+
27
+ class << self
28
+ def are_cgroup_available?
29
+ [::File.exist?(PROC_SELF_CGROUP_FILE),
30
+ Dir.exist?(PROC_CGROUP_CPU_DIR),
31
+ Dir.exist?(PROC_CGROUP_CPUACCT_DIR)].all?
52
32
  end
53
33
 
54
- def controller_groups
34
+ def control_groups
55
35
  response = {}
56
- IO.readlines(CGROUP_FILE).each do |line|
36
+
37
+ read_proc_self_cgroup_lines.each do |line|
57
38
  matches = CONTROL_GROUP_RE.match(line)
58
- next if matches.nil?
59
39
  # multiples controls, same hierarchy
60
40
  controllers = matches[1].split(CONTROLLER_SEPARATOR_RE)
61
- controllers.each do |controller|
62
- case controller
63
- when CONTROLLER_CPU_LABEL
64
- response[controller] = CpuResource.new(matches[2])
65
- when CONTROLLER_CPUACCT_LABEL
66
- response[controller] = CpuAcctResource.new(matches[2])
67
- else
68
- response[controller] = UnimplementedResource.new(controller, matches[2])
69
- end
70
- end
41
+ controllers.each_with_object(response) { |controller| response[controller] = matches[2] }
71
42
  end
43
+
72
44
  response
73
45
  end
74
- end
75
46
 
76
- module ControllerResource
77
- attr_reader :base_path, :override, :offset_path
78
- def implemented?
79
- true
80
- end
81
- private
82
- def common_initialize(base, override_key, original_path)
83
- @base_path = base
84
- # override is needed here for the logging statements
85
- @override = Override.new(override_key)
86
- @offset_path = @override.override(original_path)
87
- @procs = {}
88
- @procs[:read_int] = lambda {|path| IO.readlines(path).first.to_i }
89
- @procs[:read_lines] = lambda {|path| IO.readlines(path) }
90
- end
91
- def call_if_file_exists(call_key, file, not_found_value)
92
- path = ::File.join(@base_path, @offset_path, file)
93
- if ::File.exist?(path)
94
- @procs[call_key].call(path)
95
- else
96
- message = "File #{path} cannot be found, "
97
- if override.nil?
98
- message.concat("try providing an override '#{override.key}' in the Logstash JAVA_OPTS environment variable")
99
- else
100
- message.concat("even though the '#{override.key}' override is: '#{override.value}'")
101
- end
102
- logger.debug(message)
103
- not_found_value
104
- end
47
+ def read_first_line(path)
48
+ IO.readlines(path).first
105
49
  end
106
- end
107
50
 
108
- class CpuAcctResource
109
- include LogStash::Util::Loggable
110
- include ControllerResource
111
- def initialize(original_path)
112
- common_initialize(CPUACCT_DIR, "ls.cgroup.cpuacct.path.override", original_path)
51
+ def cgroup_cpuacct_usage_nanos(control_group)
52
+ read_first_line(::File.join(PROC_CGROUP_CPUACCT_DIR, control_group, CPUACCT_USAGE_FILE)).to_i
113
53
  end
114
- def to_hash
115
- {:control_group => offset_path, :usage_nanos => cpuacct_usage}
116
- end
117
- private
118
- def cpuacct_usage
119
- call_if_file_exists(:read_int, "cpuacct.usage", -1)
120
- end
121
- end
122
54
 
123
- class CpuResource
124
- include LogStash::Util::Loggable
125
- include ControllerResource
126
- def initialize(original_path)
127
- common_initialize(CPU_DIR, "ls.cgroup.cpu.path.override", original_path)
128
- end
129
- def to_hash
130
- {
131
- :control_group => offset_path,
132
- :cfs_period_micros => cfs_period_us,
133
- :cfs_quota_micros => cfs_quota_us,
134
- :stat => build_cpu_stats_hash
135
- }
136
- end
137
- private
138
- def cfs_period_us
139
- call_if_file_exists(:read_int, "cpu.cfs_period_us", -1)
55
+ def cgroup_cpu_fs_period_micros(control_group)
56
+ read_first_line(::File.join(PROC_CGROUP_CPUACCT_DIR, control_group, CPU_FS_PERIOD_US_FILE)).to_i
140
57
  end
141
- def cfs_quota_us
142
- call_if_file_exists(:read_int, "cpu.cfs_quota_us", -1)
143
- end
144
- def build_cpu_stats_hash
145
- stats = CpuStats.new
146
- lines = call_if_file_exists(:read_lines, "cpu.stat", [])
147
- stats.update(lines)
148
- stats.to_hash
58
+
59
+ def cgroup_cpu_fs_quota_micros(control_group)
60
+ read_first_line(::File.join(PROC_CGROUP_CPUACCT_DIR, control_group, CPU_FS_QUOTA_US_FILE)).to_i
149
61
  end
150
- end
151
62
 
152
- class UnimplementedResource
153
- attr_reader :controller, :original_path
154
- def initialize(controller, original_path)
155
- @controller, @original_path = controller, original_path
63
+ def read_proc_self_cgroup_lines
64
+ IO.readlines(PROC_SELF_CGROUP_FILE)
156
65
  end
157
- def implemented?
158
- false
66
+
67
+ class CpuStats
68
+ attr_reader :number_of_elapsed_periods, :number_of_times_throttled, :time_throttled_nanos
69
+
70
+ def initialize(number_of_elapsed_periods, number_of_times_throttled, time_throttled_nanos)
71
+ @number_of_elapsed_periods = number_of_elapsed_periods
72
+ @number_of_times_throttled = number_of_times_throttled
73
+ @time_throttled_nanos = time_throttled_nanos
74
+ end
159
75
  end
160
- end
161
76
 
162
- class CpuStats
163
- def initialize
164
- @number_of_elapsed_periods = -1
165
- @number_of_times_throttled = -1
166
- @time_throttled_nanos = -1
77
+ def read_sys_fs_cgroup_cpuacct_cpu_stat(control_group)
78
+ IO.readlines(::File.join(PROC_CGROUP_CPU_DIR, control_group, CPU_STATS_FILE))
167
79
  end
168
- def update(lines)
80
+
81
+ def cgroup_cpuacct_cpu_stat(control_group)
82
+ lines = read_sys_fs_cgroup_cpuacct_cpu_stat(control_group);
83
+
84
+ number_of_elapsed_periods = -1;
85
+ number_of_times_throttled = -1;
86
+ time_throttled_nanos = -1;
87
+
169
88
  lines.each do |line|
170
89
  fields = line.split(/\s+/)
171
- next unless fields.size > 1
172
90
  case fields.first
173
- when "nr_periods" then @number_of_elapsed_periods = fields[1].to_i
174
- when "nr_throttled" then @number_of_times_throttled = fields[1].to_i
175
- when "throttled_time" then @time_throttled_nanos = fields[1].to_i
91
+ when "nr_periods" then number_of_elapsed_periods = fields[1].to_i
92
+ when "nr_throttled" then number_of_times_throttled= fields[1].to_i
93
+ when "throttled_time" then time_throttled_nanos = fields[1].to_i
176
94
  end
177
95
  end
178
- end
179
- def to_hash
180
- {
181
- :number_of_elapsed_periods => @number_of_elapsed_periods,
182
- :number_of_times_throttled => @number_of_times_throttled,
183
- :time_throttled_nanos => @time_throttled_nanos
184
- }
185
- end
186
- end
187
96
 
188
- CGROUP_RESOURCES = CGroupResources.new
97
+ CpuStats.new(number_of_elapsed_periods, number_of_times_throttled, time_throttled_nanos)
98
+ end
189
99
 
190
- class << self
191
100
  def get_all
192
- unless CGROUP_RESOURCES.cgroup_available?
193
- logger.debug("One or more required cgroup files or directories not found: #{CRITICAL_PATHS.join(', ')}")
194
- return
195
- end
101
+ groups = control_groups
102
+ return if groups.empty?
196
103
 
197
- groups = CGROUP_RESOURCES.controller_groups
104
+ cgroups_stats = {
105
+ :cpuacct => {},
106
+ :cpu => {}
107
+ }
198
108
 
199
- if groups.empty?
200
- logger.debug("The main cgroup file did not have any controllers: #{CGROUP_FILE}")
201
- return
202
- end
109
+ cpuacct_group = groups[GROUP_CPUACCT]
110
+ cgroups_stats[:cpuacct][:control_group] = cpuacct_group
111
+ cgroups_stats[:cpuacct][:usage_nanos] = cgroup_cpuacct_usage_nanos(cpuacct_group)
203
112
 
204
- cgroups_stats = {}
205
- groups.each do |name, controller|
206
- next unless controller.implemented?
207
- cgroups_stats[name.to_sym] = controller.to_hash
208
- end
209
- cgroups_stats
113
+ cpu_group = groups[GROUP_CPU]
114
+ cgroups_stats[:cpu][:control_group] = cpu_group
115
+ cgroups_stats[:cpu][:cfs_period_micros] = cgroup_cpu_fs_period_micros(cpu_group)
116
+ cgroups_stats[:cpu][:cfs_quota_micros] = cgroup_cpu_fs_quota_micros(cpu_group)
117
+
118
+ cpu_stats = cgroup_cpuacct_cpu_stat(cpu_group)
119
+
120
+ cgroups_stats[:cpu][:stat] = {
121
+ :number_of_elapsed_periods => cpu_stats.number_of_elapsed_periods,
122
+ :number_of_times_throttled => cpu_stats.number_of_times_throttled,
123
+ :time_throttled_nanos => cpu_stats.time_throttled_nanos
124
+ }
125
+
126
+ cgroups_stats
210
127
  rescue => e
211
- logger.debug("Error, cannot retrieve cgroups information", :exception => e.class.name, :message => e.message, :backtrace => e.backtrace.take(4)) if logger.debug?
128
+ logger.debug("Error, cannot retrieve cgroups information", :exception => e.class.name, :message => e.message) if logger.debug?
212
129
  nil
213
130
  end
214
131
 
215
132
  def get
216
- get_all
133
+ are_cgroup_available? ? get_all : nil
217
134
  end
218
135
  end
219
136
  end
@@ -2,19 +2,18 @@
2
2
  require "logstash/instrument/periodic_poller/base"
3
3
  require "logstash/instrument/periodic_poller/load_average"
4
4
  require "logstash/environment"
5
+ require "jrmonitor"
5
6
  require "set"
6
7
 
7
- java_import 'com.sun.management.UnixOperatingSystemMXBean'
8
8
  java_import 'java.lang.management.ManagementFactory'
9
9
  java_import 'java.lang.management.OperatingSystemMXBean'
10
10
  java_import 'java.lang.management.GarbageCollectorMXBean'
11
11
  java_import 'java.lang.management.RuntimeMXBean'
12
+ java_import 'com.sun.management.UnixOperatingSystemMXBean'
12
13
  java_import 'javax.management.MBeanServer'
13
14
  java_import 'javax.management.ObjectName'
14
15
  java_import 'javax.management.AttributeList'
15
16
  java_import 'javax.naming.directory.Attribute'
16
- java_import 'org.logstash.instrument.reports.MemoryReport'
17
- java_import 'org.logstash.instrument.reports.ProcessReport'
18
17
 
19
18
 
20
19
  module LogStash module Instrument module PeriodicPoller
@@ -51,7 +50,7 @@ module LogStash module Instrument module PeriodicPoller
51
50
  end
52
51
 
53
52
  def collect
54
- raw = MemoryReport.generate
53
+ raw = JRMonitor.memory.generate
55
54
  collect_jvm_metrics(raw)
56
55
  collect_pools_metrics(raw)
57
56
  collect_threads_metrics
@@ -82,10 +81,11 @@ module LogStash module Instrument module PeriodicPoller
82
81
  end
83
82
 
84
83
  def collect_process_metrics
85
- process_metrics = ProcessReport.generate
84
+ process_metrics = JRMonitor.process.generate
86
85
 
87
86
  path = [:jvm, :process]
88
87
 
88
+
89
89
  open_fds = process_metrics["open_file_descriptors"]
90
90
  if @peak_open_fds.nil? || open_fds > @peak_open_fds
91
91
  @peak_open_fds = open_fds
@@ -11,13 +11,9 @@ module LogStash module Instrument module PeriodicPoller
11
11
  end
12
12
 
13
13
  def collect
14
- pipelines = @agent.get_running_user_defined_pipelines
15
- unless pipelines.nil?
16
- pipelines.each {|_, pipeline|
17
- unless pipeline.nil?
18
- pipeline.collect_stats
19
- end
20
- }
14
+ pipeline_id, pipeline = @agent.running_pipelines.first
15
+ unless pipeline.nil?
16
+ pipeline.collect_stats
21
17
  end
22
18
  end
23
19
  end
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- require "logstash/instrument/periodic_poller/dlq"
3
2
  require "logstash/instrument/periodic_poller/os"
4
3
  require "logstash/instrument/periodic_poller/jvm"
5
4
  require "logstash/instrument/periodic_poller/pq"
@@ -15,8 +14,7 @@ module LogStash module Instrument
15
14
  @metric = metric
16
15
  @periodic_pollers = [PeriodicPoller::Os.new(metric),
17
16
  PeriodicPoller::JVM.new(metric),
18
- PeriodicPoller::PersistentQueue.new(metric, queue_type, pipelines),
19
- PeriodicPoller::DeadLetterQueue.new(metric, pipelines)]
17
+ PeriodicPoller::PersistentQueue.new(metric, queue_type, pipelines)]
20
18
  end
21
19
 
22
20
  def start
@@ -10,12 +10,7 @@ module LogStash module Instrument
10
10
  @events_metrics = metric.namespace([:stats, :events])
11
11
  @pipeline_metrics = metric.namespace([:stats, :pipelines, pipeline_id, :events])
12
12
  @plugin_events_metrics = metric.namespace([:stats, :pipelines, pipeline_id, :plugins, plugin_type, plugin.id.to_sym, :events])
13
- @events_metrics_counter = @events_metrics.counter(:in)
14
- @events_metrics_time = @events_metrics.counter(:queue_push_duration_in_millis)
15
- @pipeline_metrics_counter = @pipeline_metrics.counter(:in)
16
- @pipeline_metrics_time = @pipeline_metrics.counter(:queue_push_duration_in_millis)
17
- @plugin_events_metrics_counter = @plugin_events_metrics.counter(:out)
18
- @plugin_events_metrics_time = @plugin_events_metrics.counter(:queue_push_duration_in_millis)
13
+
19
14
  define_initial_metrics_values
20
15
  end
21
16
 
@@ -24,45 +19,41 @@ module LogStash module Instrument
24
19
  end
25
20
 
26
21
  def push(event)
27
- increment_counters(1)
28
- start_time = java.lang.System.current_time_millis
29
- result = @write_client.push(event)
30
- report_execution_time(start_time)
31
- result
22
+ record_metric { @write_client.push(event) }
32
23
  end
33
-
34
24
  alias_method(:<<, :push)
35
25
 
36
26
  def push_batch(batch)
37
- increment_counters(batch.size)
38
- start_time = java.lang.System.current_time_millis
39
- result = @write_client.push_batch(batch)
40
- report_execution_time(start_time)
41
- result
27
+ record_metric(batch.size) { @write_client.push_batch(batch) }
42
28
  end
43
29
 
44
30
  private
31
+ def record_metric(size = 1)
32
+ @events_metrics.increment(:in, size)
33
+ @pipeline_metrics.increment(:in, size)
34
+ @plugin_events_metrics.increment(:out, size)
45
35
 
46
- def increment_counters(size)
47
- @events_metrics_counter.increment(size)
48
- @pipeline_metrics_counter.increment(size)
49
- @plugin_events_metrics_counter.increment(size)
50
- end
36
+ clock = @events_metrics.time(:queue_push_duration_in_millis)
51
37
 
52
- def report_execution_time(start_time)
53
- execution_time = java.lang.System.current_time_millis - start_time
54
- @events_metrics_time.increment(execution_time)
55
- @pipeline_metrics_time.increment(execution_time)
56
- @plugin_events_metrics_time.increment(execution_time)
38
+ result = yield
39
+
40
+ # Reuse the same values for all the endpoints to make sure we don't have skew in times.
41
+ execution_time = clock.stop
42
+
43
+ @pipeline_metrics.report_time(:queue_push_duration_in_millis, execution_time)
44
+ @plugin_events_metrics.report_time(:queue_push_duration_in_millis, execution_time)
45
+
46
+ result
57
47
  end
58
48
 
59
49
  def define_initial_metrics_values
60
- @events_metrics_counter.increment(0)
61
- @pipeline_metrics_counter.increment(0)
62
- @plugin_events_metrics_counter.increment(0)
63
- @events_metrics_time.increment(0)
64
- @pipeline_metrics_time.increment(0)
65
- @plugin_events_metrics_time.increment(0)
50
+ @events_metrics.increment(:in, 0)
51
+ @pipeline_metrics.increment(:in, 0)
52
+ @plugin_events_metrics.increment(:out, 0)
53
+
54
+ @events_metrics.report_time(:queue_push_duration_in_millis, 0)
55
+ @pipeline_metrics.report_time(:queue_push_duration_in_millis, 0)
56
+ @plugin_events_metrics.report_time(:queue_push_duration_in_millis, 0)
66
57
  end
67
58
  end
68
59
  end end