emily
8d2a367e92
This allows us to use multiple jobs, one for each additional exporter, and set their `job_name` accordingly. `job_name` is exported as `job` label on the resulting metrics. This allows us to quickly get an understanding what metrics of an exporter are actually available by simply filtering all metrics by `{job="$jobname"}`
35 lines
1 KiB
Nix
35 lines
1 KiB
Nix
{
|
|
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"];
|
|
}
|
|
];
|
|
};
|
|
|
|
bagel.monitoring.grafana-agent.exporters.nginxlog.port = 9103;
|
|
};
|
|
} |