Skip to content

Instantly share code, notes, and snippets.

@mister2d
Last active February 12, 2021 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mister2d/d2fcb12d0abf8f88cc0ed9be61ea84cf to your computer and use it in GitHub Desktop.
Save mister2d/d2fcb12d0abf8f88cc0ed9be61ea84cf to your computer and use it in GitHub Desktop.
locals {
config = jsondecode(file("runnervars.json"))
}
job "logging" {
datacenters = ["dc1"]
type = "service"
constraint {
attribute = "${attr.cpu.arch}"
value = "amd64"
}
group "loki" {
count = 1
network {
mode = "bridge"
port "syslog" {
static = 1514
to = 1514
}
port "loki_grpc" { static = 3101 }
port "loki_http" { static = 3100 }
port "promtail_grpc" { static = 9081 }
port "promtail_http" { static = 9080 }
port "promtail_syslog" { static = 2514 }
}
service {
name = "loki"
port = "loki_http"
task = "loki"
address_mode = "alloc"
check {
name = "healthcheck"
type = "http"
path = "/ready"
interval = "10s"
timeout = "2s"
address_mode = "alloc"
}
connect {
sidecar_service {}
}
}
service {
name = "loki-promtail-syslog"
port = "promtail_syslog"
task = "loki-promtail"
address_mode = "alloc"
check {
name = "healthcheck"
type = "http"
port = "promtail_http"
path = "/ready"
interval = "10s"
timeout = "2s"
address_mode = "alloc"
}
}
service {
name = "syslog"
port = "syslog"
task = "syslog"
address_mode = "host"
check {
name = "healthcheck"
type = "tcp"
port = "syslog"
interval = "10s"
timeout = "2s"
}
}
task "loki" {
driver = "docker"
resources {
cpu = 500
memory = 256
}
config {
image = "grafana/loki:${local.config.LOKI_VERSION}"
args = [
"-config.file=/local/config/local-config.yaml",
"-server.http-listen-address=0.0.0.0",
"-server.http-listen-port=${NOMAD_PORT_loki_http}",
"-server.grpc-listen-address=0.0.0.0",
"-server.grpc-listen-port=${NOMAD_PORT_loki_grpc}"
]
mounts = [
{
type = "volume"
target = "/srv/loki"
source = "loki_data"
readonly = false
volume_options = {
driver_config = {
name = "local"
options = [
{
device=":/srv/pool/data/loki/data"
o="addr=nfs.local,rw,vers=4.2,rsize=1048576,wsize=1048576,hard,noatime,lookupcache=positive,timeo=600,retrans=2"
type="nfs"
}
]
}
}
}
]
}
template {
data = <<EOH
---
auth_enabled: false
ingester:
lifecycler:
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s
schema_config:
configs:
- from: 2020-10-24
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
storage_config:
boltdb:
directory: /srv/loki/index
filesystem:
directory: /srv/loki/chunks
limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h
EOH
change_mode = "signal"
change_signal = "SIGHUP"
destination = "local/config/local-config.yaml"
}
}
task "loki-promtail" {
driver = "docker"
resources {
cpu = 200
memory = 256
}
config {
image = "grafana/promtail:${local.config.PROMTAIL_VERSION}"
args = [
"-config.file=/local/config/config.yml",
"-server.http-listen-address=0.0.0.0",
"-server.http-listen-port=${NOMAD_PORT_promtail_http}",
"-server.grpc-listen-address=0.0.0.0",
"-server.grpc-listen-port=${NOMAD_PORT_promtail_grpc}"
]
}
lifecycle {
sidecar = true
hook = "poststart"
}
template {
data = <<EOH
positions:
filename: /tmp/positions.yaml
clients:
- url: http://localhost:{{ env "NOMAD_PORT_loki_http" }}/loki/api/v1/push
scrape_configs:
- job_name: syslog
syslog:
listen_address: 0.0.0.0:{{ env "NOMAD_PORT_promtail_syslog" }}
idle_timeout: 60s
label_structured_data: yes
labels:
job: "syslog"
relabel_configs:
- source_labels: ['__syslog_message_hostname']
target_label: 'host'
EOH
change_mode = "signal"
change_signal = "SIGHUP"
destination = "local/config/config.yml"
}
}
task "syslog" {
driver = "docker"
resources {
cpu = 100
memory = 256
}
config {
image = "registry.ingress.service.consul/local/syslog-ng:${local.config.SYSLOGNG_VERSION}"
auth {
username = "${local.config.REGISTRY_USER}"
password = "${local.config.REGISTRY_PASSWORD}"
}
}
lifecycle {
sidecar = true
hook = "poststart"
}
template {
data = <<EOH
destination d_loki_promtail {
syslog("localhost" transport("tcp") port({{ env "NOMAD_PORT_promtail_syslog" }}));
};
log {
source(s_docker);
destination(d_loki_promtail);
};
EOH
change_mode = "signal"
change_signal = "SIGHUP"
destination = "local/conf.d/loki.conf"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment