├── .gitignore ├── Dockerfile ├── README.md ├── docker-compose.yml ├── elk ├── elasticsearch │ └── Dockerfile ├── kibana │ ├── Dockerfile │ └── config │ │ └── kibana.yml └── logstash │ ├── Dockerfile │ └── config │ └── logstash.conf ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── sarp │ │ └── elk │ │ ├── SpringbootElkApplication.java │ │ ├── controller │ │ └── UserController.java │ │ └── domain │ │ └── User.java └── resources │ ├── application.properties │ └── log4j2.xml └── test └── java └── com └── sarp └── elk └── SpringbootElkApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/java,maven,macos,intellij 2 | 3 | ### Intellij ### 4 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 5 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 6 | 7 | # User-specific stuff: 8 | .idea/**/workspace.xml 9 | .idea/**/tasks.xml 10 | .idea/dictionaries 11 | .idea* 12 | *.iml 13 | .mvn* 14 | # Sensitive or high-churn files: 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.xml 18 | .idea/**/dataSources.local.xml 19 | .idea/**/sqlDataSources.xml 20 | .idea/**/dynamic.xml 21 | .idea/**/uiDesigner.xml 22 | 23 | # Gradle: 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # CMake 28 | cmake-build-debug/ 29 | 30 | # Mongo Explorer plugin: 31 | .idea/**/mongoSettings.xml 32 | 33 | ## File-based project format: 34 | *.iws 35 | 36 | ## Plugin-specific files: 37 | 38 | # IntelliJ 39 | /out/ 40 | 41 | # mpeltonen/sbt-idea plugin 42 | .idea_modules/ 43 | 44 | # JIRA plugin 45 | atlassian-ide-plugin.xml 46 | 47 | # Cursive Clojure plugin 48 | .idea/replstate.xml 49 | 50 | # Crashlytics plugin (for Android Studio and IntelliJ) 51 | com_crashlytics_export_strings.xml 52 | crashlytics.properties 53 | crashlytics-build.properties 54 | fabric.properties 55 | 56 | ### Intellij Patch ### 57 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 58 | 59 | # *.iml 60 | # modules.xml 61 | # .idea/misc.xml 62 | # *.ipr 63 | 64 | # Sonarlint plugin 65 | .idea/sonarlint 66 | 67 | ### Java ### 68 | # Compiled class file 69 | *.class 70 | 71 | # Log file 72 | *.log 73 | 74 | # BlueJ files 75 | *.ctxt 76 | 77 | # Mobile Tools for Java (J2ME) 78 | .mtj.tmp/ 79 | 80 | # Package Files # 81 | *.jar 82 | *.war 83 | *.ear 84 | *.zip 85 | *.tar.gz 86 | *.rar 87 | 88 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 89 | hs_err_pid* 90 | 91 | ### macOS ### 92 | *.DS_Store 93 | .AppleDouble 94 | .LSOverride 95 | 96 | # Icon must end with two \r 97 | Icon 98 | 99 | # Thumbnails 100 | ._* 101 | 102 | # Files that might appear in the root of a volume 103 | .DocumentRevisions-V100 104 | .fseventsd 105 | .Spotlight-V100 106 | .TemporaryItems 107 | .Trashes 108 | .VolumeIcon.icns 109 | .com.apple.timemachine.donotpresent 110 | 111 | # Directories potentially created on remote AFP share 112 | .AppleDB 113 | .AppleDesktop 114 | Network Trash Folder 115 | Temporary Items 116 | .apdisk 117 | 118 | ### Maven ### 119 | target/ 120 | pom.xml.tag 121 | pom.xml.releaseBackup 122 | pom.xml.versionsBackup 123 | pom.xml.next 124 | release.properties 125 | dependency-reduced-pom.xml 126 | buildNumber.properties 127 | .mvn/timing.properties 128 | 129 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 130 | !/.mvn/wrapper/maven-wrapper.jar 131 | 132 | # End of https://www.gitignore.io/api/java,maven,macos,intellij 133 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | 3 | # Install maven 4 | RUN apt-get update 5 | RUN apt-get install -y maven 6 | 7 | # Adding springboot-elk app to container 8 | ADD . /usr/config-client 9 | WORKDIR /usr/config-client 10 | RUN ["mvn", "package"] 11 | 12 | EXPOSE 8080 13 | CMD ["/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-jar", "target/springboot-elk-0.0.1-SNAPSHOT.jar"] 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Elasticsearch - Logstash - Kibana 2 | ========================= 3 | 4 | Building the ELK 5 | --------------------- 6 | $ git clone https://github.com/buraksarp/docker-elk.git 7 | $ cd docker-elk 8 | 9 | This demo assumes you know how to run Docker. 10 | 11 | Building the Containers 12 | ---------------------- 13 | Nothing special if you already have Docker installed: 14 | 15 | $ docker-compose build 16 | 17 | Running Containers with the docker-compose 18 | --------------------- 19 | To run these containers: 20 | 21 | $ docker-compose up 22 | 23 | Consuming Rest Service 24 | --------------------- 25 | To consume SpringBoot app user service: 26 | 27 | $ curl http://localhost:8080/user/{userid} 28 | 29 | To view generated logs on Kibana UI: [http://localhost:5601](http://localhost:5601) 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | app: 5 | build: . 6 | ports: 7 | - "8080:8080" 8 | links: 9 | - logstash 10 | 11 | elasticsearch: 12 | build: elk/elasticsearch/ 13 | container_name: elasticsearch 14 | ports: 15 | - "9200:9200" 16 | - "9300:9300" 17 | environment: 18 | ES_JAVA_OPTS: "-Xms1g -Xmx1g" 19 | 20 | logstash: 21 | build: elk/logstash/ 22 | container_name: logstash 23 | command: -f /etc/logstash/conf.d/ 24 | volumes: 25 | - ./elk/logstash/config:/etc/logstash/conf.d 26 | ports: 27 | - "9999:9999" 28 | links: 29 | - elasticsearch 30 | 31 | kibana: 32 | build: elk/kibana/ 33 | container_name: kibana 34 | volumes: 35 | - ./elk/kibana/config/:/opt/kibana/config/ 36 | ports: 37 | - "5601:5601" 38 | links: 39 | - elasticsearch 40 | 41 | -------------------------------------------------------------------------------- /elk/elasticsearch/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM elasticsearch:5 2 | ENV ES_JAVA_OPTS="-Des.path.conf=/etc/elasticsearch" 3 | CMD ["-E", "network.host=0.0.0.0", "-E", "discovery.zen.minimum_master_nodes=1"] 4 | -------------------------------------------------------------------------------- /elk/kibana/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM kibana:5 2 | 3 | -------------------------------------------------------------------------------- /elk/kibana/config/kibana.yml: -------------------------------------------------------------------------------- 1 | server.port: 5601 2 | server.host: "0.0.0.0" 3 | elasticsearch.url: "http://elasticsearch:9200" 4 | -------------------------------------------------------------------------------- /elk/logstash/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM logstash:5 2 | -------------------------------------------------------------------------------- /elk/logstash/config/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | tcp { 3 | port => 9999 4 | codec => line 5 | } 6 | } 7 | 8 | filter { 9 | kv { 10 | source => "message" 11 | recursive => "true" 12 | } 13 | } 14 | 15 | output { 16 | elasticsearch { 17 | hosts => "elasticsearch:9200" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sarp.elk 7 | springboot-elk 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | springboot-elk 12 | Spring Boot elk 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.2.RELEASE 18 | 19 | 20 | 21 | UTF-8 22 | UTF-8 23 | 1.8 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-logging 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-actuator 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-web 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-log4j2 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/main/java/com/sarp/elk/SpringbootElkApplication.java: -------------------------------------------------------------------------------- 1 | package com.sarp.elk; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringbootElkApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringbootElkApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/sarp/elk/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.sarp.elk.controller; 2 | 3 | import java.util.GregorianCalendar; 4 | 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.PathVariable; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.sarp.elk.domain.User; 14 | 15 | @RestController 16 | public class UserController { 17 | 18 | private final Logger logger = LogManager.getLogger(this.getClass()); 19 | 20 | @RequestMapping("/user/{id}") 21 | public ResponseEntity getUserById(@PathVariable(required = true) final Long id) { 22 | 23 | logger.info("Request with the id =[" + id + "]"); 24 | 25 | final User user = new User(id, "firstname", "surname", new GregorianCalendar()); 26 | logger.info(String.format("id=[%s] firstname=[%s] surname=[%s]", user.getId(), user.getFirstname(), user.getSurname())); 27 | 28 | return new ResponseEntity<>(user, HttpStatus.OK); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/sarp/elk/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.sarp.elk.domain; 2 | 3 | import java.util.Calendar; 4 | 5 | import com.fasterxml.jackson.annotation.JsonFormat; 6 | 7 | public class User { 8 | 9 | private final Long id; 10 | private final String firstname; 11 | private final String surname; 12 | private final Calendar dateOfBirth; 13 | 14 | public User(final Long id, final String firstname, final String surname, final Calendar dateOfBirth) { 15 | this.id = id; 16 | this.firstname = firstname; 17 | this.surname = surname; 18 | this.dateOfBirth = dateOfBirth; 19 | } 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public String getFirstname() { 26 | return firstname; 27 | } 28 | 29 | public String getSurname() { 30 | return surname; 31 | } 32 | 33 | @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") 34 | public Calendar getDateOfBirth() { 35 | return dateOfBirth; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name = spring-boot-elk 2 | server.port = 8080 3 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | /home/sarp/Desktop/spring-boot-example.log 6 | logdate=(%d{ISO8601}) thread=(%thread)) level=(%level) loggerclass=(%logger{36}) message=(%msg)%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/test/java/com/sarp/elk/SpringbootElkApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sarp.elk; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringbootElkApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------