summary refs log tree commit diff
path: root/nixos/modules/services/logging
diff options
context:
space:
mode:
authorTristan Helmich <tristan.helmich@gmail.com>2017-07-01 18:57:18 +0200
committerTristan Helmich <tristan.helmich@gmail.com>2017-07-02 10:45:59 +0200
commit97e8422541d2acbf083e9efde6f0a42ffde2e18b (patch)
tree74cc7ae8f2e5b81e8a0369dd3e99bb2cf1431d22 /nixos/modules/services/logging
parenta20dbcb88b7aa125e6da481405395083784e1c00 (diff)
downloadnixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar.gz
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar.bz2
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar.lz
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar.xz
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.tar.zst
nixlib-97e8422541d2acbf083e9efde6f0a42ffde2e18b.zip
heartbeat service: init
Diffstat (limited to 'nixos/modules/services/logging')
-rw-r--r--nixos/modules/services/logging/heartbeat.nix72
1 files changed, 72 insertions, 0 deletions
diff --git a/nixos/modules/services/logging/heartbeat.nix b/nixos/modules/services/logging/heartbeat.nix
new file mode 100644
index 000000000000..b595ac07bf5e
--- /dev/null
+++ b/nixos/modules/services/logging/heartbeat.nix
@@ -0,0 +1,72 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.heartbeat;
+
+  heartbeatYml = pkgs.writeText "heartbeat.yml" ''
+    name: ${cfg.name}
+    tags: ${builtins.toJSON cfg.tags}
+
+    ${cfg.extraConfig}
+  '';
+
+in
+{
+  options = {
+
+    services.heartbeat = {
+
+      enable = mkEnableOption "heartbeat";
+
+      name = mkOption {
+        type = types.str;
+        default = "heartbeat";
+        description = "Name of the beat";
+      };
+
+      tags = mkOption {
+        type = types.listOf types.str;
+        default = [];
+        description = "Tags to place on the shipped log messages";
+      };
+
+      stateDir = mkOption {
+        type = types.str;
+        default = "/var/lib/heartbeat";
+        description = "The state directory. heartbeat's own logs and other data are stored here.";
+      };
+
+      extraConfig = mkOption {
+        type = types.lines;
+        default = ''
+          heartbeat.monitors:
+          - type: http
+            urls: ["http://localhost:9200"]
+            schedule: '@every 10s'
+        '';
+        description = "Any other configuration options you want to add";
+      };
+
+    };
+  };
+
+  config = mkIf cfg.enable {
+
+    systemd.services.heartbeat = with pkgs; {
+      description = "heartbeat log shipper";
+      wantedBy = [ "multi-user.target" ];
+      preStart = ''
+        mkdir -p "${cfg.stateDir}"/{data,logs}
+        chown nobody:nogroup "${cfg.stateDir}"/{data,logs}
+      '';
+      serviceConfig = {
+        User = "nobody";
+        PermissionsStartOnly = true;
+        AmbientCapabilities = "cap_net_raw";
+        ExecStart = "${pkgs.heartbeat}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\"";
+      };
+    };
+  };
+}