Skip to content

ELK Stack

Running the ELK stack in Docker, creating the default Kibana index pattern and shipping Java logs with Logback.

1 min read

References

Usage

Get Docker ELK Stack

Download Docker ELK Stack

Bringing up the stack

Terminal window
$ docker-compose up

Initial setup

Default Kibana index pattern creation

Create an index pattern via the Kibana API:

Terminal window
curl -XPOST -D- 'http://localhost:5601/api/saved_objects/index-pattern' -H 'Content-Type: application/json' -H 'kbn-version: 6.2.3' -d '{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'

Logback setup

pom dependencies

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.0</version>
</dependency>

logback.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>
<configuration debug="true">
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:5000</destination>
<!-- encoder is required -->
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="DEBUG">
<appender-ref ref="stash" />
</root>
</configuration>

Run the app

package com.aripd.pingerbee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MainApp {
static final Logger LOG = LoggerFactory.getLogger(MainApp.class);
public static void main(String[] args) throws Exception {
for (int i = 0; i < 10; i++) {
LOG.info("New customer successfully registered");
LOG.warn("User password will expire in two days");
LOG.error("Billing system is not available");
Thread.sleep(200);
}
}
}

Related articles

1 min read

Sonar

Static code analysis with SonarQube and SonarCloud from Maven builds.

  • Observability & Testing
  • Developer Tools
1 min read

APM

Application performance monitoring for Java servers, including setting up the Glowroot agent on GlassFish.

  • Observability & Testing
1 min read

Logback

Logback appenders: rolling file logs and writing logs to a database over JNDI.

  • Java & Jakarta EE
  • Observability & Testing

Type to search the whole site.