2024-07-05 12:18:23 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.bagel.monitoring.exporters.nginx;
|
|
|
|
inherit (lib) mkEnableOption mkIf;
|
|
|
|
logFormat = ''$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.bagel.monitoring.exporters.nginx.enable = (mkEnableOption "Nginx access.log exporter") // { default = config.services.nginx.enable; };
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.nginx.appendHttpConfig = ''
|
|
|
|
log_format ours '${logFormat}';
|
|
|
|
access_log /var/log/nginx/access.log ours;
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.prometheus.exporters.nginxlog = {
|
|
|
|
enable = true;
|
|
|
|
port = 9103;
|
|
|
|
group = "nginx";
|
|
|
|
settings.namespaces = [
|
|
|
|
{
|
|
|
|
name = "nginx";
|
|
|
|
format = logFormat;
|
|
|
|
source.files = ["/var/log/nginx/access.log"];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-07-07 22:34:30 +00:00
|
|
|
bagel.monitoring.grafana-agent.exporters.nginxlog.port = 9103;
|
2024-07-05 12:18:23 +00:00
|
|
|
};
|
|
|
|
}
|