fruitbasket/modules/monitoring.nix

77 lines
1.5 KiB
Nix
Raw Normal View History

2024-04-29 14:21:58 +02:00
{ config, pkgs, ... }:
2024-04-29 15:09:56 +02:00
let
domain = "monitoring.${config.networking.domain}";
in
{
# grafana configuration
services.grafana = {
enable = true;
settings = {
server = {
inherit domain;
http_addr = "127.0.0.1";
http_port = 2342;
};
database = {
type = "postgres";
user = "grafana";
host = "/run/postgresql";
};
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;
};
2024-04-30 14:22:50 +02:00
postfix = {
enable = true;
2024-05-02 10:48:26 +02:00
port = 9003;
2024-04-30 14:22:50 +02:00
};
2024-04-29 15:12:52 +02:00
};
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-05-02 10:48:26 +02:00
{
job_name = "postfix";
static_configs = [{
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.postfix.port}" ];
}];
# scrape_interval = "60s";
}
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
}