Skip to content

Commit

Permalink
(feat) logstash now parse application logs (manon.log)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlermitage committed Dec 12, 2018
1 parent ce5fc52 commit 966969f
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 62 deletions.
1 change: 0 additions & 1 deletion DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Application dockerized with [Jib](https://github.com/GoogleContainerTools/jib) a
* Get application logs via: `GET /manon-app-*/_search`.
* Get Nginx access logs via: `GET /manon-nginx-access-*/_search`.
* You can delete these logs via: `DELETE /manon*`. Play with application and show logs again.

* Optional: run Cerebro via Docker Compose: `./do upcerebro`.
* Visit `http://localhost:9000` and select `Main Cluster` (it's an alias for `http://elasticsearch:9200`, see `config/docker/cerebro/cerebro.conf` file for details).

Expand Down
5 changes: 3 additions & 2 deletions config/docker/docker-compose-elk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
- ~/manon-elastic-db:/usr/share/elasticsearch/data
- ./elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
environment:
ES_JAVA_OPTS: "-Xms32m -Xmx256m"
ES_JAVA_OPTS: "-Xms128m -Xmx256m"
ulimits:
memlock:
soft: -1
Expand All @@ -33,8 +33,9 @@ services:
- ~/manon-nginx-logs/:/manon-nginx/
- ./logstash/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro
- ./logstash/patterns:/opt/logstash/patterns:ro
environment:
LS_JAVA_OPTS: "-Xms32m -Xmx256m"
LS_JAVA_OPTS: "-Xms128m -Xmx256m"
depends_on:
- elasticsearch

Expand Down
3 changes: 3 additions & 0 deletions config/docker/logstash/patterns/logstash-patterns.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MSECOND [0-9]{3}
LOGBACK_DATE %{YEAR}-%{MONTHNUM}-%{MONTHDAY} %{HOUR}:%{MINUTE}:%{SECOND}.{1}%{MSECOND}
THREAD_ID [^\]]*
26 changes: 26 additions & 0 deletions config/docker/logstash/pipeline/logstash-1-inputs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
input {

# ------------------------------
# ------ Nginx access logs
# ------------------------------
file {
path => "/manon-nginx/access*.log"
start_position => "beginning"
type => "manon_nginx_access_logs"

# always (re)parse all existing files, don't use it in production
sincedb_path => "/dev/null"
}

# ------------------------------
# ------ Manon logs
# ------------------------------
file {
path => "/manon-app/manon*.log"
start_position => "beginning"
type => "manon_app_logs"

# always (re)parse all existing files, don't use it in production
sincedb_path => "/dev/null"
}
}
42 changes: 42 additions & 0 deletions config/docker/logstash/pipeline/logstash-2-filters.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# see https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns

filter {

# ------------------------------
# ------ Nginx access logs
# ------------------------------
if [type] == "manon_nginx_access_logs" {
grok {
match => [ "message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}"]
overwrite => [ "message" ]
}
mutate {
convert => ["response", "integer"]
convert => ["bytes", "integer"]
convert => ["responsetime", "float"]
}
date {
match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]
remove_field => [ "timestamp" ]
}
useragent {
source => "agent"
}
}

# ------------------------------
# ------ Manon logs
# ------------------------------
if [type] == "manon_app_logs" {
grok {
match => { "message" =>"%{LOGBACK_DATE:timestamp} \[%{THREAD_ID:thread_id}\] %{NOTSPACE:log_lvl}\s+%{NOTSPACE:j_class} L\.%{NOTSPACE:j_line} \[%{DATA:j_mdc}\] %{GREEDYDATA:content}" }
}
date {
match => [ "timestamp" , "YYYY-MM-dd HH:mm:ss,SSS", "YYYY-MM-dd HH:mm:ss.SSS" ]
}
mutate {
remove_field => [ "timestamp", "message" ]
# strip => ["content"]
}
}
}
34 changes: 34 additions & 0 deletions config/docker/logstash/pipeline/logstash-3-outputs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
output {

# ------------------------------
# ------ Nginx access logs
# ------------------------------
if [type] == "manon_nginx_access_logs" {
elasticsearch {
hosts => ["elasticsearch:9200"]
index => "manon-nginx-access-%{+YYYY.MM.dd}"
document_type => "manon_nginx_access_logs"
}

## uncomment to debug, don't use it in production
#stdout {
# codec => "rubydebug"
#}
}

# ------------------------------
# ------ Manon logs
# ------------------------------
if [type] == "manon_app_logs" {
elasticsearch {
hosts => ["elasticsearch:9200"]
index => "manon-app-%{+YYYY.MM.dd}"
document_type => "manon_app_logs"
}

## uncomment to debug, don't use it in production
#stdout {
# codec => "rubydebug"
#}
}
}
57 changes: 0 additions & 57 deletions config/docker/logstash/pipeline/logstash-pipeline.conf

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
batch:
initialize-schema: always
job.enabled: false
main.banner-mode: log
main.banner-mode: console
datasource.driver-class-name: org.mariadb.jdbc.Driver

server:
Expand All @@ -32,7 +32,6 @@ management:
web:
base-path: /actuator
exposure.include: ["configprops", "env", "health", "info", "metrics", "scheduledtasks"]

manon:
admin:
default-admin:
Expand Down

0 comments on commit 966969f

Please sign in to comment.