diff --git a/nomad/core.tf b/nomad/core.tf index eb0022e..4db9369 100644 --- a/nomad/core.tf +++ b/nomad/core.tf @@ -21,3 +21,30 @@ module "metrics" { consul_address = var.consul_address } + +module "loki" { + source = "./levant" + + template_path = "service.nomad" + variables = { + name = "loki" + image = "grafana/loki:2.2.1" + service_port = 3100 + ingress = true + sticky_disk = true + templates = jsonencode([ + { + data = file("./loki-config.yml") + dest = "/etc/loki/local-config.yaml" + } + ]) + } +} + +resource "nomad_job" "syslog-ng" { + hcl2 { + enabled = true + } + + jobspec = file("${path.module}/syslogng.nomad") +} diff --git a/nomad/loki-config.yml b/nomad/loki-config.yml new file mode 100644 index 0000000..b762f7e --- /dev/null +++ b/nomad/loki-config.yml @@ -0,0 +1,45 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + +ingester: + lifecycler: + address: 127.0.0.1 + ring: + kvstore: + store: inmemory + replication_factor: 1 + final_sleep: 0s + chunk_idle_period: 5m + chunk_retain_period: 30s + max_transfer_retries: 0 + +schema_config: + configs: + - from: 2018-04-15 + store: boltdb + object_store: filesystem + schema: v11 + index: + prefix: index_ + period: 168h + +storage_config: + boltdb: + directory: /loki/index + + filesystem: + directory: /loki/chunks + +limits_config: + enforce_metric_name: false + reject_old_samples: true + reject_old_samples_max_age: 168h + +chunk_store_config: + max_look_back_period: 0s + +table_manager: + retention_deletes_enabled: false + retention_period: 0s diff --git a/nomad/metrics/exporters.nomad b/nomad/metrics/exporters.nomad index d7224b0..936ae2b 100644 --- a/nomad/metrics/exporters.nomad +++ b/nomad/metrics/exporters.nomad @@ -204,5 +204,140 @@ job "metrics" { memory = 50 } } + + service { + name = "promtail" + port = "promtail" + + meta { + metrics_addr = "${NOMAD_ADDR_promtail}" + nomad_dc = "${NOMAD_DC}" + nomad_node_name = "${node.unique.name}" + } + + connect { + sidecar_service { + proxy { + local_service_port = 9080 + } + } + + sidecar_task { + resources { + cpu = 50 + memory = 50 + } + } + } + + check { + type = "http" + path = "/metrics" + port = "promtail" + interval = "10s" + timeout = "10s" + } + } + + task "promtail" { + driver = "docker" + + config { + image = "grafana/promtail:2.2.1" + args = ["-config.file=/etc/promtail/promtail.yml"] + ports = ["promtail"] + + # Mount config + mount { + type = "bind" + target = "/etc/promtail/promtail.yml" + source = "local/promtail.yml" + } + + # Bind mount host machine-id and log directories + mount { + type = "bind" + source = "/etc/machine-id" + target = "/etc/machine-id" + readonly = true + } + + mount { + type = "bind" + source = "/etc/machine-id" + target = "/etc/machine-id" + readonly = true + } + + mount { + type = "bind" + source = "/var/log/journal/" + target = "/var/log/journal/" + readonly = true + } + + mount { + type = "bind" + source = "/run/log/journal/" + target = "/run/log/journal/" + readonly = true + } + + mount { + type = "bind" + source = "/var/log/audit" + target = "/var/log/audit" + readonly = true + } + } + + template { + data = <