Skip to content

Commit ec511f8

Browse files
author
Ganesh Hegde
committed
simple EC2/ECS helpers for dockprom
1 parent afff260 commit ec511f8

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

helpers/aws/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Prometheus on EC2 & ECS:
2+
3+
Some helpers for anyone configuring Prometheus on ECS and AWS EC2.
4+
5+
To get started on AWS ECS and EC2:
6+
7+
*For EC2/ECS nodes*:
8+
- Import the ecs task definition and add cadvisor and node-exporter service/task definition and run them on each host you want to be monitored
9+
- Any hosts which have "Monitoring: On" tag will be automatically added in the targets
10+
- Expose ports 9100 and 9191 to your Prometheus host
11+
12+
*For Prometheus host*:
13+
14+
- Copy prometheus.yml configuration present here to base prometheus configuration to enable EC2 service discovery
15+
- `docker compose up -d`
16+
17+
**Note**:
18+
Set query.staleness-delta to 1m make metrics more realtime
19+
20+
21+
### TODO
22+
- Add alerting rules based on ECS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"family": "cadvisor",
3+
"containerDefinitions": [
4+
{
5+
"name": "cadvisor",
6+
"image": "google/cadvisor",
7+
"cpu": 10,
8+
"memory": 300,
9+
"portMappings": [
10+
{
11+
"containerPort": 9191,
12+
"hostPort": 9191
13+
}
14+
],
15+
"essential": true,
16+
"privileged": true,
17+
"mountPoints": [
18+
{
19+
"sourceVolume": "root",
20+
"containerPath": "/rootfs",
21+
"readOnly": true
22+
},
23+
{
24+
"sourceVolume": "var_run",
25+
"containerPath": "/var/run",
26+
"readOnly": false
27+
},
28+
{
29+
"sourceVolume": "sys",
30+
"containerPath": "/sys",
31+
"readOnly": true
32+
},
33+
{
34+
"sourceVolume": "var_lib_docker",
35+
"containerPath": "/var/lib/docker",
36+
"readOnly": true
37+
},
38+
{
39+
"sourceVolume": "cgroup",
40+
"containerPath": "/cgroup",
41+
"readOnly": true
42+
}
43+
]
44+
}
45+
],
46+
"volumes": [
47+
{
48+
"name": "root",
49+
"host": {
50+
"sourcePath": "/"
51+
}
52+
},
53+
{
54+
"name": "var_run",
55+
"host": {
56+
"sourcePath": "/var/run"
57+
}
58+
},
59+
{
60+
"name": "sys",
61+
"host": {
62+
"sourcePath": "/sys"
63+
}
64+
},
65+
{
66+
"name": "var_lib_docker",
67+
"host": {
68+
"sourcePath": "/var/lib/docker/"
69+
}
70+
},
71+
{
72+
"name": "cgroup",
73+
"host": {
74+
"sourcePath": "/cgroup"
75+
}
76+
}
77+
]
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"family": "prometheus",
3+
"containerDefinitions": [
4+
{
5+
"portMappings": [
6+
{
7+
"hostPort": 9100,
8+
"containerPort": 9100,
9+
"protocol": "tcp"
10+
}
11+
],
12+
"essential": true,
13+
"name": "node_exporter",
14+
"image": "prom/node-exporter",
15+
"cpu": 0,
16+
"privileged": null,
17+
"memoryReservation": 150
18+
}
19+
],
20+
"volumes": [],
21+
"networkMode": "host"
22+
}

helpers/aws/prometheus.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
# Attach these labels to any time series or alerts when communicating with
6+
# external systems (federation, remote storage, Alertmanager).
7+
external_labels:
8+
monitor: 'docker-host-alpha'
9+
10+
# Load and evaluate rules in this file every 'evaluation_interval' seconds.
11+
rule_files:
12+
- "targets.rules"
13+
- "hosts.rules"
14+
- "containers.rules"
15+
16+
# A scrape configuration containing exactly one endpoint to scrape.
17+
scrape_configs:
18+
- job_name: 'nodeexporter'
19+
scrape_interval: 5s
20+
static_configs:
21+
- targets: ['nodeexporter:9100']
22+
23+
- job_name: 'cadvisor'
24+
scrape_interval: 5s
25+
static_configs:
26+
- targets: ['cadvisor:8080']
27+
28+
- job_name: 'prometheus'
29+
scrape_interval: 10s
30+
static_configs:
31+
- targets: ['localhost:9090']
32+
33+
34+
# sample scrape configuration for AWS EC2
35+
- job_name: 'nodeexporter'
36+
ec2_sd_configs:
37+
- region: us-east-1
38+
port: 9100
39+
relabel_configs:
40+
# Only monitor instances which have a tag called Monitoring "Monitoring"
41+
- source_labels: [__meta_ec2_tag_Monitoring]
42+
regex: On
43+
action: keep
44+
45+
- job_name: 'cadvisor'
46+
ec2_sd_configs:
47+
- region: us-east-1
48+
port: 9010
49+
relabel_configs:
50+
# Only monitor instances which have a tag called Monitoring "Monitoring"
51+
- source_labels: [__meta_ec2_tag_Monitoring]
52+
regex: On
53+
action: keep

0 commit comments

Comments
 (0)