make nginx logs properly work
This commit is contained in:
parent
e69fdc44d9
commit
f328d740e0
5 changed files with 69 additions and 95 deletions
|
@ -35,19 +35,32 @@ in
|
||||||
# todo : make sure we filter out metrics from otlp receivers
|
# todo : make sure we filter out metrics from otlp receivers
|
||||||
(mkIf config.components.monitor.enable {
|
(mkIf config.components.monitor.enable {
|
||||||
services.opentelemetry-collector.settings = {
|
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" ];
|
||||||
include = ".*";
|
|
||||||
match_type = "regexp";
|
processors = {
|
||||||
action = "update";
|
|
||||||
operations = [{
|
# https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/resourcedetectionprocessor/README.md
|
||||||
action = "add_label";
|
"resourcedetection/system" = {
|
||||||
new_label = "machine";
|
detectors = [ "system" ];
|
||||||
new_value = config.networking.hostName;
|
override = false;
|
||||||
}];
|
system.hostname_sources = [ "os" ];
|
||||||
}
|
};
|
||||||
];
|
|
||||||
|
metricstransform.transforms = [
|
||||||
|
{
|
||||||
|
include = ".*";
|
||||||
|
match_type = "regexp";
|
||||||
|
action = "update";
|
||||||
|
operations = [{
|
||||||
|
action = "add_label";
|
||||||
|
new_label = "machine";
|
||||||
|
new_value = config.networking.hostName;
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -33,23 +33,38 @@ with lib;
|
||||||
|
|
||||||
# for loki logging
|
# for loki logging
|
||||||
commonHttpConfig = ''
|
commonHttpConfig = ''
|
||||||
log_format logfmt escape=json 'timestamp=$time_iso8601 '
|
log_format logfmt
|
||||||
'facility=nginx '
|
'timestamp="$time_iso8601" '
|
||||||
'src_addr=$remote_addr '
|
'facility="nginx" '
|
||||||
'body_bytes_sent=$body_bytes_sent '
|
'src_addr="$remote_addr" '
|
||||||
'request_time=$request_time '
|
'body_bytes_sent="$body_bytes_sent" '
|
||||||
'response_status=$status '
|
'request_time="$request_time" '
|
||||||
'request="$request" '
|
'response_status="$status" '
|
||||||
'request_method="$request_method" '
|
'request_method="$request_method" '
|
||||||
|
'request="$request" '
|
||||||
'host="$host" '
|
'host="$host" '
|
||||||
'upstream_cache_status="$upstream_cache_status" '
|
'upstream_cache_status="$upstream_cache_status" '
|
||||||
'upstream_addr="$upstream_addr" '
|
'upstream_addr="$upstream_addr" '
|
||||||
'http_x_forwarded_for="$http_x_forwarded_for" '
|
'http_x_forwarded_for="$http_x_forwarded_for" '
|
||||||
'http_referrer="$http_referer" '
|
'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
|
# log to local journald
|
||||||
access_log syslog:server=unix:/dev/log logfmt;
|
access_log syslog:server=unix:/dev/log,nohostname logfmt;
|
||||||
'';
|
'';
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#./telemetry/opentelemetry-hass.nix
|
#./telemetry/opentelemetry-hass.nix
|
||||||
./telemetry/prometheus.nix
|
./telemetry/prometheus.nix
|
||||||
./telemetry/loki.nix
|
./telemetry/loki.nix
|
||||||
#./telemetry/promtail.nix
|
|
||||||
|
|
||||||
#./home-display.nix
|
#./home-display.nix
|
||||||
|
|
||||||
|
|
|
@ -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";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -17,29 +17,25 @@ in
|
||||||
recommendedTlsSettings = lib.mkDefault true;
|
recommendedTlsSettings = lib.mkDefault true;
|
||||||
|
|
||||||
# for loki logging
|
# for loki logging
|
||||||
commonHttpConfig = ''
|
#commonHttpConfig = ''
|
||||||
log_format logfmt escape=json 'timestamp=$time_iso8601 '
|
# log_format logfmt 'timestamp=$time_iso8601 '
|
||||||
'facility=nginx '
|
# 'facility=nginx '
|
||||||
'src_addr=$remote_addr '
|
# 'src_addr=$remote_addr '
|
||||||
'body_bytes_sent=$body_bytes_sent '
|
# 'body_bytes_sent=$body_bytes_sent '
|
||||||
'request_time=$request_time '
|
# 'request_time=$request_time '
|
||||||
'response_status=$status '
|
# 'response_status=$status '
|
||||||
'request="$request" '
|
# 'request="$request" '
|
||||||
'request_method="$request_method" '
|
# 'request_method="$request_method" '
|
||||||
'host="$host" '
|
# 'host="$host" '
|
||||||
'upstream_cache_status="$upstream_cache_status" '
|
# 'upstream_cache_status="$upstream_cache_status" '
|
||||||
'upstream_addr="$upstream_addr" '
|
# 'upstream_addr="$upstream_addr" '
|
||||||
'http_x_forwarded_for="$http_x_forwarded_for" '
|
# 'http_x_forwarded_for="$http_x_forwarded_for" '
|
||||||
'http_referrer="$http_referer" '
|
# 'http_referrer="$http_referer" '
|
||||||
'http_user_agent="$http_user_agent"';
|
# 'http_user_agent="$http_user_agent"';
|
||||||
|
#
|
||||||
# log to local journald
|
# # log to local journald
|
||||||
access_log syslog:server=unix:/dev/log logfmt;
|
# 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};
|
|
||||||
'';
|
|
||||||
|
|
||||||
|
|
||||||
# for graylog logging
|
# for graylog logging
|
||||||
|
|
Loading…
Reference in a new issue