logstash-core 5.0.0.alpha3.snapshot5-java → 5.0.0.alpha3.snapshot6-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.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core/version.rb +1 -1
  3. data/lib/logstash/api/{lib/helpers/app_helpers.rb → app_helpers.rb} +0 -0
  4. data/lib/logstash/api/command_factory.rb +34 -0
  5. data/lib/logstash/api/commands/base.rb +25 -0
  6. data/lib/logstash/api/commands/stats.rb +105 -0
  7. data/lib/logstash/api/commands/system/basicinfo_command.rb +23 -0
  8. data/lib/logstash/api/commands/system/plugins_command.rb +35 -0
  9. data/lib/logstash/api/modules/base.rb +41 -0
  10. data/lib/logstash/api/modules/node.rb +24 -0
  11. data/lib/logstash/api/modules/node_stats.rb +59 -0
  12. data/lib/logstash/api/modules/plugins.rb +15 -0
  13. data/lib/logstash/api/modules/root.rb +15 -0
  14. data/lib/logstash/api/modules/stats.rb +63 -0
  15. data/lib/logstash/api/rack_app.rb +33 -0
  16. data/lib/logstash/api/service.rb +73 -0
  17. data/lib/logstash/instrument/metric_store.rb +11 -1
  18. data/lib/logstash/instrument/periodic_poller/base.rb +2 -0
  19. data/lib/logstash/instrument/periodic_poller/jvm.rb +47 -2
  20. data/lib/logstash/util/thread_dump.rb +55 -0
  21. data/lib/logstash/version.rb +1 -1
  22. data/lib/logstash/webserver.rb +15 -49
  23. data/locales/en.yml +5 -5
  24. data/logstash-core.gemspec +3 -3
  25. data/spec/api/lib/api/node_spec.rb +2 -2
  26. data/spec/api/lib/api/node_stats_spec.rb +32 -57
  27. data/spec/api/lib/api/plugins_spec.rb +2 -2
  28. data/spec/api/lib/api/root_spec.rb +2 -2
  29. data/spec/api/lib/api/support/resource_dsl_methods.rb +47 -0
  30. data/spec/api/lib/commands/stats.rb +47 -0
  31. data/spec/api/spec_helper.rb +2 -5
  32. data/spec/logstash/agent_spec.rb +1 -1
  33. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +45 -0
  34. metadata +30 -38
  35. data/lib/logstash/api/init.ru +0 -31
  36. data/lib/logstash/api/lib/app.rb +0 -40
  37. data/lib/logstash/api/lib/app/command.rb +0 -29
  38. data/lib/logstash/api/lib/app/command_factory.rb +0 -29
  39. data/lib/logstash/api/lib/app/commands/stats/events_command.rb +0 -13
  40. data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +0 -120
  41. data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +0 -25
  42. data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +0 -15
  43. data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +0 -28
  44. data/lib/logstash/api/lib/app/modules/node.rb +0 -25
  45. data/lib/logstash/api/lib/app/modules/node_stats.rb +0 -51
  46. data/lib/logstash/api/lib/app/modules/plugins.rb +0 -15
  47. data/lib/logstash/api/lib/app/modules/stats.rb +0 -21
  48. data/lib/logstash/api/lib/app/root.rb +0 -13
  49. data/lib/logstash/api/lib/app/service.rb +0 -61
  50. data/lib/logstash/api/lib/app/stats.rb +0 -56
  51. data/spec/api/lib/api/stats_spec.rb +0 -19
  52. data/spec/api/lib/commands/events_spec.rb +0 -17
  53. data/spec/api/lib/commands/jvm_spec.rb +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a41edc5a19188510be8f6b9e275f26d82538f4f
4
- data.tar.gz: e389c454d1999160f6b2a1a750999ef26c620285
3
+ metadata.gz: eadab99495c889eb6e28493c540bdee17bd9720b
4
+ data.tar.gz: c895be838504aaa3d56b816f726e67c70c9d6b1e
5
5
  SHA512:
6
- metadata.gz: b5871edf304c92f16a0bc33381894d497a06189fefc0858190d9b0a888db939074c14c515432727c4cfcdfba65159b898e2a1a42438ef40683bf507b122ffa46
7
- data.tar.gz: 6e30b256b36652be4499ab4398bab002c34d68fe92b67e65b2fd04d9f89e42a21a13591f79ba4396a891b27890405d1073950b7e87d171fe7ac98902e794606d
6
+ metadata.gz: c2ccf45abb4062a722d4ddb20004157b72c1160173cfbe836f71ef7bb5c54194ed6fb1646799fa62129abd52a20a25a9043482834c50da364a26105e840867f3
7
+ data.tar.gz: 6d4c3652e704eb0e5f227a5e876bf6a70556760f35ed610950b4568d5efeda32671249f8cc87d7bfa968770deb73b350d1b7bed730feb3eafa579bbd60ad3d9c
@@ -5,4 +5,4 @@
5
5
  # Note to authors: this should not include dashes because 'gem' barfs if
6
6
  # you include a dash in the version string.
7
7
 
8
- LOGSTASH_CORE_VERSION = "5.0.0-alpha3.snapshot5"
8
+ LOGSTASH_CORE_VERSION = "5.0.0-alpha3.snapshot6"
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require "logstash/api/service"
3
+ require "logstash/api/commands/system/basicinfo_command"
4
+ require "logstash/api/commands/system/plugins_command"
5
+ require "logstash/api/commands/stats"
6
+
7
+
8
+ module LogStash
9
+ module Api
10
+ class CommandFactory
11
+ attr_reader :factory, :service
12
+
13
+ def initialize(service)
14
+ @service = service
15
+ @factory = {
16
+ :system_basic_info => ::LogStash::Api::Commands::System::BasicInfo,
17
+ :plugins_command => ::LogStash::Api::Commands::System::Plugins,
18
+ :stats => ::LogStash::Api::Commands::Stats
19
+ }
20
+ end
21
+
22
+ def build(*klass_path)
23
+ # Get a nested path with args like (:parent, :child)
24
+ klass = klass_path.reduce(factory) {|acc,v| acc[v]}
25
+
26
+ if klass
27
+ klass.new(service)
28
+ else
29
+ raise ArgumentError, "Class path '#{klass_path}' does not map to command!"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ module LogStash
2
+ module Api
3
+ module Commands
4
+ class Base
5
+ attr_reader :service
6
+
7
+ def initialize(service = LogStash::Api::Service.instance)
8
+ @service = service
9
+ end
10
+
11
+ def hostname
12
+ service.agent.node_name
13
+ end
14
+
15
+ def uptime
16
+ service.agent.uptime
17
+ end
18
+
19
+ def started_at
20
+ (LogStash::Agent::STARTED_AT.to_f * 1000.0).to_i
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,105 @@
1
+ require "logstash/api/commands/base"
2
+ require 'logstash/util/thread_dump'
3
+
4
+ module LogStash
5
+ module Api
6
+ module Commands
7
+ class Stats < Commands::Base
8
+
9
+ def jvm
10
+ {:threads => service.get_shallow(:jvm, :threads)}
11
+ end
12
+
13
+ def process
14
+ service.get_shallow(:jvm, :process)
15
+ end
16
+
17
+ def events
18
+ service.get_shallow(:stats, :events)
19
+ end
20
+
21
+ def memory
22
+ memory = LogStash::Json.load(service.get(:jvm_memory_stats))
23
+ {
24
+ :heap_used_in_bytes => memory["heap"]["used_in_bytes"],
25
+ :heap_used_percent => memory["heap"]["used_percent"],
26
+ :heap_committed_in_bytes => memory["heap"]["committed_in_bytes"],
27
+ :heap_max_in_bytes => memory["heap"]["max_in_bytes"],
28
+ :heap_used_in_bytes => memory["heap"]["used_in_bytes"],
29
+ :non_heap_used_in_bytes => memory["non_heap"]["used_in_bytes"],
30
+ :non_heap_committed_in_bytes => memory["non_heap"]["committed_in_bytes"],
31
+ :pools => memory["pools"].inject({}) do |acc, (type, hash)|
32
+ hash.delete("committed_in_bytes")
33
+ acc[type] = hash
34
+ acc
35
+ end
36
+ }
37
+ end
38
+
39
+ def hot_threads(options={})
40
+ HotThreadsReport.new(self, options)
41
+ end
42
+
43
+ class HotThreadsReport
44
+ HOT_THREADS_STACK_TRACES_SIZE_DEFAULT = 10.freeze
45
+
46
+ def initialize(cmd, options)
47
+ @cmd = cmd
48
+ filter = { :stacktrace_size => options.fetch(:stacktrace_size, HOT_THREADS_STACK_TRACES_SIZE_DEFAULT) }
49
+ jr_dump = JRMonitor.threads.generate(filter)
50
+ @thread_dump = ::LogStash::Util::ThreadDump.new(options.merge(:dump => jr_dump))
51
+ end
52
+
53
+ def to_s
54
+ hash = to_hash
55
+ report = "#{I18n.t("logstash.web_api.hot_threads.title", :hostname => hash[:hostname], :time => hash[:time], :top_count => @thread_dump.top_count )} \n"
56
+ report << '=' * 80
57
+ report << "\n"
58
+ hash[:threads].each do |thread|
59
+ thread_report = ""
60
+ thread_report = "#{I18n.t("logstash.web_api.
61
+ hot_threads.thread_title", :percent_of_cpu_time => thread[:percent_of_cpu_time], :thread_state => thread[:state], :thread_name => thread[:name])} \n"
62
+ thread_report = "#{thread[:percent_of_cpu_time]} % of of cpu usage by #{thread[:state]} thread named '#{thread[:name]}'\n"
63
+ thread_report << "#{thread[:path]}\n" if thread[:path]
64
+ thread[:traces].each do |trace|
65
+ thread_report << "\t#{trace}\n"
66
+ end
67
+ report << thread_report
68
+ report << '-' * 80
69
+ report << "\n"
70
+ end
71
+ report
72
+ end
73
+
74
+ def to_hash
75
+ hash = { :hostname => @cmd.hostname, :time => Time.now.iso8601, :busiest_threads => @thread_dump.top_count, :threads => [] }
76
+ @thread_dump.each do |thread_name, _hash|
77
+ thread_name, thread_path = _hash["thread.name"].split(": ")
78
+ thread = { :name => thread_name,
79
+ :percent_of_cpu_time => cpu_time_as_percent(_hash),
80
+ :state => _hash["thread.state"]
81
+ }
82
+ thread[:path] = thread_path if thread_path
83
+ traces = []
84
+ _hash["thread.stacktrace"].each do |trace|
85
+ traces << trace
86
+ end
87
+ thread[:traces] = traces unless traces.empty?
88
+ hash[:threads] << thread
89
+ end
90
+ hash
91
+ end
92
+
93
+ def cpu_time_as_percent(hash)
94
+ (((cpu_time(hash) / @cmd.uptime * 1.0)*10000).to_i)/100.0
95
+ end
96
+
97
+ def cpu_time(hash)
98
+ hash["cpu.time"] / 1000000.0
99
+ end
100
+
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require 'logstash/api/commands/base'
3
+ require "logstash/util/duration_formatter"
4
+
5
+ module LogStash
6
+ module Api
7
+ module Commands
8
+ module System
9
+ class BasicInfo < Commands::Base
10
+
11
+ def run
12
+ {
13
+ "hostname" => hostname,
14
+ "version" => {
15
+ "number" => LOGSTASH_VERSION
16
+ }
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ require "logstash/api/commands/base"
3
+
4
+ module LogStash
5
+ module Api
6
+ module Commands
7
+ module System
8
+ class Plugins < Commands::Base
9
+ def run
10
+ { :total => plugins.count, :plugins => plugins }
11
+ end
12
+
13
+ private
14
+
15
+ def plugins
16
+ @plugins ||= find_plugins_gem_specs.map do |spec|
17
+ { :name => spec.name, :version => spec.version.to_s }
18
+ end.sort_by do |spec|
19
+ spec[:name]
20
+ end
21
+ end
22
+
23
+ def find_plugins_gem_specs
24
+ @specs ||= Gem::Specification.find_all.select{|spec| logstash_plugin_gem_spec?(spec)}
25
+ end
26
+
27
+ def logstash_plugin_gem_spec?(spec)
28
+ spec.metadata && spec.metadata["logstash_plugin"] == "true"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ require "logstash/api/app_helpers"
2
+ require "logstash/api/command_factory"
3
+
4
+ module LogStash
5
+ module Api
6
+ module Modules
7
+ class Base < ::Sinatra::Base
8
+ helpers AppHelpers
9
+
10
+ attr_reader :factory
11
+
12
+ if settings.environment != :production
13
+ set :raise_errors, true
14
+ set :show_exceptions, :after_handler
15
+ end
16
+
17
+ include LogStash::Util::Loggable
18
+
19
+ helpers AppHelpers
20
+
21
+ def initialize(app=nil)
22
+ super(app)
23
+ @factory = ::LogStash::Api::CommandFactory.new(LogStash::Api::Service.instance)
24
+ end
25
+
26
+ not_found do
27
+ status 404
28
+ as = params.has_key?("human") ? :string : :json
29
+ text = as == :string ? "" : {}
30
+ respond_with(text, :as => as)
31
+ end
32
+
33
+ error do
34
+ e = env['sinatra.error']
35
+ logger.error(e.message, :url => request.url, :ip => request.ip, :params => request.params, :class => e.class.name, :backtrace => e.backtrace)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Api
4
+ module Modules
5
+ class Node < ::LogStash::Api::Modules::Base
6
+ # return hot threads information
7
+ get "/hot_threads" do
8
+ ignore_idle_threads = params["ignore_idle_threads"] || true
9
+
10
+ options = {
11
+ :ignore_idle_threads => as_boolean(ignore_idle_threads),
12
+ :human => params.has_key?("human")
13
+ }
14
+ options[:threads] = params["threads"].to_i if params.has_key?("threads")
15
+
16
+ stats = factory.build(:stats)
17
+ as = options[:human] ? :string : :json
18
+ respond_with(stats.hot_threads(options), {:as => as})
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Api
4
+ module Modules
5
+ class NodeStats < ::LogStash::Api::Modules::Base
6
+
7
+ before do
8
+ @stats = factory.build(:stats)
9
+ end
10
+
11
+ # Global _stats resource where all information is
12
+ # retrieved and show
13
+ get "/" do
14
+ payload = {
15
+ :events => events_payload,
16
+ :jvm => jvm_payload,
17
+ :process => process_payload
18
+ }
19
+
20
+ respond_with payload
21
+ end
22
+
23
+ # Show all events stats information
24
+ # (for ingested, emitted, dropped)
25
+ # - #events since startup
26
+ # - #data (bytes) since startup
27
+ # - events/s
28
+ # - bytes/s
29
+ # - dropped events/s
30
+ # - events in the pipeline
31
+ get "/events" do
32
+ respond_with({ :events => events_payload })
33
+ end
34
+
35
+ get "/jvm" do
36
+ respond_with :jvm => jvm_payload
37
+ end
38
+
39
+ get "/process" do
40
+ respond_with :process => process_payload
41
+ end
42
+
43
+ private
44
+
45
+ def events_payload
46
+ @stats.events
47
+ end
48
+
49
+ def jvm_payload
50
+ @stats.jvm
51
+ end
52
+
53
+ def process_payload
54
+ @stats.process
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Api
4
+ module Modules
5
+ class Plugins < ::LogStash::Api::Modules::Base
6
+
7
+ get "/" do
8
+ command = factory.build(:plugins_command)
9
+ respond_with(command.run())
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Api
4
+ module Modules
5
+ class Root < ::LogStash::Api::Modules::Base
6
+
7
+ get "/" do
8
+ command = factory.build(:system_basic_info)
9
+ respond_with command.run
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ module Api
4
+ module Modules
5
+ class Stats < ::LogStash::Api::Modules::Base
6
+
7
+ def stats_command
8
+ factory.build(:stats)
9
+ end
10
+
11
+ # Global _stats resource where all information is
12
+ # retrieved and show
13
+ get "/" do
14
+ payload = {
15
+ :events => stats_command.events,
16
+ :jvm => { :memory => stats_command.memory }
17
+ }
18
+ respond_with payload
19
+ end
20
+
21
+
22
+ # return hot threads information
23
+ get "/jvm" do
24
+ jvm_payload = {
25
+ :timestamp => stats_command.started_at,
26
+ :uptime_in_millis => stats_command.uptime,
27
+ :mem => stats_command.memory
28
+ }
29
+ respond_with({:jvm => jvm_payload})
30
+ end
31
+
32
+ # Show all events stats information
33
+ # (for ingested, emitted, dropped)
34
+ # - #events since startup
35
+ # - #data (bytes) since startup
36
+ # - events/s
37
+ # - bytes/s
38
+ # - dropped events/s
39
+ # - events in the pipeline
40
+ get "/events" do
41
+ respond_with({ :events => stats_command.events })
42
+ end
43
+
44
+ # return hot threads information
45
+ get "/jvm/hot_threads" do
46
+ top_threads_count = params["threads"] || 3
47
+ ignore_idle_threads = params["ignore_idle_threads"] || true
48
+ options = {
49
+ :threads => top_threads_count.to_i,
50
+ :ignore_idle_threads => as_boolean(ignore_idle_threads)
51
+ }
52
+
53
+ respond_with(stats_command.hot_threads(options))
54
+ end
55
+
56
+ # return hot threads information
57
+ get "/jvm/memory" do
58
+ respond_with({ :memory => stats_command.memory })
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end