Skip to content

Instantly share code, notes, and snippets.

@jsvd
Created May 18, 2020 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsvd/4c2b705f84160be2a7325a2326214b91 to your computer and use it in GitHub Desktop.
Save jsvd/4c2b705f84160be2a7325a2326214b91 to your computer and use it in GitHub Desktop.
require_relative "lib/bootstrap/environment"
LogStash::Bundler.setup!({:without => [:build, :development]})
require "logstash-core"
require "logstash/environment"
require "logstash/config/source/local"
require "logstash/java_pipeline"
require "logstash/plugin"
java.lang.System.setProperty("ls.logs", "logs")
java.lang.System.setProperty("ls.log.format", "plain")
java.lang.System.setProperty("ls.log.level", "info")
java.lang.System.setProperty("ls.pipeline.separate_logs", "false")
unless java.lang.System.getProperty("log4j.configurationFile")
log4j_config_location = ::File.join("config", "log4j2.properties")
file_schema = "file://"
LogStash::Logging::Logger::reconfigure(URI.encode(file_schema + File.absolute_path(log4j_config_location)))
end
Thread.abort_on_exception = true
java_import 'org.logstash.config.ir.PipelineConfig'
java_import 'org.logstash.common.SourceWithMetadata'
settings = LogStash::SETTINGS
config_string = "input { heartbeat {} } output { }"
config_part = SourceWithMetadata.new("config_string", "config_string", 0, 0, config_string)
25.times.map do |i|
Thread.new do
psettings = settings.clone
psettings.set("pipeline.id", "main#{i}")
loop do
pcfg = PipelineConfig.new(LogStash::Config::Source::Local, "main#{i}".to_sym, [config_part], psettings)
pipeline = LogStash::JavaPipeline.new(pcfg)
t = Thread.new { pipeline.run }
sleep 0.1 until pipeline.running?
pipeline.shutdown { LogStash::ShutdownWatcher.start(pipeline) }
t.join
end
end
end.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment