monitoring
This commit is contained in:
1 parent
decc501b3c
commit
8d55b87546
4 files changed
+340
-27
No files matched your search
@@ -0,0 +1,110 @@
|
||||
{
|
||||
den.aspects.services.monitoring = let grafanaPort = 3005; proxyPort = 3006; in {
|
||||
tunnel = [
|
||||
{ subdomain = "monitor"; port = proxyPort; }
|
||||
{ subdomain = "metrics"; port = 9090; }
|
||||
];
|
||||
|
||||
nixos = { config, lib, pkgs, host, ... }: let
|
||||
home = config.users.users.${host.owner}.home;
|
||||
secrets = "${home}/.config/monitoring";
|
||||
cred = name: "$__file{/run/credentials/grafana.service/${name}}";
|
||||
overview = pkgs.writeTextDir "overview.json" (builtins.toJSON (import ./_overview.nix { inherit lib; }));
|
||||
exp = config.services.prometheus.exporters;
|
||||
in {
|
||||
services.prometheus = {
|
||||
enableAgentMode = false;
|
||||
port = 9090;
|
||||
retentionTime = "30d";
|
||||
extraFlags = [ "--web.enable-remote-write-receiver" ];
|
||||
webConfigFile = "/run/credentials/prometheus.service/web.yml";
|
||||
|
||||
exporters.process = {
|
||||
enable = true;
|
||||
listenAddress = "127.0.0.1";
|
||||
settings.process_names = [{ name = "{{.Comm}}"; cmdline = [ ".+" ]; }];
|
||||
};
|
||||
|
||||
scrapeConfigs = [
|
||||
{ job_name = "process"; static_configs = [{ targets = [ "127.0.0.1:${toString exp.process.port}" ]; labels.instance = config.networking.hostName; }]; }
|
||||
{ job_name = "cloudflared"; static_configs = [{ targets = [ "127.0.0.1:9300" ]; labels.instance = config.networking.hostName; }]; }
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.prometheus.serviceConfig.LoadCredential = [ "web.yml:${secrets}/web.yml" ];
|
||||
|
||||
systemd.services."cloudflared-tunnel-${host.cloudflared.uuid}".environment.TUNNEL_METRICS = "127.0.0.1:9300";
|
||||
|
||||
services.grafana = {
|
||||
enable = true;
|
||||
|
||||
settings = {
|
||||
server = {
|
||||
http_addr = "127.0.0.1";
|
||||
http_port = grafanaPort;
|
||||
domain = "monitor.${host.domain}";
|
||||
root_url = "https://monitor.${host.domain}";
|
||||
static_root_path = "${import ./_mocha.nix { inherit pkgs; grafana = config.services.grafana.package; }}";
|
||||
};
|
||||
security = {
|
||||
admin_user = host.owner;
|
||||
admin_password = cred "pw";
|
||||
secret_key = cred "secret";
|
||||
};
|
||||
"auth.anonymous" = { enabled = true; org_role = "Viewer"; };
|
||||
analytics.reporting_enabled = false;
|
||||
dashboards.default_home_dashboard_path = "${overview}/overview.json";
|
||||
unified_alerting.enabled = false;
|
||||
explore.enabled = false;
|
||||
news.news_feed_enabled = false;
|
||||
help.enabled = false;
|
||||
profile.enabled = false;
|
||||
public_dashboards.enabled = false;
|
||||
users = { allow_sign_up = false; home_page = "/d/overview"; default_theme = "dark"; };
|
||||
};
|
||||
|
||||
provision = {
|
||||
datasources.settings.datasources = [{
|
||||
name = "Prometheus";
|
||||
type = "prometheus";
|
||||
uid = "prometheus";
|
||||
url = "http://127.0.0.1:9090";
|
||||
isDefault = true;
|
||||
basicAuth = true;
|
||||
basicAuthUser = "push";
|
||||
jsonData.timeInterval = "1m";
|
||||
secureJsonData.basicAuthPassword = cred "pw";
|
||||
}];
|
||||
dashboards.settings.providers = [{ name = "default"; options.path = overview; }];
|
||||
};
|
||||
};
|
||||
|
||||
services.caddy = {
|
||||
enable = true;
|
||||
globalConfig = "auto_https off";
|
||||
virtualHosts."http://:${toString proxyPort}" = {
|
||||
listenAddresses = [ "127.0.0.1" ];
|
||||
extraConfig = ''
|
||||
@pin {
|
||||
not header Cookie *grafana_session=*
|
||||
not path /login* /logout* /api/* /apis/* /public/* /avatar/* /bootdata* /manifest.json /favicon.ico /d/overview*
|
||||
}
|
||||
@nokiosk {
|
||||
not header Cookie *grafana_session=*
|
||||
path /d/overview*
|
||||
not query kiosk=*
|
||||
}
|
||||
redir @pin /d/overview?kiosk 302
|
||||
redir @nokiosk /d/overview?kiosk&{query} 302
|
||||
reverse_proxy 127.0.0.1:${toString grafanaPort}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.grafana.serviceConfig.LoadCredential = [
|
||||
"pw:${secrets}/password"
|
||||
"secret:${secrets}/grafana-secret"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user