Cleanup metrics handling

This commit is contained in:
Daniel Berteaud 2024-03-27 13:15:53 +01:00
parent ac63b8a1b0
commit 1c72acbfb6
4 changed files with 25 additions and 22 deletions

View File

@ -6,18 +6,17 @@ job "traefik" {
priority = 70
constraint {
operator = "distinct_hosts"
value = "true"
}
group "traefik" {
count = 2
shutdown_delay = "6s"
constraint {
operator = "distinct_hosts"
value = "true"
}
network {
mode = "bridge"
port "http" {
@ -66,9 +65,13 @@ job "traefik" {
task = "traefik"
meta {
alloc = "${NOMAD_ALLOC_INDEX}"
job = "${NOMAD_JOB_NAME}"
namespace = "${NOMAD_NAMESPACE}"
alloc = "${NOMAD_ALLOC_INDEX}"
datacenter = "${NOMAD_DC}"
group = "${NOMAD_GROUP_NAME}"
job = "${NOMAD_JOB_NAME}"
namespace = "${NOMAD_NAMESPACE}"
node = "${node.unique.name}"
region = "${NOMAD_REGION}"
}
@ -102,6 +105,8 @@ job "traefik" {
]
}
task "traefik" {
driver = "docker"
user = 5443

View File

@ -5,7 +5,7 @@ accessLog:
bufferingSize: 100
entryPoints:
[[- if .prometheus.enabled ]]
[[- if conv.ToBool .prometheus.enabled ]]
metrics:
address: "127.0.0.1:9500"
[[- end ]]
@ -59,7 +59,8 @@ providers:
directory: /secrets/config
watch: True
[[- if .prometheus.enabled ]]
[[- if conv.ToBool .prometheus.enabled ]]
metrics:
prometheus:
entryPoint: metrics

View File

@ -8,8 +8,6 @@ job "[[ .instance ]]" {
count = [[ .traefik.count ]]
shutdown_delay = "6s"
[[ template "common/constraints" $c ]]
network {
mode = "bridge"
@ -25,7 +23,7 @@ job "[[ .instance ]]" {
}
[[- end ]]
[[- end ]]
[[- if .prometheus.enabled ]]
[[- if conv.ToBool $c.prometheus.enabled ]]
port "metrics" {}
[[- end ]]
}
@ -64,9 +62,7 @@ job "[[ .instance ]]" {
]
}
[[- if.prometheus.enabled ]]
[[- template "common/task.metrics_proxy" $c ]]
[[- end ]]
[[- template "common/task.metrics_proxy" $c ]]
task "traefik" {
driver = "[[ $c.nomad.driver ]]"
@ -77,9 +73,9 @@ job "[[ .instance ]]" {
}
config {
image = [[ .traefik.image | toJSON ]]
image = "[[ .traefik.image]]"
command = "traefik"
args = [
args = [
"--configfile=/secrets/traefik.yml"
]
}
@ -87,7 +83,7 @@ job "[[ .instance ]]" {
# Main traefik configuration
template {
data =<<_EOF
[[ template "traefik/traefik.yml.tpl" . ]]
[[ template "traefik/traefik.yml.tpl" $c ]]
_EOF
destination = "secrets/traefik.yml"
perms = "0400"

View File

@ -89,6 +89,7 @@ traefik:
# Prometheus settings
prometheus:
enabled: '[[ .prometheus.available ]]'
# The metrics_url should point on the metrics endpoint from the container's POV
# It'll be used to exposed metrics using a nginx proxy (adding mTLS)
metrics_url: http://localhost:9500/metrics