Skip to content

Commit 009405f

Browse files
committed
add: lab08 solution and report
1 parent 8c7ecf8 commit 009405f

26 files changed

Lines changed: 1609 additions & 77 deletions

ansible/playbooks/deploy-monitoring.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
# Deploy Loki Monitoring Stack
3-
# This playbook deploys the complete logging stack with Loki, Promtail, and Grafana
3+
# This playbook deploys the complete observability stack with Prometheus, Loki, Promtail, and Grafana
44

5-
- name: Deploy Loki Monitoring Stack
5+
- name: Deploy Observability Monitoring Stack
66
hosts: all
77
become: true
88

@@ -38,6 +38,7 @@
3838
3939
Services:
4040
- Grafana: http://{{ ansible_default_ipv4.address | default('localhost') }}:{{ grafana_port }}
41+
- Prometheus: http://{{ ansible_default_ipv4.address | default('localhost') }}:{{ prometheus_port }}
4142
- Loki API: http://{{ ansible_default_ipv4.address | default('localhost') }}:{{ loki_port }}
4243
- Promtail: http://{{ ansible_default_ipv4.address | default('localhost') }}:{{ promtail_port }}
4344
{% if python_app_enabled %}
@@ -49,16 +50,18 @@
4950
- Password: (check {{ monitoring_dir }}/.env on target host)
5051
5152
Configuration:
53+
- Prometheus Version: {{ prometheus_version }}
54+
- Prometheus Retention: {{ prometheus_retention_days }}d / {{ prometheus_retention_size }}
5255
- Log Retention: {{ loki_retention_period }}
5356
- Loki Version: {{ loki_version }}
5457
- Grafana Version: {{ grafana_version }}
5558
5659
Next Steps:
57-
1. Access Grafana web UI
58-
2. Verify Loki datasource is configured
59-
3. Navigate to Explore and run: {job="docker"}
60-
4. Create dashboards based on Lab 7 requirements
61-
5. Take screenshots for documentation
60+
1. Open Prometheus targets page and verify all jobs are UP
61+
2. Access Grafana web UI and verify Loki + Prometheus datasources
62+
3. Open pre-provisioned logs and metrics dashboards
63+
4. Generate app traffic and validate live metrics/log streams
64+
5. Take screenshots for Lab 8 documentation
6265
6366
Useful Commands:
6467
- View logs: docker compose -f {{ monitoring_dir }}/docker-compose.yml logs -f

ansible/roles/monitoring/README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Monitoring Ansible Role
22

3-
This Ansible role deploys the Grafana Loki monitoring stack including Loki 3.0, Promtail 3.0, and Grafana 11.3.1.
3+
This Ansible role deploys the full observability stack including Prometheus 3.9, Loki 3.0, Promtail 3.0, and Grafana 12.3 with pre-provisioned datasources and dashboards.
44

55
## Requirements
66

@@ -18,16 +18,23 @@ See `defaults/main.yml` for all available variables. Key variables:
1818
# Service versions
1919
loki_version: "3.0.0"
2020
promtail_version: "3.0.0"
21-
grafana_version: "11.3.1"
21+
grafana_version: "12.3.0"
22+
prometheus_version: "3.9.0"
2223

2324
# Service ports
25+
prometheus_port: 9090
2426
loki_port: 3100
2527
grafana_port: 3000
2628
promtail_port: 9080
2729

2830
# Loki configuration
2931
loki_retention_period: "168h" # 7 days
3032

33+
# Prometheus configuration
34+
prometheus_retention_days: 15
35+
prometheus_retention_size: "10GB"
36+
prometheus_scrape_interval: "15s"
37+
3138
# Grafana security
3239
grafana_admin_user: "admin"
3340
grafana_admin_password: "{{ vault_grafana_password }}"
@@ -96,7 +103,8 @@ ansible-playbook -i inventory/hosts.ini playbooks/deploy-monitoring.yml --limit
96103
- **Idempotent**: Safe to run multiple times
97104
- **Templated Configs**: Easy to customize via variables
98105
- **Health Checks**: Automatic service health verification
99-
- **Grafana Provisioning**: Auto-configured Loki datasource
106+
- **Grafana Provisioning**: Auto-configured Loki + Prometheus datasources
107+
- **Dashboard Provisioning**: Auto-imported logs + metrics dashboards
100108
- **Security**: Secrets managed via Ansible Vault
101109
- **Resource Limits**: Configurable resource constraints
102110
- **Multi-Environment**: Support for dev/staging/prod
@@ -105,10 +113,11 @@ ansible-playbook -i inventory/hosts.ini playbooks/deploy-monitoring.yml --limit
105113

106114
The role deploys:
107115

108-
1. **Loki**: Log aggregation with TSDB storage
109-
2. **Promtail**: Docker log collector with service discovery
110-
3. **Grafana**: Visualization with pre-configured Loki datasource
111-
4. **Python App** (optional): Application with JSON logging
116+
1. **Prometheus**: Metrics collection and TSDB storage
117+
2. **Loki**: Log aggregation with TSDB storage
118+
3. **Promtail**: Docker log collector with service discovery
119+
4. **Grafana**: Visualization with pre-configured Loki + Prometheus datasources
120+
5. **Python App** (optional): Application with JSON logging and `/metrics`
112121

113122
All services run in Docker containers managed by Docker Compose.
114123

@@ -125,7 +134,11 @@ monitoring/
125134
│ ├── docker-compose.yml.j2 # Docker Compose template
126135
│ ├── loki-config.yml.j2 # Loki configuration
127136
│ ├── promtail-config.yml.j2 # Promtail configuration
137+
│ ├── prometheus.yml.j2 # Prometheus scrape configuration
128138
│ └── env.j2 # Environment variables
139+
├── files/
140+
│ ├── grafana-app-dashboard.json
141+
│ └── grafana-logs-dashboard.json
129142
├── handlers/main.yml # Service restart handlers
130143
└── meta/main.yml # Role metadata
131144
```
@@ -135,6 +148,7 @@ monitoring/
135148
After deployment, the stack is available at:
136149
137150
- **Grafana**: http://localhost:3000
151+
- **Prometheus**: http://localhost:9090
138152
- **Loki API**: http://localhost:3100
139153
- **Promtail**: http://localhost:9080
140154

ansible/roles/monitoring/defaults/main.yml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,39 @@
44
# Service versions
55
loki_version: "3.0.0"
66
promtail_version: "3.0.0"
7-
grafana_version: "11.3.1"
7+
grafana_version: "12.3.0"
8+
prometheus_version: "3.9.0"
89

910
# Service ports
1011
loki_port: 3100
1112
grafana_port: 3000
1213
promtail_port: 9080
14+
prometheus_port: 9090
1315

1416
# Loki configuration
1517
loki_retention_period: "168h" # 7 days
1618
loki_schema_version: "v13"
1719
loki_compaction_interval: "10m"
1820
loki_retention_delete_delay: "2h"
1921

22+
# Prometheus configuration
23+
prometheus_retention_days: 15
24+
prometheus_retention_size: "10GB"
25+
prometheus_scrape_interval: "15s"
26+
27+
prometheus_targets:
28+
- job: "prometheus"
29+
targets: ["localhost:9090"]
30+
- job: "loki"
31+
targets: ["loki:3100"]
32+
path: "/metrics"
33+
- job: "grafana"
34+
targets: ["grafana:3000"]
35+
path: "/metrics"
36+
- job: "app"
37+
targets: ["app-python:5000"]
38+
path: "/metrics"
39+
2040
# Resource limits
2141
loki_memory_limit: "1G"
2242
loki_cpu_limit: "1.0"
@@ -25,8 +45,13 @@ loki_cpu_reservation: "0.5"
2545

2646
grafana_memory_limit: "1G"
2747
grafana_cpu_limit: "1.0"
28-
grafana_memory_reservation: "512M"
29-
grafana_cpu_reservation: "0.5"
48+
grafana_memory_reservation: "256M"
49+
grafana_cpu_reservation: "0.25"
50+
51+
prometheus_memory_limit: "1G"
52+
prometheus_cpu_limit: "1.0"
53+
prometheus_memory_reservation: "512M"
54+
prometheus_cpu_reservation: "0.5"
3055

3156
promtail_memory_limit: "512M"
3257
promtail_cpu_limit: "0.5"
@@ -49,6 +74,10 @@ python_app_port: 8000
4974
python_app_internal_port: 5000
5075
python_app_log_level: "INFO"
5176
python_app_context: "../app_python"
77+
python_app_memory_limit: "256M"
78+
python_app_cpu_limit: "0.5"
79+
python_app_memory_reservation: "128M"
80+
python_app_cpu_reservation: "0.25"
5281

5382
# Docker configuration
5483
docker_network_name: "logging-network"

0 commit comments

Comments
 (0)