Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
app/php/vendor
/volumes/logstash/logs/**/*
/var/
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,35 @@
![Build Elastic Stack](https://github.com/CodelyTV/elastic-stack-example/workflows/Build%20Elastic%20Stack/badge.svg)

## How to run the Stack

To initialize all the needed services.

```
docker-compose up -d
```

## How to run PHP sample app
## How to query the Stack directly
Https and authentication have been disabled for the sake of simplicity.

```
curl --location --request GET 'http://localhost:9200/' \
--header 'Content-Type: application/json' \
--data-raw ''
```

Install needed PHP dependencies

## How to run PHP sample app
No local setup is eneded: the php docker-compose service can be used. Access it and install the needed PHP dependencies

```
cd app && composer install
docker-compose exec php
```

Execute the PHP sample application
inside the docker install the dependencies:
```
composer install
```

Execute the PHP sample application within the docker:
```
php app/php/app.php -a fo1 -b bar
php app.php -a fo1 -b bar
```
19 changes: 11 additions & 8 deletions app/php/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Monolog\Logger;
use Elastica\Client;
use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\ElasticSearchHandler;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\RotatingFileHandler;

Expand All @@ -16,31 +15,35 @@
$stdoutHandler = new ErrorLogHandler();
$formatter = new JsonFormatter();
$stdoutHandler->setFormatter($formatter);
$log->pushHandler($stdoutHandler);

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

// Elasticsearch Handler
$elasticaClient = new Client(
[
'host' => 'localhost',
'port' => 9200
'host' => 'elasticsearch',
'port' => 9200,
'transport' => 'http',
'hosts' => ['elasticsearch:9200'],
]
);

$elasticsearchHandler = new ElasticSearchHandler($elasticaClient);
$elasticsearchHandler = new \Monolog\Handler\ElasticaHandler($elasticaClient, ['index' => 'codelytv', 'type' => 'record']);

// Register Handlers
$log->pushHandler($fileHandler);
$log->pushHandler($stdoutHandler);
$log->pushHandler($elasticsearchHandler);

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

# App Servidor A
if ($options['a'] === 'warning') {
$log->warn('Esto es un Warning', ['Servidor' => 'Servidor A']);
$log->warning('Esto es un nuevo Warning', ['Servidor' => 'Servidor A']);
} else {
$log->info('Esto es un Info', ['Servidor' => 'Servidor A']);
}
Expand Down
9 changes: 7 additions & 2 deletions app/php/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"require": {
"monolog/monolog": "^1.23",
"ruflin/elastica": "^6.0"
"ruflin/elastica": "^8.1",
"monolog/monolog": "^3.9.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
Loading