From c256a6ee063c86d17b7bc059d2650bb479a8f121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Barnouin?= Date: Mon, 7 Oct 2024 12:23:45 +0200 Subject: [PATCH] Add rsyslog / promtail log relay --- services/grafana/default.nix | 78 +++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/services/grafana/default.nix b/services/grafana/default.nix index 618251c..717a4c6 100644 --- a/services/grafana/default.nix +++ b/services/grafana/default.nix @@ -15,7 +15,20 @@ in }; }; config = lib.mkIf cfg.enable { - services.rsyslogd.enable = true; + services.rsyslogd = { + enable = true; + extraConfig = '' + ruleset(name="remote"){ + action(type="omfwd" Target="localhost" Port="1514" Protocol="tcp" Template="RSYSLOG_SyslogProtocol23Format" TCP_Framing="octet-counted") + } + + module(load="imudp") + input(type="imudp" port="514" ruleset="remote") + + module(load="imtcp") + input(type="imtcp" port="514" ruleset="remote") + ''; + }; services.grafana = { enable = true; settings = { @@ -170,20 +183,57 @@ in clients = [{ url = "http://127.0.0.1:3100/loki/api/v1/push"; }]; - scrape_configs = [{ - job_name = "journal"; - journal = { - max_age = "12h"; - labels = { - job = "systemd-journal"; - host = "localhost"; + scrape_configs = [ + { + job_name = "journal"; + journal = { + max_age = "12h"; + labels = { + job = "systemd-journal"; + host = "localhost"; + }; }; - }; - relabel_configs = [{ - source_labels = [ "__journal__systemd_unit" ]; - target_label = "unit"; - }]; - }]; + relabel_configs = [{ + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + }]; + } + { + job_name = "syslog"; + syslog = { + listen_address = "0.0.0.0:1514"; + labels = { + job = "syslog"; + }; + }; + relabel_configs = [ + { + source_labels = [ "__syslog_message_hostname" ]; + target_label = "host"; + } + { + source_labels = [ "__syslog_message_hostname" ]; + target_label = "hostname"; + } + { + source_labels = [ "__syslog_message_severity" ]; + target_label = "level"; + } + { + source_labels = [ "__syslog_message_app_name" ]; + target_label = "application"; + } + { + source_labels = [ "__syslog_message_facility" ]; + target_label = "facility"; + } + { + source_labels = [ "__syslog_connection_hostname" ]; + target_label = "connection_hostname"; + } + ]; + } + ]; }; };