2022-03-12 18:07:52 +00:00
|
|
|
job "grafana" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
group "grafana" {
|
|
|
|
count = 1
|
|
|
|
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "web" {
|
2023-08-24 19:36:47 +00:00
|
|
|
%{~ if use_wesher ~}
|
2023-03-24 23:32:37 +00:00
|
|
|
host_network = "wesher"
|
2023-08-24 19:36:47 +00:00
|
|
|
%{~ endif ~}
|
2022-03-12 18:07:52 +00:00
|
|
|
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"
|
2023-03-24 18:24:36 +00:00
|
|
|
provider = "nomad"
|
2022-03-12 18:07:52 +00:00
|
|
|
port = "web"
|
|
|
|
|
|
|
|
tags = [
|
|
|
|
"traefik.enable=true",
|
2022-11-10 21:34:55 +00:00
|
|
|
"traefik.http.routers.grafana.entryPoints=websecure",
|
2023-07-07 07:40:19 +00:00
|
|
|
# "traefik.http.routers.grafana.middlewares=authelia@nomad",
|
2022-03-12 18:07:52 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-05-09 20:20:36 +00:00
|
|
|
task "stunnel" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = true
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "alpine:3.17"
|
|
|
|
args = ["/bin/sh", "$${NOMAD_TASK_DIR}/start.sh"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 100
|
|
|
|
memory = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
set -e
|
|
|
|
apk add stunnel
|
|
|
|
exec stunnel {{ env "NOMAD_TASK_DIR" }}/stunnel.conf
|
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_TASK_DIR}/start.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
syslog = no
|
|
|
|
foreground = yes
|
|
|
|
delay = yes
|
|
|
|
|
|
|
|
[mysql_client]
|
|
|
|
client = yes
|
|
|
|
accept = 127.0.0.1:3306
|
|
|
|
{{ range nomadService 1 (env "NOMAD_ALLOC_ID") "mysql-tls" -}}
|
|
|
|
connect = {{ .Address }}:{{ .Port }}
|
|
|
|
{{- end }}
|
|
|
|
PSKsecrets = {{ env "NOMAD_SECRETS_DIR" }}/mysql_stunnel_psk.txt
|
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_TASK_DIR}/stunnel.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: Get psk for backup jobs despite multiple job declarations
|
|
|
|
# Probably should use variable ACLs to grant each node job to this path
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
{{- with nomadVar "nomad/jobs/grafana/grafana/stunnel" }}{{ .mysql_stunnel_psk }}{{ end -}}
|
|
|
|
EOF
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/mysql_stunnel_psk.txt"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 = [
|
2023-05-09 20:20:36 +00:00
|
|
|
"/usr/bin/timeout",
|
|
|
|
"2m",
|
2022-07-29 20:02:22 +00:00
|
|
|
"/bin/bash",
|
|
|
|
"-c",
|
2023-05-09 20:20:36 +00:00
|
|
|
"until /usr/bin/mysql --defaults-extra-file=$${NOMAD_SECRETS_DIR}/my.cnf < $${NOMAD_SECRETS_DIR}/bootstrap.sql; do sleep 10; done",
|
2022-07-29 20:02:22 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
[client]
|
2023-05-09 20:20:36 +00:00
|
|
|
host=127.0.0.1
|
|
|
|
port=3306
|
2022-07-29 20:02:22 +00:00
|
|
|
user=root
|
2023-03-24 18:24:36 +00:00
|
|
|
{{ with nomadVar "nomad/jobs" -}}
|
|
|
|
password={{ .mysql_root_password }}
|
|
|
|
{{ end -}}
|
2022-07-29 20:02:22 +00:00
|
|
|
EOF
|
2022-11-10 21:35:48 +00:00
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/my.cnf"
|
2022-07-29 20:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-03-24 18:24:36 +00:00
|
|
|
{{ with nomadVar "nomad/jobs/grafana" -}}
|
|
|
|
{{ if .db_name -}}
|
|
|
|
CREATE DATABASE IF NOT EXISTS `{{ .db_name }}`;
|
|
|
|
CREATE USER IF NOT EXISTS '{{ .db_user }}'@'%' IDENTIFIED BY '{{ .db_pass }}';
|
|
|
|
GRANT ALL ON `{{ .db_name }}`.* to '{{ .db_user }}'@'%';
|
|
|
|
-- Create Read Only user
|
|
|
|
CREATE USER IF NOT EXISTS '{{ .db_user_ro }}'@'%' IDENTIFIED BY '{{ .db_pass_ro }}';
|
2022-07-29 20:02:22 +00:00
|
|
|
{{ else -}}
|
|
|
|
SELECT 'NOOP';
|
|
|
|
{{ end -}}
|
|
|
|
{{ end -}}
|
|
|
|
EOF
|
2022-11-10 21:35:48 +00:00
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/bootstrap.sql"
|
2022-07-29 20:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 50
|
|
|
|
memory = 50
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-12 18:07:52 +00:00
|
|
|
task "grafana" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
2023-03-12 17:22:47 +00:00
|
|
|
image = "grafana/grafana:9.4.2"
|
2023-08-24 18:59:10 +00:00
|
|
|
args = ["--config", "$${NOMAD_ALLOC_DIR}/config/grafana.ini"]
|
2022-03-12 18:07:52 +00:00
|
|
|
ports = ["web"]
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
2022-11-12 00:21:17 +00:00
|
|
|
"GF_INSTALL_PLUGINS" = "grafana-clock-panel,grafana-piechart-panel,grafana-polystat-panel,natel-discrete-panel",
|
2023-05-03 04:13:59 +00:00
|
|
|
"GF_PATHS_PROVISIONING" = "$${NOMAD_ALLOC_DIR}/config/provisioning"
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
|
|
|
|
2022-07-25 22:49:29 +00:00
|
|
|
template {
|
|
|
|
data = <<EOF
|
2023-03-24 18:24:36 +00:00
|
|
|
{{ with nomadVar "nomad/jobs/grafana" -}}
|
|
|
|
GF_SECURITY_ADMIN_PASSWORD={{ .admin_pw }}
|
|
|
|
GF_SMTP_USER={{ .smtp_user }}
|
|
|
|
GF_SMTP_PASSWORD={{ .smtp_password }}
|
|
|
|
GF_EXTERNAL_IMAGE_STORAGE_S3_ACCESS_KEY={{ .minio_access_key }}
|
|
|
|
GF_EXTERNAL_IMAGE_STORAGE_S3_SECRET_KEY={{ .minio_secret_key }}
|
2023-03-24 23:32:37 +00:00
|
|
|
GRAFANA_ALERT_EMAIL_ADDRESSES={{ .alert_email_addresses }}
|
2023-07-07 07:40:19 +00:00
|
|
|
GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET={{ .oidc_secret }}
|
2023-03-24 23:32:37 +00:00
|
|
|
{{ if .db_name -}}
|
2022-07-29 20:02:22 +00:00
|
|
|
# Database storage
|
|
|
|
GF_DATABASE_TYPE=mysql
|
2023-05-09 20:20:36 +00:00
|
|
|
GF_DATABASE_HOST=127.0.0.1:3306
|
2023-03-24 18:24:36 +00:00
|
|
|
GF_DATABASE_NAME={{ .db_name }}
|
|
|
|
GF_DATABASE_USER={{ .db_user }}
|
|
|
|
GF_DATABASE_PASSWORD={{ .db_pass }}
|
|
|
|
{{- end }}
|
|
|
|
SLACK_BOT_URL={{ .slack_bot_url }}
|
|
|
|
SLACK_BOT_TOKEN={{ .slack_bot_token }}
|
|
|
|
SLACK_HOOK_URL={{ .slack_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"
|
|
|
|
}
|
|
|
|
|
2023-05-03 04:13:59 +00:00
|
|
|
resources {
|
|
|
|
cpu = 100
|
|
|
|
memory = 200
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "grafana-reprovisioner" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
lifecycle {
|
|
|
|
hook = "prestart"
|
|
|
|
sidecar = true
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
2023-08-24 18:39:00 +00:00
|
|
|
image = "alpine:3.17"
|
2023-05-03 04:13:59 +00:00
|
|
|
args = ["$${NOMAD_TASK_DIR}/startup.sh"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resources {
|
|
|
|
cpu = 100
|
|
|
|
memory = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
|
|
|
LOG_FILE = "/var/log/grafana_reloader.log"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
#! /bin/sh
|
|
|
|
apk add curl
|
|
|
|
touch "$LOG_FILE"
|
|
|
|
exec tail -f "$LOG_FILE"
|
|
|
|
EOF
|
|
|
|
perms = "777"
|
|
|
|
destination = "$${NOMAD_TASK_DIR}/startup.sh"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
{{ with nomadVar "nomad/jobs/grafana" -}}
|
|
|
|
GF_SECURITY_ADMIN_PASSWORD={{ .admin_pw }}
|
|
|
|
{{ end -}}
|
|
|
|
EOF
|
|
|
|
env = true
|
|
|
|
destination = "$${NOMAD_SECRETS_DIR}/conf.env"
|
|
|
|
}
|
|
|
|
|
|
|
|
template {
|
|
|
|
data = <<EOF
|
|
|
|
#! /bin/sh
|
|
|
|
exec > "$LOG_FILE"
|
|
|
|
exec 2>&1
|
|
|
|
GRAFANA_URL=http://127.0.0.1:3000
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload dashboards"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/dashboards/reload
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload datasources"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/datasources/reload
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload plugins"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/plugins/reload
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload notifications"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/notifications/reload
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload access-control"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/access-control/reload
|
2023-06-20 16:44:04 +00:00
|
|
|
echo "Reload alerting"
|
2023-05-03 04:13:59 +00:00
|
|
|
curl -s -S --user admin:$GF_SECURITY_ADMIN_PASSWORD --request POST $GRAFANA_URL/api/admin/provisioning/alerting/reload
|
|
|
|
EOF
|
|
|
|
change_mode = "noop"
|
|
|
|
perms = "777"
|
|
|
|
destination = "$${NOMAD_TASK_DIR}/reload_config.sh"
|
|
|
|
}
|
|
|
|
|
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
|
2023-05-03 04:13:59 +00:00
|
|
|
destination = "$${NOMAD_ALLOC_DIR}/config/${config_file}"
|
2022-11-15 16:59:06 +00:00
|
|
|
perms = 777
|
|
|
|
# Set owner to grafana uid
|
|
|
|
# uid = 472
|
2022-07-21 22:54:05 +00:00
|
|
|
# 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 = ">>>>"
|
2022-11-12 00:21:17 +00:00
|
|
|
%{ endif }
|
2023-05-03 04:13:59 +00:00
|
|
|
change_mode = "script"
|
|
|
|
change_script {
|
2023-06-20 16:44:04 +00:00
|
|
|
command = "/local/reload_config.sh"
|
2023-05-03 04:13:59 +00:00
|
|
|
}
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
2022-11-12 00:21:17 +00:00
|
|
|
%{ endfor }
|
2022-03-12 18:07:52 +00:00
|
|
|
|
|
|
|
}
|
2022-11-15 16:59:06 +00:00
|
|
|
|
|
|
|
task "grafana-image-renderer" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "grafana/grafana-image-renderer:3.6.1"
|
|
|
|
ports = ["renderer"]
|
|
|
|
}
|
|
|
|
|
|
|
|
env = {
|
|
|
|
"RENDERING_MODE" = "clustered"
|
|
|
|
"RENDERING_CLUSTERING_MODE" = "browser"
|
|
|
|
"RENDERING_CLUSTERING_MAX_CONCURRENCY" = 5
|
|
|
|
"RENDERING_CLUSTERING_TIMEOUT" = 30
|
|
|
|
}
|
|
|
|
}
|
2022-03-12 18:07:52 +00:00
|
|
|
}
|
|
|
|
}
|