at 24.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.heartbeat; 7 8 heartbeatYml = pkgs.writeText "heartbeat.yml" '' 9 name: ${cfg.name} 10 tags: ${builtins.toJSON cfg.tags} 11 12 ${cfg.extraConfig} 13 ''; 14 15in 16{ 17 options = { 18 19 services.heartbeat = { 20 21 enable = mkEnableOption "heartbeat, uptime monitoring"; 22 23 package = mkPackageOption pkgs "heartbeat" { 24 example = "heartbeat7"; 25 }; 26 27 name = mkOption { 28 type = types.str; 29 default = "heartbeat"; 30 description = "Name of the beat"; 31 }; 32 33 tags = mkOption { 34 type = types.listOf types.str; 35 default = []; 36 description = "Tags to place on the shipped log messages"; 37 }; 38 39 stateDir = mkOption { 40 type = types.str; 41 default = "/var/lib/heartbeat"; 42 description = "The state directory. heartbeat's own logs and other data are stored here."; 43 }; 44 45 extraConfig = mkOption { 46 type = types.lines; 47 default = '' 48 heartbeat.monitors: 49 - type: http 50 urls: ["http://localhost:9200"] 51 schedule: '@every 10s' 52 ''; 53 description = "Any other configuration options you want to add"; 54 }; 55 56 }; 57 }; 58 59 config = mkIf cfg.enable { 60 61 systemd.tmpfiles.rules = [ 62 "d '${cfg.stateDir}' - nobody nogroup - -" 63 ]; 64 65 systemd.services.heartbeat = with pkgs; { 66 description = "heartbeat log shipper"; 67 wantedBy = [ "multi-user.target" ]; 68 preStart = '' 69 mkdir -p "${cfg.stateDir}"/{data,logs} 70 ''; 71 serviceConfig = { 72 User = "nobody"; 73 AmbientCapabilities = "cap_net_raw"; 74 ExecStart = "${cfg.package}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\""; 75 }; 76 }; 77 }; 78}