modules: services: add monitoring
This includes a dashboard to monitor system ressources, using Prometheus.
This commit is contained in:
parent
9fa16a9b33
commit
c910b643da
|
@ -14,6 +14,7 @@
|
|||
./lohr.nix
|
||||
./matrix.nix
|
||||
./miniflux.nix
|
||||
./monitoring.nix
|
||||
./nextcloud.nix
|
||||
./nginx.nix
|
||||
./pirate.nix
|
||||
|
|
116
modules/services/monitoring.nix
Normal file
116
modules/services/monitoring.nix
Normal file
|
@ -0,0 +1,116 @@
|
|||
# Grafana dashboards for all the things!
|
||||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.my.services.monitoring;
|
||||
|
||||
domain = config.networking.domain;
|
||||
grafanaDomain = "monitoring.${config.networking.domain}";
|
||||
in
|
||||
{
|
||||
options.my.services.monitoring = with lib; {
|
||||
enable = mkEnableOption "monitoring";
|
||||
|
||||
grafana = {
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 9500;
|
||||
example = 3001;
|
||||
description = "Internal port";
|
||||
};
|
||||
|
||||
username = mkOption {
|
||||
type = types.str;
|
||||
default = "ambroisie";
|
||||
example = "admin";
|
||||
description = "Admin username";
|
||||
};
|
||||
|
||||
passwordFile = mkOption {
|
||||
type = types.str;
|
||||
example = "/var/lib/grafana/password.txt";
|
||||
description = "Admin password stored in a file";
|
||||
};
|
||||
};
|
||||
|
||||
prometheus = {
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 9501;
|
||||
example = 3002;
|
||||
description = "Internal port";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
services.grafana = {
|
||||
enable = true;
|
||||
domain = grafanaDomain;
|
||||
port = cfg.grafana.port;
|
||||
addr = "127.0.0.1"; # Proxied through Nginx
|
||||
|
||||
security = {
|
||||
adminUser = cfg.grafana.username;
|
||||
adminPasswordFile = cfg.grafana.passwordFile;
|
||||
};
|
||||
|
||||
provision = {
|
||||
enable = true;
|
||||
|
||||
datasources = [
|
||||
{
|
||||
name = "Prometheus";
|
||||
type = "prometheus";
|
||||
url = "http://localhost:${toString cfg.prometheus.port}";
|
||||
}
|
||||
];
|
||||
|
||||
dashboards = [
|
||||
{
|
||||
name = "Node Exporter";
|
||||
options.path = pkgs.nur.repos.alarsyo.grafana-dashboards.node-exporter;
|
||||
disableDeletion = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.prometheus = {
|
||||
enable = true;
|
||||
port = cfg.prometheus.port;
|
||||
listenAddress = "127.0.0.1";
|
||||
|
||||
retentionTime = "2y";
|
||||
|
||||
exporters = {
|
||||
node = {
|
||||
enable = true;
|
||||
enabledCollectors = [ "systemd" ];
|
||||
port = 9100;
|
||||
listenAddress = "127.0.0.1";
|
||||
};
|
||||
};
|
||||
|
||||
scrapeConfigs = [
|
||||
{
|
||||
job_name = config.networking.hostName;
|
||||
static_configs = [{
|
||||
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.node.port}" ];
|
||||
}];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
services.nginx = {
|
||||
virtualHosts.${grafanaDomain} = {
|
||||
forceSSL = true;
|
||||
useACMEHost = domain;
|
||||
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString cfg.grafana.port}";
|
||||
proxyWebsockets = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue