2024-07-01 00:00:46 +03:00
|
|
|
{ cluster, config, depot, lib, ... }:
|
2023-06-03 01:33:51 +03:00
|
|
|
let
|
2023-08-31 01:55:45 +03:00
|
|
|
inherit (depot.lib.meta) domain;
|
2023-06-03 01:33:51 +03:00
|
|
|
|
2024-08-03 01:56:13 +03:00
|
|
|
inherit (cluster.config.links) prometheus-ingest;
|
2023-06-03 01:33:51 +03:00
|
|
|
|
|
|
|
inherit (cluster.config) hostLinks;
|
|
|
|
|
|
|
|
inherit (config.networking) hostName;
|
|
|
|
|
|
|
|
iniList = lib.concatStringsSep " ";
|
|
|
|
|
|
|
|
login = x: "https://login.${domain}/auth/realms/master/protocol/openid-connect/${x}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
age.secrets = {
|
|
|
|
grafana-db-credentials = {
|
|
|
|
file = ./secrets/grafana-db-credentials.age;
|
|
|
|
owner = "grafana";
|
|
|
|
};
|
|
|
|
grafana-secrets.file = ./secrets/grafana-secrets.age;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
root_url = "https://monitoring.${domain}/";
|
|
|
|
http_addr = hostLinks.${hostName}.grafana.ipv4;
|
|
|
|
http_port = hostLinks.${hostName}.grafana.port;
|
|
|
|
};
|
|
|
|
database = {
|
|
|
|
type = "postgres";
|
|
|
|
host = cluster.config.links.patroni-pg-access.tuple;
|
|
|
|
user = "grafana";
|
|
|
|
password = "$__file{${config.age.secrets.grafana-db-credentials.path}}";
|
|
|
|
};
|
|
|
|
analytics.reporting_enabled = false;
|
|
|
|
"auth.generic_oauth" = {
|
|
|
|
enabled = true;
|
|
|
|
allow_sign_up = true;
|
|
|
|
client_id = "net.privatevoid.monitoring1";
|
|
|
|
auth_url = login "auth";
|
|
|
|
token_url = login "token";
|
|
|
|
api_url = login "userinfo";
|
|
|
|
scopes = iniList [ "openid" "profile" "email" "roles" ];
|
|
|
|
role_attribute_strict = true;
|
|
|
|
role_attribute_path = "resource_access.monitoring.roles[0]";
|
|
|
|
};
|
|
|
|
security = {
|
|
|
|
cookie_secure = true;
|
|
|
|
disable_gravatar = true;
|
|
|
|
};
|
|
|
|
feature_toggles.enable = iniList [
|
|
|
|
"tempoSearch"
|
|
|
|
"tempoBackendSearch"
|
|
|
|
"tempoServiceGraph"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
datasources.settings.datasources = [
|
|
|
|
{
|
|
|
|
name = "Prometheus";
|
|
|
|
uid = "PBFA97CFB590B2093";
|
|
|
|
inherit (prometheus-ingest) url;
|
|
|
|
type = "prometheus";
|
|
|
|
isDefault = true;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "Loki";
|
|
|
|
uid = "P8E80F9AEF21F6940";
|
2024-08-03 01:12:15 +03:00
|
|
|
inherit (cluster.config.ways.monitoring-logs) url;
|
2023-06-03 01:33:51 +03:00
|
|
|
type = "loki";
|
|
|
|
}
|
2024-08-23 03:50:18 +03:00
|
|
|
{
|
|
|
|
name = "Tempo";
|
|
|
|
uid = "P214B5B846CF3925F";
|
|
|
|
inherit (cluster.config.ways.monitoring-traces) url;
|
|
|
|
type = "tempo";
|
|
|
|
jsonData = {
|
|
|
|
serviceMap.datasourceUid = "PBFA97CFB590B2093";
|
|
|
|
nodeGraph.enabled = true;
|
|
|
|
};
|
|
|
|
}
|
2023-06-03 01:33:51 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
grafana = {
|
2023-08-27 17:26:17 +03:00
|
|
|
distributed = {
|
|
|
|
enable = true;
|
|
|
|
registerService = "grafana";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
EnvironmentFile = config.age.secrets.grafana-secrets.path;
|
2024-05-17 17:23:19 +03:00
|
|
|
Restart = lib.mkForce "always";
|
2023-08-21 20:03:56 +03:00
|
|
|
RestartSec = "10s";
|
2023-06-03 01:33:51 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
consul.services.grafana = {
|
|
|
|
mode = "manual";
|
2024-07-04 18:31:59 +03:00
|
|
|
definition = {
|
2023-06-03 01:33:51 +03:00
|
|
|
name = "grafana";
|
2024-07-04 18:31:59 +03:00
|
|
|
address = hostLinks.${hostName}.grafana.ipv4;
|
|
|
|
port = hostLinks.${hostName}.grafana.port;
|
2023-06-03 01:33:51 +03:00
|
|
|
checks = [
|
|
|
|
{
|
2024-07-04 18:31:59 +03:00
|
|
|
name = "Grafana";
|
2023-06-03 01:33:51 +03:00
|
|
|
id = "service:grafana:backend";
|
|
|
|
interval = "5s";
|
|
|
|
http = "${hostLinks.${hostName}.grafana.url}/healthz";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|