diff --git a/.gitignore b/.gitignore index a68b3d1..d00675a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ packer/variables.json *.retry **/roles/jdauphantnginx/* jdauphant.nginx +docker/.env diff --git a/README.md b/README.md index d590dfd..d2bf26c 100644 --- a/README.md +++ b/README.md @@ -147,3 +147,25 @@ docker exec -it gitlab-runner gitlab-runner register \ - Написал стадии для Staging и Production - Добавил условия для джобы - Добавил динамические окружения + +## Monitoring 1 +### Что было сделано: +- Запустил prometheus +```shell +docker run --rm -p 9090:9090 -d --name prometheus prom/prometheus +``` +- Упорядочил структуру репозитория для Docker +- Создал Dockerfile и конфигурацию для Prometheus +- Собрал все образы для сервисов приложения +```shell +for i in ui post-py comment; do cd src/$i; bash docker_build.sh; cd -; done +``` +- Добавил сервис prometheus в docker-compose +- Изучил взаимодействие с метриками Prometheus и протестировал отслеживание состояния сервисов которые подключены к мониторингу +- Добавил Node exporter для сбора информации о работе Docker +хоста +- Запушил образы в Docker Hub + - [prometheus](https://hub.docker.com/repository/docker/baykanurov/prometheus/general) + - [post](https://hub.docker.com/repository/docker/baykanurov/post/general) + - [comment](https://hub.docker.com/repository/docker/baykanurov/comment/general) + - [ui](https://hub.docker.com/repository/docker/baykanurov/ui/general) diff --git a/src/.env.example b/docker/.env.example similarity index 100% rename from src/.env.example rename to docker/.env.example diff --git a/src/docker-compose.override.yml b/docker/docker-compose.override.yml similarity index 84% rename from src/docker-compose.override.yml rename to docker/docker-compose.override.yml index 79c5fa1..743529d 100644 --- a/src/docker-compose.override.yml +++ b/docker/docker-compose.override.yml @@ -10,33 +10,30 @@ services: ui: container_name: ui - build: ./ui image: ${USERNAME:-baykanurov}/ui:${UI_IMAGE_TAG:-1.0} command: ["puma", "--debug", "-w 2"] ports: - ${UI_PORT:-9292}:9292/tcp volumes: - - ./ui:/app:consistent + - ../src/ui:/app:consistent networks: - front_net post: container_name: post - build: ./post-py image: ${USERNAME:-baykanurov}/post:${POST_IMAGE_TAG:-1.0} volumes: - - ./post-py:/app:consistent + - ../src/post-py:/app:consistent networks: - back_net - front_net comment: container_name: comment - build: ./comment image: ${USERNAME:-baykanurov}/comment:${COMMENT_IMAGE_TAG:-1.0} command: ["puma", "--debug", "-w 2"] volumes: - - ./comment:/app:consistent + - ../src/comment:/app:consistent networks: - back_net - front_net diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..fc15f2b --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,68 @@ +version: '3.3' +services: + mongo: + container_name: post_db + image: mongo:${MONGO_IMAGE_TAG} + volumes: + - post_db:/data/db + networks: + - back_net + + ui: + container_name: ui + image: ${USERNAME}/ui:${UI_IMAGE_TAG} + ports: + - ${UI_PORT}:9292/tcp + networks: + - front_net + + post: + container_name: post + image: ${USERNAME}/post:${POST_IMAGE_TAG} + networks: + - back_net + - front_net + + comment: + container_name: comment + image: ${USERNAME}/comment:${COMMENT_IMAGE_TAG} + networks: + - back_net + - front_net + + prometheus: + image: ${USERNAME}/prometheus + ports: + - '9090:9090' + volumes: + - prometheus_data:/prometheus + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--storage.tsdb.retention=1d' + networks: + - back_net + - front_net + + node-exporter: + image: prom/node-exporter:v0.15.2 + user: root + volumes: + - /proc:/host/proc:ro + - /sys:/host/sys:ro + - /:/rootfs:ro + command: + - '--path.procfs=/host/proc' + - '--path.sysfs=/host/sys' + - '--collector.filesystem.ignored-mount-points="^/(sys|proc|dev|host|etc)($$|/)"' + networks: + - back_net + - front_net + +volumes: + post_db: + prometheus_data: + +networks: + back_net: + front_net: diff --git a/docker-monolith/Dockerfile b/docker/docker-monolith/Dockerfile similarity index 100% rename from docker-monolith/Dockerfile rename to docker/docker-monolith/Dockerfile diff --git a/docker-monolith/db_config b/docker/docker-monolith/db_config similarity index 100% rename from docker-monolith/db_config rename to docker/docker-monolith/db_config diff --git a/docker-monolith/docker-1.log b/docker/docker-monolith/docker-1.log similarity index 100% rename from docker-monolith/docker-1.log rename to docker/docker-monolith/docker-1.log diff --git a/docker-monolith/mongod.conf b/docker/docker-monolith/mongod.conf similarity index 100% rename from docker-monolith/mongod.conf rename to docker/docker-monolith/mongod.conf diff --git a/docker-monolith/start.sh b/docker/docker-monolith/start.sh similarity index 100% rename from docker-monolith/start.sh rename to docker/docker-monolith/start.sh diff --git a/monitoring/prometheus/Dockerfile b/monitoring/prometheus/Dockerfile new file mode 100644 index 0000000..22c9319 --- /dev/null +++ b/monitoring/prometheus/Dockerfile @@ -0,0 +1,2 @@ +FROM prom/prometheus:v2.1.0 +ADD prometheus.yml /etc/prometheus/ diff --git a/monitoring/prometheus/prometheus.yml b/monitoring/prometheus/prometheus.yml new file mode 100644 index 0000000..cce0142 --- /dev/null +++ b/monitoring/prometheus/prometheus.yml @@ -0,0 +1,25 @@ +--- +global: + scrape_interval: '5s' + +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: + - 'localhost:9090' + + - job_name: 'ui' + static_configs: + - targets: + - 'ui:9292' + + - job_name: 'comment' + static_configs: + - targets: + - 'comment:9292' + + + - job_name: 'node' + static_configs: + - targets: + - 'node-exporter:9100' diff --git a/src/.gitignore b/src/.gitignore index 5f651ab..5052201 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,6 +1,5 @@ build_info.txt prometheus/ -.env ## python specific *.pyc