Skip to content

Commit aa93730

Browse files
committed
nginx: add access log prometheus exporter
1 parent e5b20d9 commit aa93730

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

modules/dd-ix/nginx.nix

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
{ lib, config, ... }:
2+
13
let
4+
enable = config.services.nginx.enable;
25
headers = ''
36
# Permissions Policy - gps only
47
more_set_headers "Permissions-Policy: geolocation=()";
@@ -25,14 +28,27 @@ let
2528
'';
2629
in
2730
{
28-
networking.firewall.allowedTCPPorts = [ 80 443 ];
29-
services.nginx = {
30-
recommendedZstdSettings = true;
31-
recommendedTlsSettings = true;
32-
recommendedProxySettings = true;
33-
recommendedOptimisation = true;
34-
recommendedGzipSettings = true;
35-
recommendedBrotliSettings = true;
36-
commonServerConfig = headers;
31+
networking.firewall.allowedTCPPorts = lib.mkIf enable [ 80 443 ];
32+
services = {
33+
nginx = {
34+
recommendedZstdSettings = true;
35+
recommendedTlsSettings = true;
36+
recommendedProxySettings = true;
37+
recommendedOptimisation = true;
38+
recommendedGzipSettings = true;
39+
recommendedBrotliSettings = true;
40+
commonServerConfig = headers;
41+
};
42+
prometheus.exporters.nginxlog = lib.mkIf enable {
43+
enable = true;
44+
group = "nginx";
45+
settings.namespaces = [{
46+
name = "nginx";
47+
source.files = [ "/var/log/nginx/access.log" ];
48+
# default value extracted from:
49+
# https://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
50+
format = "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\"";
51+
}];
52+
};
3753
};
3854
}

modules/obs/prometheus-all.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ in
5151
listAddress;
5252
}];
5353
}
54+
{
55+
job_name = "nginxlog_exporter";
56+
static_configs = [{
57+
targets =
58+
let
59+
# filters out all the systems where monitoring is turned off
60+
monitoredSystems = builtins.filter (x: x.config.services.prometheus.exporters.nginxlog.enable) allSystems;
61+
62+
# turns the hostname into an address
63+
extractAddress = host: "${host.config.dd-ix.hostName}.dd-ix.net:9117";
64+
65+
# list of addresses
66+
listAddress = builtins.map extractAddress monitoredSystems;
67+
68+
in
69+
listAddress;
70+
}];
71+
}
5472
{
5573
job_name = "openrc_exporter";
5674
static_configs = [{

0 commit comments

Comments
 (0)