Monitoring stack (almost done)
This commit is contained in:
parent
7d2ce03dc3
commit
b96176958c
4 changed files with 249 additions and 2 deletions
130
modules/monitoring/grafana.nix
Normal file
130
modules/monitoring/grafana.nix
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.my.monitoring.grafana;
|
||||
|
||||
in
|
||||
{
|
||||
options.my.monitoring.grafana = {
|
||||
enable = lib.mkEnableOption "Enable grafana as a data visualization";
|
||||
|
||||
proxy = {
|
||||
enable = lib.mkEnableOption "Set the proxy entry for this service";
|
||||
|
||||
domain = lib.mkOption {
|
||||
default = "example.com";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The domain where Caddy is reachable
|
||||
'';
|
||||
};
|
||||
|
||||
host = lib.mkOption {
|
||||
default = "localhost";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Host name where Grafana is running
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf cfg.enable {
|
||||
|
||||
age.secrets = {
|
||||
grafana-admin-pwd = {
|
||||
file = ../../secrets/grafana-admin-pwd.age;
|
||||
owner = "grafana";
|
||||
};
|
||||
};
|
||||
|
||||
services = {
|
||||
|
||||
grafana = {
|
||||
enable = true;
|
||||
settings = {
|
||||
analytics.reporting_enabled = false;
|
||||
database = {
|
||||
user = "grafana";
|
||||
type = "postgres";
|
||||
|
||||
host = "/run/postgresql/";
|
||||
name = "grafana";
|
||||
};
|
||||
security = {
|
||||
admin_user = "pazpi";
|
||||
admin_password = "$__file{${config.age.secrets.grafana-admin-pwd.path}}";
|
||||
};
|
||||
server = {
|
||||
domain = "grafana.neon-dory.ts.net";
|
||||
http_addr = "0.0.0.0";
|
||||
http_port = 3000;
|
||||
# root_url = "https://grafana.${cfg.proxy.domain}";
|
||||
enable_gzip = true;
|
||||
};
|
||||
users = {
|
||||
default_theme = "light";
|
||||
allow_sign_up = false;
|
||||
};
|
||||
};
|
||||
# XXX Just for future reference
|
||||
# provision.dashboards.settings.providers = [
|
||||
# {
|
||||
# name = "example";
|
||||
# options.path = ./dashboards/example.json;
|
||||
# }
|
||||
# ];
|
||||
};
|
||||
|
||||
grafana-image-renderer = {
|
||||
enable = true;
|
||||
provisionGrafana = true;
|
||||
chromium = pkgs.ungoogled-chromium;
|
||||
};
|
||||
|
||||
postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [ "grafana" ];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = "grafana";
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = [ 3000 ];
|
||||
|
||||
})
|
||||
|
||||
(lib.mkIf (cfg.proxy != { }) {
|
||||
services.caddy = with cfg.proxy; {
|
||||
virtualHosts."grafana.${domain}".extraConfig = ''
|
||||
reverse_proxy http://${host}:3000
|
||||
import cloudflare
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
# {
|
||||
# name = "Alertmanager";
|
||||
# type = "alertmanager";
|
||||
# url = "http://nuc:9093";
|
||||
# jsonData.implementation = "prometheus";
|
||||
# jsonData.handleGrafanaManagedAlerts = true;
|
||||
# }
|
||||
Loading…
Add table
Add a link
Reference in a new issue