Skip to content

Commit f6b5c31

Browse files
committed
nginx: enable prometheus exporter
1 parent a46ad1a commit f6b5c31

5 files changed

Lines changed: 45 additions & 5 deletions

File tree

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{ config, lib, ... }:
2+
let
3+
logFormat = ''$remote_addr - $remote_user [$time_local] "$host" "$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"'';
4+
in
25
{
3-
options.uwumarie.profiles.nginx = lib.mkEnableOption (lib.mdDoc "nginx config");
6+
options.uwumarie.profiles.nginx.enable = lib.mkEnableOption (lib.mdDoc "nginx config");
7+
options.uwumarie.profiles.nginx.monitoring.enable = lib.mkEnableOption (lib.mdDoc "nginx monitoring") // {
8+
default = true;
9+
};
410
options.services.nginx.virtualHosts = lib.mkOption {
511
type = lib.types.attrsOf (lib.types.submodule {
612
config.forceSSL = lib.mkDefault true;
713
config.http2 = lib.mkDefault true;
814
config.useACMEHost = lib.mkDefault "marie.cologne";
915
});
1016
};
11-
config = lib.mkIf config.uwumarie.profiles.nginx {
17+
config = lib.mkIf config.uwumarie.profiles.nginx.enable {
1218
services.nginx = {
1319
enable = true;
1420
virtualHosts."_" = {
@@ -17,11 +23,32 @@
1723
return = "404";
1824
};
1925
};
26+
virtualHosts.localhost = {
27+
forceSSL = false;
28+
http2 = false;
29+
useACMEHost = null;
30+
};
2031
recommendedTlsSettings = true;
2132
recommendedOptimisation = true;
2233
recommendedGzipSettings = true;
2334
recommendedBrotliSettings = true;
2435
recommendedProxySettings = true;
36+
appendHttpConfig = ''
37+
log_format meow '${logFormat}';
38+
access_log /var/log/nginx/access.log meow;
39+
'';
40+
};
41+
42+
services.prometheus.exporters.nginxlog = {
43+
enable = config.uwumarie.profiles.nginx.monitoring.enable;
44+
group = "nginx";
45+
settings.namespaces = [
46+
{
47+
name = "nginx";
48+
format = logFormat;
49+
source.files = ["/var/log/nginx/access.log"];
50+
}
51+
];
2552
};
2653
};
2754
}

hosts/artemis/configuration.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
fail2ban = true;
1616
openssh = true;
1717
acme = true;
18-
nginx = true;
18+
nginx.enable = true;
1919
nix = true;
2020
users.marie = true;
2121
headless = true;

hosts/artemis/monitoring/prometheus/default.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@
8383
}
8484
];
8585
}
86+
{
87+
job_name = "nginx";
88+
static_configs = [
89+
{
90+
targets = [ "localhost:9117" ];
91+
labels.instance = config.networking.hostName;
92+
}
93+
{
94+
targets = [ "delphi:9117" ];
95+
labels.instance = "delphi";
96+
}
97+
];
98+
}
8699
(mkTarget {
87100
job = "ip-playground";
88101
target = "127.0.0.1:3032";

hosts/delphi/configuration.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
uwumarie.profiles = {
1515
openssh = true;
1616
acme = true;
17-
nginx = true;
17+
nginx.enable = true;
1818
nix = true;
1919
users.marie = true;
2020
headless = true;

hosts/marie-nas/configuration.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
uwumarie.profiles = {
3030
headless = true;
3131
acme = true;
32-
nginx = true;
32+
nginx.enable = true;
3333
};
3434

3535
services.iperf3 = {

0 commit comments

Comments
 (0)