nixos: crawler report as native units
Same script, schedule and threshold. It now mails through SMTP with the alert account from sops instead of reading Forgejo's app.ini out of its container, and reads Traefik's log at its new place. Forgejo's router is forgejo@file now. Tried on the rehearsal pair against generated GPTBot traffic. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
cbf14b4b99
commit
2a0e7bd83a
3 changed files with 85 additions and 0 deletions
82
nixos/hosts/asxpio-ops/crawler.nix
Normal file
82
nixos/hosts/asxpio-ops/crawler.nix
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
# Crawler watch for Forgejo: separates real AI crawlers from traffic that
|
||||||
|
# only claims to be one, from Traefik's access log. A daily mail when
|
||||||
|
# yesterday crossed the threshold, a weekly summary, and metrics every
|
||||||
|
# five minutes for the Crawlers dashboard.
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
# flag: "" (daily alert), "--weekly" or "--metrics"
|
||||||
|
run = flag: extra: {
|
||||||
|
description = "Crawler report ${flag}";
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
environment = {
|
||||||
|
CRAWLER_SITE = "git.asxp.io";
|
||||||
|
CRAWLER_THRESHOLD = "100000";
|
||||||
|
CRAWLER_ROBOTS = "https://git.czsk.it/robots.txt";
|
||||||
|
CRAWLER_LOG = "/var/log/traefik/access.log*";
|
||||||
|
CRAWLER_LIVE_LOG = "/var/log/traefik/access.log";
|
||||||
|
CRAWLER_ROUTER = "forgejo@file";
|
||||||
|
CRAWLER_TEXTFILE = "/var/lib/node_exporter/textfile/crawler.prom";
|
||||||
|
CRAWLER_SMTP_ADDR = "smtp.fastmail.com";
|
||||||
|
CRAWLER_SMTP_PORT = "587";
|
||||||
|
CRAWLER_SMTP_FROM = "Czechoslovakia Git <noreply@asxp.io>";
|
||||||
|
}
|
||||||
|
// extra;
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
EnvironmentFile = config.sops.templates."crawler.env".path;
|
||||||
|
CacheDirectory = "crawler-alert";
|
||||||
|
ExecStart = "${pkgs.python3}/bin/python3 ${./crawler-alert.py} ${flag}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
sops.templates."crawler.env".content = ''
|
||||||
|
CRAWLER_RECIPIENT=${config.sops.placeholder."alert/recipient"}
|
||||||
|
CRAWLER_SMTP_USER=${config.sops.placeholder."alert/smtp_user"}
|
||||||
|
CRAWLER_SMTP_PASSWORD=${config.sops.placeholder."alert/smtp_password"}
|
||||||
|
'';
|
||||||
|
|
||||||
|
systemd.services = {
|
||||||
|
crawler-alert = run "" { };
|
||||||
|
crawler-weekly = run "--weekly" { };
|
||||||
|
# Every router, not only Forgejo's; fewer DNS lookups per run
|
||||||
|
crawler-metrics = lib.recursiveUpdate (run "--metrics" {
|
||||||
|
CRAWLER_METRICS_ROUTER = "";
|
||||||
|
CRAWLER_RDNS_MAX = "100";
|
||||||
|
}) {
|
||||||
|
serviceConfig = {
|
||||||
|
Nice = 10;
|
||||||
|
TimeoutStartSec = "4min";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systemd.timers = {
|
||||||
|
crawler-alert = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "*-*-* 00:15:00";
|
||||||
|
Persistent = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
crawler-weekly = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "Mon *-*-* 12:00:00";
|
||||||
|
Persistent = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
crawler-metrics = {
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "*:0/5";
|
||||||
|
RandomizedDelaySec = 30;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
./crawler.nix
|
||||||
./forgejo.nix
|
./forgejo.nix
|
||||||
./garage.nix
|
./garage.nix
|
||||||
./monitoring
|
./monitoring
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@
|
||||||
# No alert mail from a test pair
|
# No alert mail from a test pair
|
||||||
asxpio.alertEmail = "nobody@example.invalid";
|
asxpio.alertEmail = "nobody@example.invalid";
|
||||||
services.grafana.settings.smtp.enabled = lib.mkForce false;
|
services.grafana.settings.smtp.enabled = lib.mkForce false;
|
||||||
|
systemd.timers.crawler-alert.enable = false;
|
||||||
|
systemd.timers.crawler-weekly.enable = false;
|
||||||
services.loki.configuration = {
|
services.loki.configuration = {
|
||||||
# No Object Storage keys here: everything on local disk
|
# No Object Storage keys here: everything on local disk
|
||||||
schema_config.configs = lib.mkForce [
|
schema_config.configs = lib.mkForce [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue