From 40a74fc8a71f4d20ddf57b771f8bdcae19c9ed93 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sat, 1 Jun 2024 13:02:27 -0400 Subject: [PATCH] feat: vector sending logs to victoria-logs --- nix/base-system/darwin-configuration.nix | 57 +++++++++++++++++++++++ nix/base-system/flake.nix | 1 + nix/base-system/modules/vector.nix | 34 ++++++++++++++ nix/base-system/modules/victoria-logs.nix | 2 +- 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 nix/base-system/modules/vector.nix diff --git a/nix/base-system/darwin-configuration.nix b/nix/base-system/darwin-configuration.nix index bc63733..a99b7b5 100644 --- a/nix/base-system/darwin-configuration.nix +++ b/nix/base-system/darwin-configuration.nix @@ -162,6 +162,63 @@ ]; services.victoria-logs.enable = true; + services.vector.enable = true; + services.vector.settings = { + data_dir = "/var/lib/vector"; + sources = { + prometheus = { + type = "file"; + include = [ + "${config.launchd.user.agents.prometheus.serviceConfig.StandardOutPath}" + "${config.launchd.user.agents.prometheus.serviceConfig.StandardErrorPath}" + ]; + }; + heracles = { + type = "file"; + include = [ + "${config.launchd.user.agents.heracles.serviceConfig.StandardOutPath}" + "${config.launchd.user.agents.heracles.serviceConfig.StandardErrorPath}" + ]; + }; + # TODO(zaphar): We should remap durnitisp output to get strip the tty control characters. + durnitisp = { + type = "file"; + include = [ + "${config.launchd.daemons.durnitisp.serviceConfig.StandardOutPath}" + "${config.launchd.daemons.durnitisp.serviceConfig.StandardErrorPath}" + ]; + }; + vector = { + type = "file"; + include = [ + "${config.launchd.daemons.vector.serviceConfig.StandardOutPath}" + "${config.launchd.daemons.vector.serviceConfig.StandardErrorPath}" + ]; + }; + }; + sinks = { + victoria = { + type = "elasticsearch"; + mode = "bulk"; + endpoints = [ + "http://${config.services.victoria-logs.listenAddr}/insert/elasticsearch/" + ]; + inputs = [ + "prometheus" + "heracles" + "durnitisp" + "vector" + ]; + api_version = "v8"; + healthcheck.enabled = false; + query = { + _msg_field = "message"; + _time_field = "timestamp"; + _stream_fields = "host,file"; + }; + }; + }; + }; # TODO launchd.user.agents.prometheus; # Use a custom configuration.nix location. diff --git a/nix/base-system/flake.nix b/nix/base-system/flake.nix index 9a10325..527d87a 100644 --- a/nix/base-system/flake.nix +++ b/nix/base-system/flake.nix @@ -349,6 +349,7 @@ EOF"; (vimModule system) ./modules/darwin-monitor.nix ./modules/victoria-logs.nix + ./modules/vector.nix ./darwin-configuration.nix ]; }; diff --git a/nix/base-system/modules/vector.nix b/nix/base-system/modules/vector.nix new file mode 100644 index 0000000..1189662 --- /dev/null +++ b/nix/base-system/modules/vector.nix @@ -0,0 +1,34 @@ +{pkgs, lib, config, ...}: +with lib; +{ + options.services.vector = { + enable = mkEnableOption "Enable the vector agent"; + settings = mkOption { + description = "Settings for the vector agent"; + default = { + data_dir = "/var/lib/vector"; + }; + defaultText = "{}"; + }; + }; + + config = { + environment.etc."vector.yaml" = mkIf config.services.vector.enable { + text = (generators.toYAML {} config.services.vector.settings); + }; + + launchd.daemons.vector = mkIf config.services.vector.enable { + serviceConfig = { + ProgramArguments = [ + "${pkgs.vector}/bin/vector" + "--watch-config" + "--config=/etc/${config.environment.etc."vector.yaml".target}" + ]; + KeepAlive = true; + RunAtLoad = true; + StandardOutPath = "/var/log/vector.out.log"; + StandardErrorPath = "/var/log/vector.err.log"; + }; + }; + }; +} diff --git a/nix/base-system/modules/victoria-logs.nix b/nix/base-system/modules/victoria-logs.nix index 9afdbf1..c6bd83b 100644 --- a/nix/base-system/modules/victoria-logs.nix +++ b/nix/base-system/modules/victoria-logs.nix @@ -10,7 +10,7 @@ with lib; }; listenAddr = mkOption { description = "Socket Address to listen on"; - default = ":9428"; + default = "127.0.0.1:9428"; }; }; };