Skip to content

Commit

Permalink
Implement monitoring of the application using Prometheus, Grafana, Al…
Browse files Browse the repository at this point in the history
…ertmanager, cAdvisor. Implement broadcasting of messages from Redis Pub/Sub
  • Loading branch information
rkudryashov committed Oct 31, 2021
1 parent de3f408 commit 45bd594
Show file tree
Hide file tree
Showing 18 changed files with 1,143 additions and 218 deletions.
333 changes: 187 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mongodb-redis/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ MONGODB_URI=mongodb://admin:password@localhost:27017
REDIS_URI=redis://localhost
RUST_LOG=debug
# defines whether to enable REST C(R)UD methods
ENABLE_WRITE_HANDLERS=true
ENABLE_WRITING_HANDLERS=true
4 changes: 3 additions & 1 deletion mongodb-redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"

[dependencies]
mongodb = "2.0.1"
redis = { version = "0.21.3", features = ["tokio-comp", "connection-manager"] }
redis = { version = "0.21.4", features = ["tokio-comp", "connection-manager"] }
actix-web = "4.0.0-beta.10"
tokio = "1.13.0"
tokio-stream = "0.1.8"
Expand All @@ -19,3 +19,5 @@ log = "0.4.14"
env_logger = "0.9.0"
rust-embed = "6.2.0"
mime = "0.3.16"
prometheus = { version = "0.13.0", features = ["process"] }
lazy_static = "1.4.0"
8 changes: 7 additions & 1 deletion mongodb-redis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ FROM rust:1.56

ENV CARGO_TERM_COLOR always

WORKDIR /usr/src/app/docker-build
# create empty project for caching dependencies
RUN USER=root cargo new --bin /mongodb-redis/docker-build
WORKDIR /mongodb-redis/docker-build
COPY /Cargo.lock ./
COPY /mongodb-redis/Cargo.toml ./
# cache dependencies
RUN cargo install --path . --locked
COPY /mongodb-redis/ ./
RUN touch ./src/main.rs
RUN cargo install --path . --locked

FROM debian:buster-slim
Expand Down
54 changes: 52 additions & 2 deletions mongodb-redis/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# development configuration
# development configuration + services for monitoring
version: '3.8'
services:

Expand All @@ -7,4 +7,54 @@ services:
context: ..
dockerfile: ./mongodb-redis/Dockerfile
environment:
ENABLE_WRITE_HANDLERS: 'true'
ENABLE_WRITING_HANDLERS: 'true'

# services for monitoring
# comment services below if you don't need monitoring
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
ports:
- '9090:9090'
volumes:
- ./monitoring/prometheus:/etc/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.external-url=http://localhost:9090'

grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
ports:
- '3000:3000'
volumes:
- ./monitoring/grafana/data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin

alertmanager:
image: prom/alertmanager:latest
container_name: alertmanager
ports:
- '9093:9093'
volumes:
- ./monitoring/alertmanager:/etc/alertmanager
command:
- '--config.file=/etc/alertmanager/alertmanager.yml'
- '--web.external-url=http://localhost:9093'

cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
container_name: cadvisor
restart: always
ports:
- '8080:8080'
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
9 changes: 5 additions & 4 deletions mongodb-redis/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ services:
MONGODB_URI: mongodb://$MONGODB_USERNAME:$MONGODB_PASSWORD@mongodb:27017
REDIS_URI: redis://redis
RUST_LOG: debug
ENABLE_WRITE_HANDLERS: 'false'
ENABLE_WRITING_HANDLERS: 'false'
ports:
- 9000:9000
- '9000:9000'

mongodb:
image: mongo:5
Expand All @@ -26,7 +26,7 @@ services:
MONGO_INITDB_ROOT_PASSWORD: $MONGODB_PASSWORD
MONGO_INITDB_DATABASE: solar_system_info
ports:
- 27017:27017
- '27017:27017'

mongodb-seed:
image: mongo:5
Expand All @@ -43,5 +43,6 @@ services:
redis:
image: redis:alpine
container_name: redis
restart: always
ports:
- 6379:6379
- '6379:6379'
12 changes: 12 additions & 0 deletions mongodb-redis/monitoring/alertmanager/alertmanager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
route:
receiver: gmail

receivers:
- name: gmail
email_configs:
- to: [email protected]
from: [email protected]
smarthost: smtp.gmail.com:587
auth_username: [email protected]
auth_identity: [email protected]
auth_password: password
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'default'
folder: 'default'
type: file
allowUiUpdates: true
updateIntervalSeconds: 30
options:
path: /etc/grafana/provisioning/dashboards
foldersFromFilesStructure: true
Loading

0 comments on commit 45bd594

Please sign in to comment.