fruitbasket/modules/monitoring/default.nix

91 lines
2.3 KiB
Nix
Raw Normal View History

2024-05-06 11:21:12 +02:00
{ config, ... }:
2024-04-29 15:09:56 +02:00
let
domain = "monitoring.${config.networking.domain}";
in
{
2024-05-08 00:09:40 +02:00
sops.secrets."grafana/oidc_secret" = {
owner = "grafana";
};
2024-04-29 15:09:56 +02:00
# grafana configuration
services.grafana = {
enable = true;
settings = {
server = {
inherit domain;
http_addr = "127.0.0.1";
http_port = 2342;
2024-05-02 19:33:50 +02:00
root_url = "https://monitoring.ifsr.de";
2024-04-29 15:09:56 +02:00
};
database = {
type = "postgres";
user = "grafana";
host = "/run/postgresql";
};
2024-05-08 00:09:40 +02:00
"auth.generic_oauth" = {
enabled = true;
name = "iFSR";
allow_sign_up = true;
client_id = "grafana";
client_secret = "$__file{${config.sops.secrets."grafana/oidc_secret".path}}";
scopes = "openid email profile offline_access roles";
email_attribute_path = "email";
login_attribute_path = "username";
name_attribute_path = "full_name";
auth_url = "https://sso.ifsr.de/realms/internal/protocol/openid-connect/auth";
token_url = "https://sso.ifsr.de/realms/internal/protocol/openid-connect/token";
api_url = "https://sso.ifsr.de/realms/internal/protocol/openid-connect/userinfo";
role_attribute_path = "contains(roles[*], 'admin') && 'Admin' || contains(roles[*], 'editor') && 'Editor' || 'Viewer'";
};
2024-04-29 14:21:58 +02:00
};
2024-04-29 15:09:56 +02:00
};
services.postgresql = {
enable = true;
ensureUsers = [
{
name = "grafana";
2024-04-29 17:10:35 +02:00
ensureDBOwnership = true;
2024-04-29 15:09:56 +02:00
}
];
ensureDatabases = [ "grafana" ];
};
services.prometheus = {
enable = true;
port = 9001;
2024-04-29 15:12:52 +02:00
exporters = {
node = {
enable = true;
enabledCollectors = [ "systemd" ];
port = 9002;
};
};
scrapeConfigs = [
{
job_name = "node";
static_configs = [{
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.node.port}" ];
}];
2024-04-29 17:09:37 +02:00
scrape_interval = "15s";
2024-04-29 15:12:52 +02:00
}
2024-06-16 18:29:36 +02:00
{
job_name = "rspamd";
static_configs = [{
targets = [ "rspamd.ifsr.de:11334" ];
}];
scrape_interval = "15s";
}
2024-04-29 15:12:52 +02:00
];
2024-04-29 15:09:56 +02:00
};
# nginx reverse proxy
services.nginx.virtualHosts.${domain} = {
locations."/" = {
2024-05-02 10:48:26 +02:00
proxyPass = "http://localhost:${toString config.services.grafana.settings.server.http_port}";
2024-04-29 15:09:56 +02:00
proxyWebsockets = true;
2024-04-29 14:21:58 +02:00
};
2024-04-29 15:09:56 +02:00
};
2024-04-29 14:21:58 +02:00
}