homelab/nomad-job/decom/promtail.nomad

106 lines
2.8 KiB
Plaintext
Raw Permalink Normal View History

2022-05-13 18:17:20 +00:00
job "promtail" {
2022-10-29 08:40:01 +00:00
datacenters = ["homelab", "hetzner"]
2022-12-10 16:10:32 +00:00
priority = 50
2022-10-29 08:40:01 +00:00
type = "system"
2022-05-13 18:17:20 +00:00
meta {
forcedeploy = "0"
}
2022-10-29 08:40:01 +00:00
group "promtail" {
2022-05-13 18:17:20 +00:00
network {
mode = "host"
port "http" {
static = 3200
}
}
task "promtail" {
driver = "docker"
service {
name = "promtail"
port = "http"
check {
name = "Promtail HTTP"
type = "http"
path = "/targets"
interval = "5s"
timeout = "2s"
check_restart {
limit = 2
grace = "60s"
ignore_warnings = false
}
}
}
config {
image = "grafana/promtail"
ports = ["http"]
args = [
"-config.file=/local/promtail.yml",
"-server.http-listen-port=${NOMAD_PORT_http}",
]
volumes = [
"/opt/nomad/:/nomad/"
2022-05-13 18:17:20 +00:00
]
}
env {
HOSTNAME = "${attr.unique.hostname}"
}
2022-10-29 08:40:01 +00:00
template {
2022-05-13 18:17:20 +00:00
data = <<EOTC
positions:
filename: {{ env "NOMAD_ALLOC_DIR"}}/positions.yaml
2022-05-13 18:17:20 +00:00
clients:
- url: http://loki.service.consul:3100/loki/api/v1/push
scrape_configs:
- job_name: 'nomad-logs'
consul_sd_configs:
- server: 'consul.service.consul:8500'
relabel_configs:
2022-05-14 07:33:04 +00:00
- source_labels: [__meta_consul_service_metadata_external_source]
regex: nomad
action: keep
- source_labels: [__meta_consul_service]
regex: nomad|nomad-client
action: drop
2022-05-13 18:17:20 +00:00
- source_labels: [__meta_consul_node]
target_label: __host__
- source_labels: [__meta_consul_service_metadata_external_source]
target_label: source
regex: (.*)
replacement: '$1'
- source_labels: [__meta_consul_service_id]
regex: '_nomad-task-([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})-.*'
2022-06-19 06:43:31 +00:00
target_label: 'alloc_id'
2022-05-13 18:17:20 +00:00
replacement: '$1'
- source_labels: [__meta_consul_service]
2023-10-08 12:45:27 +00:00
target_label: service
2022-05-13 18:17:20 +00:00
- source_labels: ['__meta_consul_node']
regex: '(.*)'
target_label: 'instance'
replacement: '$1'
- source_labels: [__meta_consul_service_id]
regex: '_nomad-task-([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})-.*'
target_label: '__path__'
replacement: '/nomad/alloc/$1/alloc/logs/*std*.{?,??}'
2023-10-08 12:45:27 +00:00
pipeline_stages:
- match:
selector: '{source="nomad"}'
stages:
- regex:
source: filename
expression: '\/nomad\/alloc\/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\/alloc\/logs\/(?P<task_file>[-_\w]*)\.std.*\.\d*'
- labels:
task_file:
2022-05-13 18:17:20 +00:00
EOTC
destination = "/local/promtail.yml"
}
resources {
2022-05-23 17:46:10 +00:00
memory = 100
2022-05-13 18:17:20 +00:00
}
}
}
}