2022-03-12 18:07:52 +00:00
|
|
|
job "grafana" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
group "grafana" {
|
|
|
|
count = 1
|
|
|
|
|
2022-07-21 22:54:05 +00:00
|
|
|
# TODO: Add backup task or job
|
|
|
|
|
2022-03-12 18:07:52 +00:00
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "web" {
|
|
|
|
host_network = "loopback"
|
|
|
|
to = 3000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-13 17:13:19 +00:00
|
|
|
ephemeral_disk {
|
|
|
|
migrate = true
|
|
|
|
sticky = true
|
|
|
|
}
|
|
|
|
|
2022-03-12 18:07:52 +00:00
|
|
|
service {
|
2022-03-13 17:13:19 +00:00
|
|
|
name = "grafana"
|
2022-03-12 18:07:52 +00:00
|
|
|
port = "web"
|
|
|
|
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
local_service_port = 3000
|
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "prometheus"
|
|
|
|
local_bind_port = 9090
|
|
|
|
}
|
2022-07-25 22:49:29 +00:00
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "loki"
|
|
|
|
local_bind_port = 3100
|
|
|
|
}
|
2022-07-29 20:02:22 +00:00
|
|
|
|
|
|
|
upstreams {
|
|
|
|
destination_name = "mysql-server"
|
|
|
|
local_bind_port = 6060
|
|
|
|
}
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sidecar_task {
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
check {
|
|
|
|
type = "http"
|
|
|
|
path = "/"
|
|
|
|
port = "web"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "10s"
|
|
|
|
}
|
|
|
|
|
|
|
|
tags = [
|
|
|
|
"traefik.enable=true",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-07-29 20:02:22 +00:00
|
|
|
task "grafana-bootstrap" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = false
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
2022-11-10 19:15:58 +00:00
|
|
|
image = "mariadb:10"
|
2022-07-29 20:02:22 +00:00
|
|
|
args = [
|
|
|
|
"/bin/bash",
|
|
|
|
"-c",
|
|
|
|
"/usr/bin/mysql --defaults-extra-file=/task/my.cnf < /task/bootstrap.sql",
|
|
|
|
]
|
|
|
|
|
|
|
|
mount {
|
|
|
|
type = "bind"
|
|
|
|
source = "local/"
|
|
|
|
target = "/task/"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
[client]
|
|
|
|
host={{ env "NOMAD_UPSTREAM_IP_mysql_server" }}
|
|
|
|
port={{ env "NOMAD_UPSTREAM_PORT_mysql_server" }}
|
|
|
|
user=root
|
|
|
|
{{ with secret "kv/data/mysql" }}
|
|
|
|
password={{ .Data.data.root_password }}
|
|
|
|
{{ end }}
|
|
|
|
EOF
|
|
|
|
destination = "local/my.cnf"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
{{ with secret "kv/data/grafana" -}}
|
|
|
|
{{ if .Data.data.db_name -}}
|
|
|
|
CREATE DATABASE IF NOT EXISTS `{{ .Data.data.db_name }}`;
|
|
|
|
CREATE USER IF NOT EXISTS '{{ .Data.data.db_user }}'@'%' IDENTIFIED BY '{{ .Data.data.db_pass }}';
|
|
|
|
GRANT ALL ON `{{ .Data.data.db_name }}`.* to '{{ .Data.data.db_user }}'@'%';
|
|
|
|
{{ else -}}
|
|
|
|
SELECT 'NOOP';
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
EOF
|
|
|
|
destination = "local/bootstrap.sql"
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-12 18:07:52 +00:00
|
|
|
task "grafana" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "grafana/grafana:7.3.6"
|
|
|
|
ports = ["web"]
|
|
|
|
|
|
|
|
mount {
|
|
|
|
type = "bind"
|
2022-07-21 22:54:05 +00:00
|
|
|
target = "/etc/grafana"
|
|
|
|
source = "local/config"
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
|
|
|
"GF_INSTALL_PLUGINS" = "grafana-clock-panel,grafana-piechart-panel,grafana-polystat-panel",
|
|
|
|
}
|
|
|
|
|
2022-07-25 22:49:29 +00:00
|
|
|
vault {
|
|
|
|
policies = [
|
|
|
|
"access-tables",
|
|
|
|
"nomad-task",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2022-07-29 20:02:22 +00:00
|
|
|
{{ with secret "kv/data/grafana" -}}
|
2022-07-25 22:49:29 +00:00
|
|
|
GF_SECURITY_ADMIN_PASSWORD={{ .Data.data.admin_pw }}
|
|
|
|
GF_SMTP_USER={{ .Data.data.smtp_user }}
|
|
|
|
GF_SMTP_PASSWORD={{ .Data.data.smtp_password }}
|
|
|
|
GF_EXTERNAL_IMAGE_STORAGE_S3_ACCESS_KEY={{ .Data.data.minio_access_key }}
|
|
|
|
GF_EXTERNAL_IMAGE_STORAGE_S3_SECRET_KEY={{ .Data.data.minio_secret_key }}
|
|
|
|
GRAFANA_ALERT_EMAIL_ADDRESSES={{ .Data.data.alert_email_addresses }}
|
2022-07-29 20:02:22 +00:00
|
|
|
{{ if .Data.data.db_name -}}
|
|
|
|
# Database storage
|
|
|
|
GF_DATABASE_TYPE=mysql
|
|
|
|
GF_DATABASE_HOST={{ env "NOMAD_UPSTREAM_ADDR_mysql_server" }}
|
|
|
|
GF_DATABASE_NAME={{ .Data.data.db_name }}
|
|
|
|
GF_DATABASE_USER={{ .Data.data.db_user }}
|
|
|
|
GF_DATABASE_PASSWORD={{ .Data.data.db_pass }}
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
{{ with secret "kv/data/slack" -}}
|
2022-07-25 22:49:29 +00:00
|
|
|
SLACK_BOT_URL={{ .Data.data.bot_url }}
|
|
|
|
SLACK_BOT_TOKEN={{ .Data.data.bot_token }}
|
|
|
|
SLACK_HOOK_URL={{ .Data.data.hook_url }}
|
2022-07-29 20:02:22 +00:00
|
|
|
{{ end -}}
|
2022-07-25 22:49:29 +00:00
|
|
|
EOF
|
|
|
|
env = true
|
|
|
|
destination = "secrets/conf.env"
|
|
|
|
}
|
|
|
|
|
2022-07-21 22:54:05 +00:00
|
|
|
%{ for config_file in fileset(join("/", [module_path, "grafana"]), "**") ~}
|
2022-03-12 18:07:52 +00:00
|
|
|
template {
|
|
|
|
data = <<EOF
|
2022-07-21 22:54:05 +00:00
|
|
|
${file(join("/", [module_path, "grafana", config_file]))}
|
2022-03-12 18:07:52 +00:00
|
|
|
EOF
|
|
|
|
change_mode = "signal"
|
|
|
|
change_signal = "SIGHUP"
|
2022-07-21 22:54:05 +00:00
|
|
|
destination = "local/config/${config_file}"
|
|
|
|
# Change template delimeter for dashboard files that use json and have double curly braces and square braces
|
2022-07-25 22:49:29 +00:00
|
|
|
%{ if length(regexall("dashboard", config_file)) > 0 ~}
|
2022-07-21 22:54:05 +00:00
|
|
|
left_delimiter = "<<<<"
|
|
|
|
right_delimiter = ">>>>"
|
|
|
|
%{ endif ~}
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
2022-07-21 22:54:05 +00:00
|
|
|
%{ endfor ~}
|
2022-03-12 18:07:52 +00:00
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 100
|
|
|
|
memory = 200
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|