Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/buildstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Elastic Stack

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Configure VM for Elasticsearch
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Run docker-compose
run: docker-compose up -d elasticsearch kibana
- name: Wait
run: sleep 30
- name: Elasticsearch Health
run: curl http://localhost:9200/_cat/health
- name: Kibana status
run: curl http://localhost:5601/api/status
- name: PHP - Composer install
run: cd app/php && composer install
- name: PHP - Test app
run: php app/php/app.php -a fo1 -b bar
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea
app/vendor
app/php/vendor
/var/
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
[![Build Status](https://travis-ci.org/CodelyTV/elastic-stack-docker-example.svg?branch=master)](https://travis-ci.org/CodelyTV/elastic-stack-docker-example)
# Elastic Stack with Docker
![Build Elastic Stack](https://github.com/CodelyTV/elastic-stack-example/workflows/Build%20Elastic%20Stack/badge.svg)

# Elastic Stack with Docker (PHP sample App)
## How to run the Stack

Simple PHP Application using Elastic Stack running with Docker.
To initialize all the needed services.

- ``docker-compose up -d `` to initialize all the needed services.
```
docker-compose up -d
```

- ```cd app && composer install``` to install needed PHP dependencies
## How to run PHP sample app

- ```php app/app.php -a fo1 -b bar``` to execute the PHP sample application
Install needed PHP dependencies

```
cd app && composer install
```

Execute the PHP sample application

```
php app/php/app.php -a fo1 -b bar
```
21 changes: 13 additions & 8 deletions app/php/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,50 @@
require __DIR__ . '/vendor/autoload.php';

use Monolog\Logger;
use Elastica\Client;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\ElasticSearchHandler;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\RotatingFileHandler;

// create a log channel
$log = new Logger('logger');

//Log to stdout
$stdoutHandler = new \Monolog\Handler\ErrorLogHandler();
$formatter = new \Monolog\Formatter\JsonFormatter();
$stdoutHandler = new ErrorLogHandler();
$formatter = new JsonFormatter();
$stdoutHandler->setFormatter($formatter);
$log->pushHandler($stdoutHandler);

// File Handler
$fileHandler = new \Monolog\Handler\RotatingFileHandler('../var/logs/app.log', 0, Logger::DEBUG);
$formatter = new \Monolog\Formatter\JsonFormatter();
$fileHandler = new RotatingFileHandler('../var/logs/app.log', 0, Logger::DEBUG);
$formatter = new JsonFormatter();
$fileHandler->setFormatter($formatter);
$log->pushHandler($fileHandler);

// Elasticsearch Handler
$elasticaClient = new \Elastica\Client(
$elasticaClient = new Client(
[
'host' => 'localhost',
'port' => 9200
]
);

$elasticsearchHandler = new \Monolog\Handler\ElasticSearchHandler($elasticaClient);
$elasticsearchHandler = new ElasticSearchHandler($elasticaClient);
$log->pushHandler($elasticsearchHandler);

// My Application
$options = getopt('a:b:');

# App Servidor A
if ($options['a'] == 'warning') {
if ($options['a'] === 'warning') {
$log->warn('Esto es un Warning', ['Servidor' => 'Servidor A']);
} else {
$log->info('Esto es un Info', ['Servidor' => 'Servidor A']);
}

# App Servidor B
if ($options['b'] == 'error') {
if ($options['b'] === 'error') {
$log->error('Esto es un Error', ['Servidor' => 'Servidor B']);
} else {
$log->info('Esto es un Info', ['Servidor' => 'Servidor B']);
Expand Down
28 changes: 22 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
version: '3.3'
version: '3.7'

services:

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
image: docker.elastic.co/elasticsearch/elasticsearch:7.5.0
container_name: elasticsearch
ports: ['9200:9200']
environment:
- "ELASTIC_PASSWORD=elastic"
- "bootstrap.memory_lock=true"
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
- "discovery.type=single-node"
- "TAKE_FILE_OWNERSHIP=1"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- './var/elasticsearch:/usr/share/elasticsearch/data'

logstash:
image: docker.elastic.co/logstash/logstash:6.4.2
image: docker.elastic.co/logstash/logstash:7.5.0
container_name: logstash
environment:
- "ELASTIC_PASSWORD=elastic"
ports: ['9600:9600']
depends_on: ['elasticsearch']
volumes:
- './etc/logstash/pipeline:/usr/share/logstash/pipeline'
- './var/logs:/logs'

filebeat:
image: docker.elastic.co/beats/filebeat:6.4.2
image: docker.elastic.co/beats/filebeat:7.5.0
container_name: filebeat
environment:
- "ELASTIC_PASSWORD=elastic"
user: root
volumes:
- './var/filebeat/log/:/var/log/:ro'
Expand All @@ -30,9 +44,11 @@ services:
command: ["--strict.perms=false"]

kibana:
image: docker.elastic.co/kibana/kibana:6.4.2
image: docker.elastic.co/kibana/kibana:7.5.0
container_name: kibana
environment:
- "ELASTIC_PASSWORD=elastic"
ports: ['5601:5601']
depends_on:
- 'elasticsearch'
- elasticsearch

10 changes: 0 additions & 10 deletions etc/filebeat/filebeat.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
logging.level: info
logging.to_files: false

#------------------------------ Log input --------------------------------
filebeat.inputs:
- type: log
enabled: true
Expand All @@ -14,16 +13,7 @@ filebeat.inputs:
fields: ['message']
target: json

#========================== Elasticsearch output ===============================
output.elasticsearch:
hosts: ["elasticsearch:9200"]
username: elastic
password: changeme

#============================== Dashboards =====================================
#setup.dashboards:
# enabled: true
#setup.kibana:
# host: "kibana:80"
# username: elastic
# password: changeme
1 change: 0 additions & 1 deletion etc/filebeat/meta.json

This file was deleted.

1 change: 0 additions & 1 deletion etc/filebeat/registry

This file was deleted.

Empty file removed var/elasticsearch/.gitkeep
Empty file.
Empty file removed var/filebeat/.gitkeep
Empty file.