@@ -58,55 +58,73 @@ mkdir ~/monitoring && cd ~/monitoring
58
58
59
59
### Step 3: Create Prometheus config file
60
60
Create a file named ` prometheus.yml ` :
61
+ See example from my prometheus folder
61
62
``` yaml
62
63
global :
63
64
scrape_interval : 15s
64
65
scrape_configs :
65
- - job_name : ' docker '
66
+ - job_name : ' flask-app '
66
67
static_configs :
67
- - targets : ['localhost:9323']
68
+ - targets : ['web-app:5000']
69
+ - job_name : ' cadvisor'
70
+ static_configs :
71
+ - targets : ['cadvisor:9323']
68
72
` ` `
69
-
70
- ### Step 4: Run Prometheus and Grafana in Docker
73
+ ### Step 4: Create Docker Network
74
+ Docker network helps the containers in docker to communicate with each, this docker network is used among all.
75
+ Create docker network if not created. It is created in ` Github Actions` ci-cd pipeline. Check with this command. `
76
+ ` ` ` bash
77
+ docker network create devops-net
78
+ ` ` `
79
+ # ## Step 5: Run Prometheus and Grafana in Docker
71
80
` ` ` bash
72
81
# Run Prometheus
73
- docker run -d \
82
+ docker run -d --name prometheus \
83
+ --network devops-net \
74
84
-p 9090:9090 \
75
85
-v ~/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml \
76
- --name prometheus \
77
86
prom/prometheus
78
87
79
88
# Run Grafana
80
- docker run -d \
89
+ docker run -d --name grafana \
90
+ --network devops-net \
81
91
-p 3000:3000 \
82
- --name=grafana \
83
92
grafana/grafana
84
93
` ` `
85
94
86
- ### Step 5: Install Docker Metrics Exporter
95
+ # ## Step 6: (Optional) Install Docker Metrics Exporter
87
96
Prometheus needs metrics from Docker – install this exporter :
88
97
` ` ` bash
89
- docker run -d \
98
+ docker run -d --name cadvisor \
99
+ --network devops-net \
90
100
-p 9323:9323 \
91
101
-v /var/run/docker.sock:/var/run/docker.sock \
92
- --name cadvisor \
102
+ -v /:/rootfs:ro \
103
+ -v /var/run:/var/run:ro \
104
+ -v /sys:/sys:ro \
105
+ -v /var/lib/docker/:/var/lib/docker:ro \
93
106
google/cadvisor:latest
94
107
` ` `
95
108
96
- ### Step 6 : Access Grafana on Browser
109
+ # ## Step 7 : Access Grafana on Browser
97
110
Open : http://<your-azure-vm-ip>:3000
98
111
99
112
Default login :
100
113
- User : admin
101
114
- Password : admin (you'll be prompted to change)
102
115
103
- ### Step 7: Connect Prometheus as Grafana Data Source
116
+ Confirm Everything Works
117
+ 1. http://<vm-ip>:5000/metrics → Should show Flask app metrics
118
+ 2. http://<vm-ip>:9090/targets → Prometheus should show flask-app:5000 and cadvisor:9323 as UP
119
+ 3. http://<vm-ip>:3000 → Grafana dashboard
120
+
121
+ # ## Step 8: Connect Prometheus as Grafana Data Source
104
122
In Grafana :
105
123
1. Go to Settings → Data Sources → Add Prometheus
106
- 2 . URL: http://localhost :9090
124
+ 2. URL : http://<az-vm-ip> :9090
107
125
3. Click Save & Test
108
126
109
- ### Step 8 : Import a Dashboard
127
+ # ## Step 9 : Import a Dashboard
110
128
1. Go to + → Import
111
129
2. Paste Dashboard ID : 193 (Docker metrics)
112
130
3. Click Load → Select Prometheus as data source → Import
0 commit comments