Skip to content

Commit

Permalink
ELK Docker-Compose & Documentation (#64)
Browse files Browse the repository at this point in the history
* ELK Docker-Compose & Documentation
* Logs Tests
  • Loading branch information
Ealenn authored Jan 22, 2021
1 parent 53bd302 commit 7d79360
Show file tree
Hide file tree
Showing 13 changed files with 300 additions and 45 deletions.
6 changes: 2 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Github
.github
.gitignore
docs
docs
*.md
Dockerfile
Dockerfile.local
docker-compose.yml
docker-compose/*

# Logs
logs
Expand Down
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ Available:
* [Combine custom actions](#Combinecustomactions)
* [Change default Queries/Request commands](#ChangedefaultQueriesRequestcommands)
* [Loggers](#Loggers)
* [Format](#Format)
* [Seq](#Seq)
* [ELK](#ELK)
* [Setting up](#Settingup)
* [Docker](#Docker)
* [Docker-Compose](#Docker-Compose)
Expand Down Expand Up @@ -243,11 +245,20 @@ HTTP/1.1 401 Unauthorized
| Environment | CLI | Default |
|------------------------------------|------------------------------------|--------------------|
| LOGS__APP | --logs:app | `echo-server` |
| LOGS__LEVEL | --logs:level | `debug` |
| LOGS__LEVEL | --logs:level | `debug` |
| LOGS__FORMAT | --logs:format | `default` |

### <a name='Format'></a>Format

| LOG FORMAT | DESCRIPTION |
|-------------------|-----------------------------------------------------------------------------|
| default | Combine `line` & `object` |
| line | Simple `Fri, 22 Jan 2021 10:45:20 GMT | [GET] - http://localhost:8080/path` |
| object | JSON `{ "host": {}, http: {}, request: {}}` |

### <a name='Seq'></a>Seq

![seq](https://ealenn.github.io/Echo-Server/assets/images/seq.png)
[Full example](https://github.com/Ealenn/Echo-Server/tree/master/docker-compose) - [Documentation](https://ealenn.github.io/Echo-Server/pages/quick-start/docker-compose.html)

| Environment | CLI | Default |
|------------------------------------|------------------------------------|--------------------|
Expand All @@ -256,6 +267,10 @@ HTTP/1.1 401 Unauthorized
| LOGS__SEQ__KEY | --logs:seq:key | ` ` |
| LOGS__SEQ__LEVEL | --logs:seq:level | `info` |

### <a name='ELK'></a>ELK

[Full example](https://github.com/Ealenn/Echo-Server/tree/master/docker-compose) - [Documentation](https://ealenn.github.io/Echo-Server/pages/quick-start/docker-compose.html)

## <a name='Settingup'></a>Setting up

### <a name='Docker'></a>Docker
Expand Down Expand Up @@ -285,7 +300,6 @@ services:
```yaml
version: "3"

services:
echo:
image: ealen/echo-server
Expand Down
7 changes: 7 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage:
range: 90..100
round: down
precision: 2
ignore:
- "test/*"
- "src/middlewares/logMiddleware.js"
28 changes: 0 additions & 28 deletions docker-compose.yml

This file was deleted.

File renamed without changes.
48 changes: 48 additions & 0 deletions docker-compose/ELK/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3"
services:
# ----------------------------------
# ECHO-SERVER
# ----------------------------------
echo:
build:
context: ../../
dockerfile: docker-compose/Dockerfile.local
restart: unless-stopped
logging:
driver: syslog
options:
syslog-address: "tcp://localhost:8089"
environment:
- "LOGS__FORMAT=object"
depends_on:
- logstash
ports:
- 3000:80

# ----------------------------------
# ELK
# ----------------------------------
elasticsearch:
image: elasticsearch:7.7.0
hostname: elasticsearch
restart: unless-stopped
environment:
- "discovery.type=single-node"
kibana:
image: kibana:7.7.0
hostname: kibana
restart: unless-stopped
depends_on:
- elasticsearch
ports:
- 3010:5601
logstash:
image: logstash:7.7.0
hostname: logstash
restart: unless-stopped
volumes:
- ./logstash:/usr/share/logstash/pipeline/
depends_on:
- elasticsearch
ports:
- 8089:8089
9 changes: 9 additions & 0 deletions docker-compose/ELK/logstash/logstash.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
input {
tcp {
port => 8089
}
}

output {
elasticsearch { hosts => ["elasticsearch:9200"] }
}
27 changes: 27 additions & 0 deletions docker-compose/SEQ/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
# ----------------------------------
# ECHO-SERVER
# ----------------------------------
echo:
build:
context: ../../
dockerfile: ../Dockerfile.local
restart: unless-stopped
environment:
PORT: 80
LOGS__SEQ__ENABLED: "true"
LOGS__SEQ__SERVER: "http://seq:5341"
ports:
- 3000:80

# ----------------------------------
# SEQ
# ----------------------------------
seq:
image: datalust/seq:latest
restart: unless-stopped
environment:
ACCEPT_EULA: "Y"
ports:
- 3010:80
9 changes: 9 additions & 0 deletions docs/pages/configuration/loggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ nav_order: 2
| LOGS__IGNORE__PING | --logs:ignore:ping | `false` |
| LOGS__APP | --logs:app | `echo-server` |
| LOGS__LEVEL | --logs:level | `debug` |
| LOGS__FORMAT | --logs:format | `default` |

### Format

| LOG FORMAT | DESCRIPTION |
|-------------------|-----------------------------------------------------------------------------|
| default | Combine `line` and `object` |
| line | Simple `Fri, 22 Jan 2021 10:45:20 GMT | [GET] - http://localhost:8080/path` |
| object | JSON `{ "host": {}, http: {}, request: {}}` |

## Seq

Expand Down
88 changes: 84 additions & 4 deletions docs/pages/quick-start/docker-compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,106 @@ services:
[More information](https://ealenn.github.io/Echo-Server/pages/configuration/loggers)
### Seq
```yaml
version: "3"
services:
# ----------------------------------
# ECHO-SERVER
# ----------------------------------
echo:
image: ealen/echo-server:{{ site.github.releases[0].tag_name }}
environment:
restart: unless-stopped
environment:
PORT: 80
LOGS__SEQ__ENABLED: "true"
LOGS__SEQ__SERVER: "http://seq:5341"
ports:
ports:
- 3000:80

# ----------------------------------
# SEQ
# ----------------------------------
seq:
image: datalust/seq:{{ site.github.releases[0].tag_name }}
environment:
image: datalust/seq:latest
restart: unless-stopped
environment:
ACCEPT_EULA: "Y"
ports:
- 3010:80
```
> - Echo-Server : [http://localhost:3000](http://localhost:3000)
> - Seq : [http://localhost:3010](http://localhost:3010)
### ELK
```conf
# ./logstash/logstash.conf
input {
tcp {
port => 8089
}
}

output {
elasticsearch { hosts => ["elasticsearch:9200"] }
}
```

```yaml
version: "3"
services:
# ----------------------------------
# ECHO-SERVER
# ----------------------------------
echo:
image: ealen/echo-server:{{ site.github.releases[0].tag_name }}
restart: unless-stopped
logging:
driver: syslog
options:
syslog-address: "tcp://localhost:8089"
environment:
- "LOGS__FORMAT=object"
depends_on:
- logstash
ports:
- 3000:80

# ----------------------------------
# ELK
# ----------------------------------
elasticsearch:
image: elasticsearch:7.7.0
hostname: elasticsearch
restart: unless-stopped
environment:
- "discovery.type=single-node"
kibana:
image: kibana:7.7.0
hostname: kibana
restart: unless-stopped
depends_on:
- elasticsearch
ports:
- 3010:5601
logstash:
image: logstash:7.7.0
hostname: logstash
restart: unless-stopped
volumes:
- ./logstash:/usr/share/logstash/pipeline/
depends_on:
- elasticsearch
ports:
- 8089:8089
```
> - Echo-Server : [http://localhost:3000](http://localhost:3000)
> - Kibana : [http://localhost:3010](http://localhost:3010)
## Examples
{% include_relative includes/section-examples.md host="localhost:3000" %}
1 change: 1 addition & 0 deletions src/global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"logs": {
"app": "echo-server",
"level": "debug",
"format": "default",
"ignore": {
"ping": false
},
Expand Down
28 changes: 22 additions & 6 deletions src/middlewares/logMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,28 @@ const log = bunyan.createLogger({

module.exports = (req, res, next) => {
if (req.originalUrl != "/ping" || !config.get('logs:ignore:ping')) {
log.info({
host: require('../response/host')(req),
http: require('../response/http')(req),
request: require('../response/request')(req),
environment: require('../response/environment')(req)
}, `${new Date().toUTCString()} | [${req.method}] - ${req.protocol}://${req.get('host')}${req.originalUrl}`);
switch (config.get('logs:format'))
{
case "line":
log.info(`${new Date().toUTCString()} | [${req.method}] - ${req.protocol}://${req.get('host')}${req.originalUrl}`);
break;
case "object":
log.info({
host: require('../response/host')(req),
http: require('../response/http')(req),
request: require('../response/request')(req),
environment: require('../response/environment')(req)
});
break;
default:
log.info({
host: require('../response/host')(req),
http: require('../response/http')(req),
request: require('../response/request')(req),
environment: require('../response/environment')(req)
}, `${new Date().toUTCString()} | [${req.method}] - ${req.protocol}://${req.get('host')}${req.originalUrl}`);
break;
}
}
next();
}
Loading

0 comments on commit 7d79360

Please sign in to comment.