Skip to content

Instantly share code, notes, and snippets.

@asrivascrealytee
Created March 11, 2019 16:17
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asrivascrealytee/00856a03518e665754ed87b8224cc8ea to your computer and use it in GitHub Desktop.
Save asrivascrealytee/00856a03518e665754ed87b8224cc8ea to your computer and use it in GitHub Desktop.
Grafana+loki+promtail nomad example
job "grafana" {
datacenters = ["dc1"]
type = "service"
group "grafana" {
count = 1
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
task "grafana" {
driver = "docker"
config {
image = "grafana/grafana"
port_map {
grafana_port = 3000
}
}
resources {
cpu = 50
memory = 32
network {
mbits = 1
port "grafana_port"{}
}
}
service {
name = "graphana"
port = "grafana_port"
check {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
}
}
}
}
}
@asrivascrealytee
Copy link
Author

job "loki" {
  datacenters = ["dc1"]
  type        = "service"

  group "loki" {
    count = 1

    restart {
      attempts = 10
      interval = "5m"
      delay    = "25s"
      mode     = "delay"
    }

    task "loki" {
      driver = "docker"

      config {
        image = "grafana/loki:master"

        args = [
          "-config.file",
          "/etc/loki/local-config.yaml",
        ]

        port_map {
          loki_port = 3100
        }
      }

      resources {
        cpu    = 50
        memory = 32

        network {
          mbits = 1
          port  "loki_port"{}
        }
      }

      service {
        name = "loki"
        port = "loki_port"

        check {
          type     = "http"
          path     = "/health"
          interval = "10s"
          timeout  = "2s"
        }
      }
    }
  }
}

@asrivascrealytee
Copy link
Author

job "promtail" {
  datacenters = ["dc1"]
  type        = "service"

  group "promtail" {
    count = 1

    restart {
      attempts = 10
      interval = "5m"
      delay    = "25s"
      mode     = "delay"
    }

    task "promtail" {
      driver = "docker"

      config {
        image = "grafana/promtail:master"

        args = [
          "-config.file",
          "local/config.yaml",
        ]

        port_map {
          promtail_port = 3000
        }
      }

      template {
        data = <<EOH
server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

client:
  url: http://10.70.103.139:22503/api/prom/push

scrape_configs:
- job_name: system
  entry_parser: raw
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /alloc/logs/*
EOH

        destination = "local/config.yaml"
      }

      resources {
        cpu    = 50
        memory = 32

        network {
          mbits = 1
          port  "promtail_port"{}
        }
      }

      service {
        name = "promtail"
        port = "promtail_port"

        check {
          type     = "http"
          path     = "/health"
          interval = "10s"
          timeout  = "2s"
        }
      }
    }
  }
}

@ufukhalis
Copy link

Hey, I was trying to install Grafana-Loki. So, I have a question regarding promtail job. path: /alloc/logs/* this one only gives about logs promtail job. In my nomad, I have other jobs and I would like to push their logs, in that case, which path should I use? Or is there any better way to push other job logs?

@cyriltovena
Copy link

@ufukhalis
Copy link

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment