summaryrefslogtreecommitdiff
path: root/nixos/hosts/tente/monitoring.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/hosts/tente/monitoring.nix')
-rw-r--r--nixos/hosts/tente/monitoring.nix70
1 files changed, 70 insertions, 0 deletions
diff --git a/nixos/hosts/tente/monitoring.nix b/nixos/hosts/tente/monitoring.nix
index bbf4439..c761018 100644
--- a/nixos/hosts/tente/monitoring.nix
+++ b/nixos/hosts/tente/monitoring.nix
@@ -104,6 +104,19 @@ in
compactor = {
working_directory = "/var/lib/loki";
};
+
+ limits_config = {
+ allow_structured_metadata = true;
+ };
+ };
+ };
+
+ systemd.services.alloy = {
+ serviceConfig = {
+ SupplementaryGroups = [
+ "systemd-journal"
+ "www-data"
+ ];
};
};
@@ -131,6 +144,63 @@ in
}
}
+ loki.source.file "nginx_access" {
+ targets = local.file_match.nginx_access.targets
+ forward_to = [loki.process.nginx_access.receiver]
+ }
+
+ local.file_match "nginx_access" {
+ path_targets = [{
+ __path__ = "/var/log/nginx/*.access.log",
+ }]
+ }
+
+ loki.process "nginx_access" {
+ forward_to = [loki.write.default.receiver]
+
+ stage.static_labels {
+ values = {
+ job = "nginx",
+ }
+ }
+
+ // Extracting the log file name as vhost because it's more convenient
+ // to query for than the full filename. We could also use server_name
+ // but there could be wildcard server_names and Loki labels should have
+ // a low cardinality for performance reasons.
+ stage.regex {
+ source = "filename"
+ expression = "(?P<vhost>[^/]+)\\.access\\.log$"
+ }
+
+ stage.labels {
+ values = {
+ vhost = "",
+ }
+ }
+
+ stage.json {
+ expressions = { "msec" = "" }
+ }
+
+ stage.timestamp {
+ source = "msec"
+ format = "Unix"
+ }
+
+ // Setting level=info to prevent Loki's log level detection from wrongly
+ // detecting messages with paths containing "error" as errors.
+ // Creating the filetype entry via stage.template because there's no
+ // static_structured_metadata stage yet. (https://github.com/grafana/loki/issues/16703)
+ stage.template {
+ source = "level"
+ template = "info"
+ }
+ stage.structured_metadata {
+ values = { level = "" }
+ }
+ }
+
loki.write "default" {
endpoint {
url = "http://127.0.0.1:${toString cfg.lokiPort}/loki/api/v1/push"