gitea: Add monitoring

This commit is contained in:
Tristan Daniël Maat 2023-10-07 04:15:52 +02:00
parent c373911a1b
commit 6f8d95781c
Signed by: tlater
GPG key ID: 49670FD774E43268
2 changed files with 44 additions and 6 deletions

View file

@ -1,6 +1,7 @@
{ {
pkgs, pkgs,
config, config,
lib,
... ...
}: let }: let
domain = "gitea.${config.services.nginx.domain}"; domain = "gitea.${config.services.nginx.domain}";
@ -19,11 +20,23 @@ in {
SSH_PORT = 2222; SSH_PORT = 2222;
}; };
metrics = {
ENABLED = true;
TOKEN = "#metricstoken#";
};
service.DISABLE_REGISTRATION = true; service.DISABLE_REGISTRATION = true;
session.COOKIE_SECURE = true; session.COOKIE_SECURE = true;
}; };
}; };
systemd.services.gitea.serviceConfig.ExecStartPre = let
replaceSecretBin = "${pkgs.replace-secret}/bin/replace-secret";
secretPath = config.sops.secrets."gitea/metrics-token".path;
runConfig = "${config.services.gitea.customDir}/conf/app.ini";
in [
"${replaceSecretBin} '#metricstoken#' '${secretPath}' '${runConfig}'"
];
# Set up SSL # Set up SSL
services.nginx.virtualHosts."${domain}" = let services.nginx.virtualHosts."${domain}" = let
httpAddress = config.services.gitea.settings.server.HTTP_ADDR; httpAddress = config.services.gitea.settings.server.HTTP_ADDR;
@ -37,6 +50,14 @@ in {
''; '';
locations."/".proxyPass = "http://${httpAddress}:${toString httpPort}"; locations."/".proxyPass = "http://${httpAddress}:${toString httpPort}";
locations."/metrics" = {
extraConfig = ''
access_log off;
allow 127.0.0.1;
${lib.optionalString config.networking.enableIPv6 "allow ::1;"}
deny all;
'';
};
}; };
# Block repeated failed login attempts # Block repeated failed login attempts

View file

@ -138,12 +138,29 @@ in {
job_name = "tlater.net"; job_name = "tlater.net";
static_configs = [ static_configs = [
{ {
targets = targets = let
lib.mapAttrsToList (name: exporter: "${exporter.listenAddress}:${toString exporter.port}") exporters = config.services.prometheus.exporters;
(lib.filterAttrs (name: exporter: (builtins.isAttrs exporter) && exporter.enable) localExporters = config.services.prometheus.local-exporters;
(config.services.prometheus.exporters // config.services.prometheus.local-exporters)) in
++ [ map (exporter: "${exporter.listenAddress}:${toString exporter.port}") [
"127.0.0.1:9641" # coturn exporters.domain
exporters.node
exporters.nginx
exporters.nginxlog
exporters.systemd
localExporters.prometheus-fail2ban-exporter
{
# coturn
listenAddress = "127.0.0.1";
port = "9641";
}
{
# gitea
listenAddress = "127.0.0.1";
port = "3000";
}
]; ];
} }
]; ];