make nginx logs properly work

This commit is contained in:
Ingolf Wagner 2024-05-15 17:11:41 +02:00
parent e69fdc44d9
commit f328d740e0
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
5 changed files with 69 additions and 95 deletions

View file

@ -35,8 +35,20 @@ in
# todo : make sure we filter out metrics from otlp receivers
(mkIf config.components.monitor.enable {
services.opentelemetry-collector.settings = {
service.pipelines.metrics.processors = [ "metricstransform" ];
processors.metricstransform.transforms = [
service.pipelines.metrics.processors = [ "metricstransform" "resourcedetection/system" ];
service.pipelines.logs.processors = [ "resourcedetection/system" ];
processors = {
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourcedetectionprocessor/README.md
"resourcedetection/system" = {
detectors = [ "system" ];
override = false;
system.hostname_sources = [ "os" ];
};
metricstransform.transforms = [
{
include = ".*";
match_type = "regexp";
@ -49,6 +61,7 @@ in
}
];
};
};
})
# ship to next instance

View file

@ -33,23 +33,38 @@ with lib;
# for loki logging
commonHttpConfig = ''
log_format logfmt escape=json 'timestamp=$time_iso8601 '
'facility=nginx '
'src_addr=$remote_addr '
'body_bytes_sent=$body_bytes_sent '
'request_time=$request_time '
'response_status=$status '
'request="$request" '
log_format logfmt
'timestamp="$time_iso8601" '
'facility="nginx" '
'src_addr="$remote_addr" '
'body_bytes_sent="$body_bytes_sent" '
'request_time="$request_time" '
'response_status="$status" '
'request_method="$request_method" '
'request="$request" '
'host="$host" '
'upstream_cache_status="$upstream_cache_status" '
'upstream_addr="$upstream_addr" '
'http_x_forwarded_for="$http_x_forwarded_for" '
'http_referrer="$http_referer" '
'http_user_agent="$http_user_agent"';
'http_user_agent="$http_user_agent" ';
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';
# log to local journald
access_log syslog:server=unix:/dev/log logfmt;
access_log syslog:server=unix:/dev/log,nohostname logfmt;
'';
};

View file

@ -42,7 +42,6 @@
#./telemetry/opentelemetry-hass.nix
./telemetry/prometheus.nix
./telemetry/loki.nix
#./telemetry/promtail.nix
#./home-display.nix

View file

@ -1,49 +0,0 @@
{ config, ... }:
{
services.opentelemetry-collector.settings = {
receivers.loki = {
protocols.http.endpoint = "127.0.0.1:3500";
use_incoming_timestamp = true;
};
service.pipelines.logs.receivers = [ "loki" ];
};
services.promtail = {
enable = true;
configuration = {
server = {
http_listen_port = 28183;
grpc_listen_port = 0;
};
positions.filename = "/tmp/positions.yaml";
clients = [
{ url = "http://127.0.0.1:3500/loki/api/v1/push"; }
];
scrape_configs = [
{
job_name = "journal";
journal = {
max_age = "12h";
#labels = {
# job = "systemd-journal";
# host = config.networking.hostName;
#};
};
relabel_configs = [
{
source_labels = [ "__journal__systemd_unit" ];
target_label = "unit";
}
{
source_labels = [ "__journal__transport" ];
target_label = "transport";
}
];
}
];
};
};
}

View file

@ -17,29 +17,25 @@ in
recommendedTlsSettings = lib.mkDefault true;
# for loki logging
commonHttpConfig = ''
log_format logfmt escape=json 'timestamp=$time_iso8601 '
'facility=nginx '
'src_addr=$remote_addr '
'body_bytes_sent=$body_bytes_sent '
'request_time=$request_time '
'response_status=$status '
'request="$request" '
'request_method="$request_method" '
'host="$host" '
'upstream_cache_status="$upstream_cache_status" '
'upstream_addr="$upstream_addr" '
'http_x_forwarded_for="$http_x_forwarded_for" '
'http_referrer="$http_referer" '
'http_user_agent="$http_user_agent"';
# log to local journald
access_log syslog:server=unix:/dev/log logfmt;
# to send logs somewhere
#access_log syslog:server=${access_log_sink} logfmt;
#error_log syslog:server=${error_log_sink};
'';
#commonHttpConfig = ''
# log_format logfmt 'timestamp=$time_iso8601 '
# 'facility=nginx '
# 'src_addr=$remote_addr '
# 'body_bytes_sent=$body_bytes_sent '
# 'request_time=$request_time '
# 'response_status=$status '
# 'request="$request" '
# 'request_method="$request_method" '
# 'host="$host" '
# 'upstream_cache_status="$upstream_cache_status" '
# 'upstream_addr="$upstream_addr" '
# 'http_x_forwarded_for="$http_x_forwarded_for" '
# 'http_referrer="$http_referer" '
# 'http_user_agent="$http_user_agent"';
#
# # log to local journald
# access_log syslog:server=unix:/dev/log logfmt;
# '';
# for graylog logging