2023-09-25 02:32:04 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
domain = "metrics.${config.services.nginx.domain}";
|
|
|
|
yaml = pkgs.formats.yaml {};
|
|
|
|
in {
|
2023-10-02 21:54:21 +01:00
|
|
|
imports = [
|
|
|
|
./exporters.nix
|
|
|
|
];
|
|
|
|
|
2023-09-25 02:32:04 +01:00
|
|
|
services.victoriametrics.enable = true;
|
|
|
|
|
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
|
|
|
settings = {
|
|
|
|
server.http_port = 3001; # Default overlaps with gitea
|
|
|
|
|
|
|
|
security = {
|
|
|
|
admin_user = "tlater";
|
|
|
|
admin_password = "$__file{${config.sops.secrets."grafana/adminPassword".path}}";
|
|
|
|
secret_key = "$__file{${config.sops.secrets."grafana/secretKey".path}}";
|
|
|
|
cookie_secure = true;
|
|
|
|
cookie_samesite = "strict";
|
|
|
|
content_security_policy = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
database = {
|
|
|
|
user = "grafana";
|
|
|
|
name = "grafana";
|
|
|
|
type = "postgres";
|
|
|
|
host = "/run/postgresql";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
datasources.settings.datasources = [
|
|
|
|
{
|
|
|
|
name = "Victoriametrics - tlater.net";
|
|
|
|
url = "http://localhost:8428";
|
|
|
|
type = "prometheus";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.prometheus.exporters = {
|
|
|
|
node = {
|
|
|
|
enable = true;
|
|
|
|
enabledCollectors = ["systemd"];
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
2023-10-02 21:53:56 +01:00
|
|
|
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
|
|
|
|
|
|
|
nginxlog = {
|
|
|
|
enable = true;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
2023-09-25 02:32:04 +01:00
|
|
|
};
|
|
|
|
|
2023-10-02 21:54:21 +01:00
|
|
|
services.prometheus.local-exporters = {
|
|
|
|
prometheus-fail2ban-exporter = rec {
|
|
|
|
enable = true;
|
|
|
|
after = ["fail2ban.service"];
|
|
|
|
|
|
|
|
port = 9191;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Group = "fail2ban";
|
|
|
|
|
|
|
|
ExecStart = lib.concatStringsSep " " [
|
|
|
|
"${pkgs.local.prometheus-fail2ban-exporter}/bin/fail2ban-prometheus-exporter"
|
|
|
|
"--collector.f2b.socket=/var/run/fail2ban/fail2ban.sock"
|
|
|
|
"--web.listen-address='${listenAddress}:${toString port}'"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-09-25 02:32:04 +01:00
|
|
|
systemd.services.export-to-victoriametrics = let
|
|
|
|
promscrape = yaml.generate "prometheus.yml" {
|
|
|
|
scrape_configs = [
|
|
|
|
{
|
|
|
|
job_name = "tlater.net";
|
|
|
|
static_configs = [
|
|
|
|
{
|
|
|
|
targets =
|
|
|
|
lib.mapAttrsToList (name: exporter: "${exporter.listenAddress}:${toString exporter.port}")
|
|
|
|
(lib.filterAttrs (name: exporter: (builtins.isAttrs exporter) && exporter.enable)
|
2023-10-02 21:54:21 +01:00
|
|
|
(config.services.prometheus.exporters // config.services.prometheus.local-exporters));
|
2023-09-25 02:32:04 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
enable = true;
|
|
|
|
path = [pkgs.victoriametrics];
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
script = "vmagent -promscrape.config=${promscrape} -remoteWrite.url=http://localhost:8428/api/v1/write";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."${domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
enableACME = true;
|
|
|
|
extraConfig = ''
|
|
|
|
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
|
|
|
|
'';
|
|
|
|
locations."/".proxyPass = "http://localhost:3001";
|
|
|
|
};
|
|
|
|
}
|