From 809d4ee6c1647b0f72f675ee62433f0a485c9825 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 1 Dec 2024 23:21:42 -0600 Subject: [PATCH] observation conversion --- configuration.nix | 6 ++++ portainer.nix | 13 ++++++++ promtail.nix | 81 +++++++++++++++++++++++++++++++++++++++++++++++ watchtower.nix | 11 +++++++ 4 files changed, 111 insertions(+) create mode 100644 portainer.nix create mode 100644 promtail.nix create mode 100644 watchtower.nix diff --git a/configuration.nix b/configuration.nix index 332908e..3af1b1a 100644 --- a/configuration.nix +++ b/configuration.nix @@ -14,6 +14,9 @@ in (import "${builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz}/nixos") (fetchTarball "https://github.com/nix-community/nixos-vscode-server/tarball/master") ./telegraf.nix + ./promtail.nix + ./portainer.nix + ./watchtower.nix ]; environment.systemPackages = with pkgs; [ @@ -27,6 +30,7 @@ in echo "${adPath} already exists" fi '') + unstable.uv bash git eza @@ -37,6 +41,8 @@ in time.timeZone = "America/Chicago"; virtualisation.docker.enable = true; + virtualisation.oci-containers.backend = "docker"; + services.vscode-server.enable = true; services.openssh.enable = true; services.tailscale.enable = true; diff --git a/portainer.nix b/portainer.nix new file mode 100644 index 0000000..2ced680 --- /dev/null +++ b/portainer.nix @@ -0,0 +1,13 @@ +{ ... }: +{ + virtualisation.oci-containers.containers.portainer-agent = { + image = "portainer/agent:latest"; # Use the latest Portainer agent image + ports = [ + "9001:9001" # Expose the Portainer agent API port + ]; + volumes = [ + "/etc/zoneinfo/America/Chicago:/etc/localtime:ro" + "/var/run/docker.sock:/var/run/docker.sock" + ]; + }; +} \ No newline at end of file diff --git a/promtail.nix b/promtail.nix new file mode 100644 index 0000000..52c137e --- /dev/null +++ b/promtail.nix @@ -0,0 +1,81 @@ +{ config, ... }: +let + lokiHost = "192.168.1.174:3100"; +in +{ + systemd.services.promtail.serviceConfig = { + SupplementaryGroups = [ "docker" ]; + }; + + services.promtail = { + enable = true; + configuration = { + server = { + http_listen_port = 3031; + grpc_listen_port = 0; + }; + positions = { + filename = "/tmp/positions.yaml"; + }; + clients = [{url = "http://${lokiHost}/loki/api/v1/push";}]; + scrape_configs = [ + { + job_name = "journal"; + journal = { + max_age = "24h"; + path = "/var/log/journal"; + json = true; + # matches: _TRANSPORT=kernel; + labels = { + job = "systemd-journal"; + host = config.networking.hostName; # Dynamically fetch the hostname + }; + }; + relabel_configs = [ + { + source_labels = [ "__journal__systemd_unit" ]; + target_label = "unit"; + } + ]; + } + { + job_name = "flog_scrape"; + docker_sd_configs = [ + { + host = "unix:///var/run/docker.sock"; + refresh_interval = "5s"; + } + ]; + relabel_configs = [ + { + source_labels = [ "__meta_docker_container_name" ]; + regex = "/(.*)"; + target_label = "container"; + } + { + source_labels = [ "__meta_docker_container_label_com_docker_compose_oneoff" ]; + target_label = "oneoff"; + } + { + source_labels = [ "__meta_docker_container_label_com_docker_compose_project_config_files" ]; + target_label = "compose_file"; + } + { + source_labels = [ "__meta_docker_container_label_com_docker_compose_project" ]; + target_label = "project_name"; + } + { + source_labels = [ "__meta_docker_container_label_com_docker_compose_service" ]; + target_label = "service"; + } + { + target_label = "host"; + replacement = "${config.networking.hostName}"; + } + ]; + } + ]; + }; + # extraFlags + }; +} \ No newline at end of file diff --git a/watchtower.nix b/watchtower.nix new file mode 100644 index 0000000..666d6aa --- /dev/null +++ b/watchtower.nix @@ -0,0 +1,11 @@ +{ ... }: +{ + virtualisation.oci-containers.containers.watchtower = { + image = "containrrr/watchtower:latest"; + volumes = [ + "/etc/zoneinfo/America/Chicago:/etc/localtime:ro" + "/var/run/docker.sock:/var/run/docker.sock" + ]; + environment = {WATCHTOWER_SCHEDULE = "0 0 3 * * *";}; + }; +} \ No newline at end of file