From 5228e7c7fb5ea52d77b22e2fe31c68244090034e Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Thu, 2 Mar 2023 11:00:30 -0800 Subject: [PATCH] Export envoy metrics for services --- services/service/main.tf | 1 + services/service/service_template.nomad | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/services/service/main.tf b/services/service/main.tf index 4039d18..e418a63 100644 --- a/services/service/main.tf +++ b/services/service/main.tf @@ -21,6 +21,7 @@ resource "nomad_job" "service" { templates = var.templates host_volumes = var.host_volumes + connect = anytrue([var.ingress, var.use_mysql, var.use_redis, var.use_ldap, length(var.upstreams) > 0]) upstreams = var.upstreams use_mysql = var.use_mysql use_redis = var.use_redis diff --git a/services/service/service_template.nomad b/services/service/service_template.nomad index e557136..85d2551 100644 --- a/services/service/service_template.nomad +++ b/services/service/service_template.nomad @@ -15,6 +15,11 @@ job "${name}" { to = ${service_port} } %{ endif } + %{ if connect } + port "envoy_metrics" { + to = 9123 + } + %{~ endif } } %{ if length(group_meta) > 0 } @@ -42,7 +47,7 @@ job "${name}" { name = "${replace(name, "_", "-")}" port = "main" - %{ if anytrue([ingress, use_mysql, use_redis, use_ldap, length(upstreams) > 0]) } + %{ if connect } connect { sidecar_service { proxy { @@ -71,6 +76,10 @@ job "${name}" { local_bind_port = ${upstream.local_bind_port} } %{ endfor } + + config { + envoy_prometheus_bind_addr = "0.0.0.0:9123" + } } } @@ -93,13 +102,16 @@ job "${name}" { timeout = "10s" } - %{ endif ~} - %{ if metrics_port_name != null ~} + %{~ endif } meta { + %{ if metrics_port_name != null } metrics_addr = "$${NOMAD_ADDR_${metrics_port_name}}" + %{ endif } + %{ if connect } + envoy_metrics_addr = "$${NOMAD_ADDR_envoy_metrics}" + %{~ endif } } - %{ endif ~} tags = [ %{ if ingress } "traefik.enable=true",