Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
add proxy for scraping paas apps
Browse files Browse the repository at this point in the history
This has to be a separate container because container links can't form
cycles.
  • Loading branch information
philandstuff committed May 17, 2018
1 parent 38773ff commit 8b3fe02
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion terraform/projects/app-ecs-services/config/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ scrape_configs:
- targets: ['prometheus-server.sd.ecs-monitoring.com:9090']
- job_name: paas-targets
scheme: http
proxy_url: 'http://metrics-nginx.sd.ecs-monitoring.com:8080'
proxy_url: 'http://paas-proxy:8080'
file_sd_configs:
- files: ['/etc/prometheus/targets/*.json']
refresh_interval: 30s
Expand Down
10 changes: 10 additions & 0 deletions terraform/projects/app-ecs-services/config/vhosts/paas-proxy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
server {
listen 8080;

location / {
proxy_pass https://$host$uri;
proxy_ssl_server_name on;
proxy_set_header X-CF-APP-INSTANCE $arg_cf_app_guid:$arg_cf_app_instance_index;
proxy_set_header Authorization "Bearer $arg_cf_app_guid";
}
}
24 changes: 19 additions & 5 deletions terraform/projects/app-ecs-services/prometheus-service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ resource "aws_ecs_task_definition" "prometheus_server" {
}

volume {
name = "nginx-vhosts"
host_path = "/ecs/config-from-s3/nginx/conf.d"
name = "auth-proxy"
host_path = "/ecs/config-from-s3/auth-proxy/conf.d"
}

volume {
name = "paas-proxy"
host_path = "/ecs/config-from-s3/paas-proxy/conf.d"
}
}

Expand All @@ -104,7 +109,7 @@ resource "aws_ecs_service" "prometheus_server" {

load_balancer {
target_group_arn = "${data.terraform_remote_state.app_ecs_albs.monitoring_external_tg}"
container_name = "nginx"
container_name = "auth-proxy"
container_port = 9090
}
}
Expand All @@ -120,7 +125,7 @@ resource "aws_s3_bucket_object" "prometheus-config" {

resource "aws_s3_bucket_object" "nginx-reverse-proxy" {
bucket = "${aws_s3_bucket.config_bucket.id}"
key = "prometheus/nginx/conf.d/prometheus-auth-proxy.conf"
key = "prometheus/auth-proxy/conf.d/prometheus-auth-proxy.conf"
source = "config/vhosts/auth-proxy.conf"
etag = "${md5(file("config/vhosts/auth-proxy.conf"))}"
}
Expand All @@ -130,7 +135,16 @@ resource "aws_s3_bucket_object" "nginx-reverse-proxy" {
# https://github.com/nginxinc/docker-nginx/issues/29
resource "aws_s3_bucket_object" "nginx-htpasswd" {
bucket = "${aws_s3_bucket.config_bucket.id}"
key = "prometheus/nginx/conf.d/.htpasswd"
key = "prometheus/auth-proxy/conf.d/.htpasswd"
source = "config/vhosts/.htpasswd"
etag = "${md5(file("config/vhosts/.htpasswd"))}"
}

#### paas proxy

resource "aws_s3_bucket_object" "nginx-paas-proxy" {
bucket = "${aws_s3_bucket.config_bucket.id}"
key = "prometheus/paas-proxy/conf.d/prometheus-paas-proxy.conf"
source = "config/vhosts/paas-proxy.conf"
etag = "${md5(file("config/vhosts/paas-proxy.conf"))}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"containerPath": "/etc/prometheus"
}
],
"links": [
"paas-proxy"
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
Expand All @@ -23,8 +26,8 @@
{
"name": "s3-config-grabber",
"image": "mesosphere/aws-cli",
"cpu": 256,
"memory": 256,
"cpu": 128,
"memory": 128,
"essential": false,
"mountPoints": [
{
Expand All @@ -43,10 +46,10 @@
}
},
{
"name": "nginx",
"name": "auth-proxy",
"image": "nginx:alpine",
"cpu": 256,
"memory": 256,
"cpu": 128,
"memory": 128,
"essential": true,
"portMappings": [
{
Expand All @@ -55,7 +58,7 @@
],
"mountPoints": [
{
"sourceVolume": "nginx-vhosts",
"sourceVolume": "auth-proxy",
"containerPath": "/etc/nginx/conf.d",
"readOnly": true
}
Expand All @@ -71,5 +74,32 @@
"awslogs-stream-prefix": "prometheus"
}
}
},
{
"name": "paas-proxy",
"image": "nginx:alpine",
"cpu": 128,
"memory": 128,
"essential": true,
"portMappings": [
{
"containerPort": 8080
}
],
"mountPoints": [
{
"sourceVolume": "paas-proxy",
"containerPath": "/etc/nginx/conf.d",
"readOnly": true
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "${log_group}",
"awslogs-region": "${region}",
"awslogs-stream-prefix": "prometheus"
}
}
}
]

0 comments on commit 8b3fe02

Please sign in to comment.