Reporting ELK des temps d'attente des agences.
L'ambition de cette repo est de fournir une solution de reporting complète et totalement conteneurisée pour effectuer un reporting des temps d'attente en agence.
L'objectif principale est d'apprendre à:
- Dockerizer une solution
- Créer un déploiement K8S
Lancer l'API : opt-temps-attente-agences-api par le moyen que vous aurez choisi (docker
, mvn
, etc.). L'utilisation de ce projet nécessite l'installation des outils suivants :
- git
- Docker
- docker-compose
- (Facultatif) Un client REST tel que Postman ou Insomnia
Récupérer le projet :
git clone https://github.com/adriens/opt-temps-attente-agences-elk.git
cd opt-temps-attente-agences-elk
Test si l'API est up and running, par exemple :
$ curl -GET http://localhost:8081/temps-attente/agences | jq
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12818 0 12818 0 0 12818 0 --:--:-- --:--:-- --:--:-- 21579
[
{
"idAgence": 9502,
"designation": "TOMO SERVICES",
"realMaxWaitingTimeMs": 0,
"coordonneeX": 414695.3241999969,
"coordonneeY": 249399.27869999968,
"coordonneeXPrecise": 0,
"coordonneeYPrecise": 0
},
[...]
{
"idAgence": 4310,
"designation": "Agence de MOINDOU",
"realMaxWaitingTimeMs": 0,
"coordonneeX": 367105.9452000037,
"coordonneeY": 278873.54089999944,
"coordonneeXPrecise": 366555,
"coordonneeYPrecise": 278703
}
]
💡 Ou à l'aide d'un client REST (Postman ou Insomnia)
Adapter l'url de l'api dans la configuration logstash logstash\pipeline\logstash-waiting-time.conf
:
...
urls => {
waiting_time => {
url => "<url>/temps-attente/agences"
method => get
tags => waiting_time
headers => {
Accept => "application/json"
}
}
}
...
Démarrer la suite Elastic complète :
$ docker-compose --project-name opt-temps-attente-agences-elk -f elk.yml up -d
Starting elasticsearch-opt-temps-attente-agences ... done
Starting kibana-opt-temps-attente-agences ... done
Starting logstash-opt-temps-attente-agences ... done
$ docker-compose -f elk.yml ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------------
elasticsearch-opt-temps-attente-agences /tini -- /usr/local/bin/do ... Up 0.0.0.0:9200->9200/tcp, 9300/tcp
kibana-opt-temps-attente-agences /usr/local/bin/dumb-init - ... Up 0.0.0.0:5601->5601/tcp
logstash-opt-temps-attente-agences /usr/local/bin/docker-entr ... Up 5044/tcp, 9600/tcp
On peut vérifier dans les logs si logstash
a complètement démarré :
$ docker logs logstash-opt-temps-attente-agences -f
...
[INFO ] 2020-11-05 04:11:12.334 [[waiting-time]-pipeline-manager] javapipeline - Pipeline Java execution initialization time {"seconds"=>0.99}
[INFO ] 2020-11-05 04:11:12.341 [[waiting-time]-pipeline-manager] http_poller - Registering http_poller Input {:type=>nil, :schedule=>{"cron"=>"* * * * * UTC"}, :timeout=>nil}
[INFO ] 2020-11-05 04:11:12.342 [[waiting-time]-pipeline-manager] javapipeline - Pipeline started {"pipeline.id"=>"waiting-time"}
[INFO ] 2020-11-05 04:11:12.383 [Agent thread] agent - Pipelines running {:count=>1, :running_pipelines=>[:"waiting-time"], :non_running_pipelines=>[]}
[INFO ] 2020-11-05 04:11:12.547 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
...
stdout
d'exemple suite à un appel à l'api :
{
"coordonneeYPrecise" => 360314,
"coordonneeY" => 360315.82239999995,
"idAgence" => 4326,
"@version" => "1",
"realMaxWaitingTimeMs" => 0,
"designation" => "Agence de VOH",
"coordonneeXPrecise" => 263706,
"@timestamp" => 2020-11-05T04:12:01.571Z,
"coordonneeX" => 263699.49930000305,
"http_poller_metadata" => {
"request" => {
"headers" => {
"Accept" => "application/json"
},
"url" => "http://192.168.67.181:8081/temps-attente/agences",
"tags" => "waiting_time",
"method" => "get"
},
"times_retried" => 0,
"name" => "waiting_time",
"runtime_seconds" => 1.2791679999999999,
"host" => "0892b571a88b",
"response_message" => "",
"code" => 200,
"response_headers" => {
"vary" => [
[0] "Origin",
[1] "Access-Control-Request-Method",
[2] "Access-Control-Request-Headers"
],
"keep-alive" => "timeout=60",
"connection" => "keep-alive",
"content-type" => "application/json",
"date" => "Thu, 05 Nov 2020 04:12:01 GMT",
"transfer-encoding" => "chunked"
}
}
}
-
Aller à http://localhost:5601
-
Atteindre
Stack Management
depuis le menu de gauche -
Dans la page
Index Patterns
, cliquer sur le boutonCreate index pattern
-
Saisir
opt-temps-attente-agences-*
en tant qu'index pattern et cliquer surNext step
-
Sélectionner
@timestamp
en tant que Time field -
Pour finir, cliquer sur
Create index pattern
Vous êtes maintenant prêts à voir vos données dans la partie Discover
(accessible depuis le menu de gauche)
Vous pouvez aussi visualiser vos données au travers de Dashboards. Exemples de tableaux de bords :
$ docker-compose --project-name opt-temps-attente-agences-elk -f elk.yml stop
Stopping logstash-opt-temps-attente-agences ... done
Stopping kibana-opt-temps-attente-agences ... done
Stopping elasticsearch-opt-temps-attente-agences ... done