kifj / wildfly-logstash Goto Github PK
View Code? Open in Web Editor NEWLogstash / Filebeat appender for JBoss Wildfly
License: Apache License 2.0
Logstash / Filebeat appender for JBoss Wildfly
License: Apache License 2.0
If the logstash server is not available at wildfly startup, it will not be logged.
Hello,
I've noticed that locally saved json data is not delivered to logstash collector after long network outage.
Is it my configuration problem or stale logs should be uploaded manually or with external tools?
Thanks in advance!
/subsystem=logging/custom-formatter=LOGSTASH-PATTERN:add(class=net.logstash.logging.formatter.LogstashUtilFormatter,module=net.logstash.logging)
/subsystem=logging/periodic-rotating-file-handler=LOGSTASH:add(autoflush=true,suffix=".yyyy-MM-dd",append=true,file={path=logstash.log, relative-to=jboss.server.log.dir})
/subsystem=logging/periodic-rotating-file-handler=LOGSTASH:write-attribute(name=named-formatter,value=LOGSTASH-PATTERN)
/subsystem=logging/custom-handler=LOGSTASH-SOCKET:add(level=DEBUG,class=net.logstash.logging.handler.SocketHandler,module=net.logstash.logging,named-formatter=LOGSTASH-PATTERN,properties={protocol=TCP,hostname=collector.localnet,port=9200,subHandler=LOGSTASH})
/subsystem=logging/async-handler=LOGSTASH-ASYNC:add(queue-length=512, subhandlers=[LOGSTASH-SOCKET])
/subsystem=logging/root-logger=ROOT:add-handler(name=LOGSTASH-ASYNC)
I have ELK stack in docker and an image with wildfly which runs an application that takes time to start up. The problem I found is when you start wildfly container and logstash a bit later logs are never sent. After debbuging the module I found out the problem lies in the initialize method:
final OutputStream out = createOutputStream();
if (out == null) { <-- here
return;
}
final String encoding = getEncoding();
final UninterruptibleOutputStream outputStream = new UninterruptibleOutputStream(out);
writer = new OutputStreamWriter(outputStream, (encoding != null) ? encoding : "UTF-8");
writeHead(writer);
method createOutputStream
returns null if TcpOutpuStream is not connected. That results in not creating writer in the code above, but without throwing any exception doPublish
method walks in the condition below, sets the initialize
flag to false and never tries again to initialize writer:
if (initialize && (em.lastExceptionTimestamp < System.currentTimeMillis() - 5000)) {
initialize();
if (em.lastException == null) {
initialize = false;
}
}
I could work-around this with throwing an exception in the createOutputStream
method if the output stream is not connected - after that everything works okay:
private OutputStream createOutputStream() {
if (address == null) {
setHostname(hostName);
}
if (address != null || port >= 0) {
try {
switch (protocol) {
case SSL_TCP:
SslTcpOutputStream sos = new SslTcpOutputStream(address, port);
if (sos.isConnected()) {
return sos;
}
break;
case UDP:
return new UdpOutputStream(address, port);
case TCP:
default:
TcpOutputStream tos = new TcpOutputStream(address, port);
if (tos.isConnected()) {
return tos;
}
// this sets last exception in em and connects after a while correctly
throw new UnknownHostException("could not connect to address: " + address);
// break;
}
} catch (IOException e) {
reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE);
}
}
return null;
}
Test
Feedback via eMail: we are using Wildfly 23.0.2.Final and ELK 8.0.1, and the README seems to be out of date:
input {
file {
type => "wildfly-server"
path => "/mnt/log/logstash.log"
codec => "json"
}
}
filter {
if [type] == "wildfly-server" {
json {
source => "message"
}
}
}
output {
elasticsearch {
hosts => "elasticsearch:9200"
user => "logstash_internal"
password => "${LOGSTASH_INTERNAL_PASSWORD}"
}
}
Hello,
you have wrote a very useful thing, thanks! Maintaining logstash forwarder for each WF instance is a real pain on big traffic.
Can I ask for JDK7 build support?
My 8.x WF is build on 7th java and currently I have not possibility to upgrade.
Thanks!
to create a zip file you'll have to start maven with zip profile:
mvn package -P zip
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.