at 25.11-pre 3.1 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.scollector; 9 10 collectors = pkgs.runCommand "collectors" { preferLocalBuild = true; } '' 11 mkdir -p $out 12 ${lib.concatStringsSep "\n" ( 13 lib.mapAttrsToList ( 14 frequency: binaries: 15 "mkdir -p $out/${frequency}\n" 16 + (lib.concatStringsSep "\n" ( 17 map (path: "ln -s ${path} $out/${frequency}/$(basename ${path})") binaries 18 )) 19 ) cfg.collectors 20 )} 21 ''; 22 23 conf = pkgs.writeText "scollector.toml" '' 24 Host = "${cfg.bosunHost}" 25 ColDir = "${collectors}" 26 ${cfg.extraConfig} 27 ''; 28 29in 30{ 31 32 options = { 33 34 services.scollector = { 35 36 enable = lib.mkOption { 37 type = lib.types.bool; 38 default = false; 39 description = '' 40 Whether to run scollector. 41 ''; 42 }; 43 44 package = lib.mkPackageOption pkgs "scollector" { }; 45 46 user = lib.mkOption { 47 type = lib.types.str; 48 default = "scollector"; 49 description = '' 50 User account under which scollector runs. 51 ''; 52 }; 53 54 group = lib.mkOption { 55 type = lib.types.str; 56 default = "scollector"; 57 description = '' 58 Group account under which scollector runs. 59 ''; 60 }; 61 62 bosunHost = lib.mkOption { 63 type = lib.types.str; 64 default = "localhost:8070"; 65 description = '' 66 Host and port of the bosun server that will store the collected 67 data. 68 ''; 69 }; 70 71 collectors = lib.mkOption { 72 type = with lib.types; attrsOf (listOf path); 73 default = { }; 74 example = lib.literalExpression ''{ "0" = [ "''${postgresStats}/bin/collect-stats" ]; }''; 75 description = '' 76 An attribute set mapping the frequency of collection to a list of 77 binaries that should be executed at that frequency. You can use "0" 78 to run a binary forever. 79 ''; 80 }; 81 82 extraOpts = lib.mkOption { 83 type = with lib.types; listOf str; 84 default = [ ]; 85 example = [ "-d" ]; 86 description = '' 87 Extra scollector command line options 88 ''; 89 }; 90 91 extraConfig = lib.mkOption { 92 type = lib.types.lines; 93 default = ""; 94 description = '' 95 Extra scollector configuration added to the end of scollector.toml 96 ''; 97 }; 98 99 }; 100 101 }; 102 103 config = lib.mkIf config.services.scollector.enable { 104 105 systemd.services.scollector = { 106 description = "scollector metrics collector (part of Bosun)"; 107 wantedBy = [ "multi-user.target" ]; 108 109 path = [ 110 pkgs.coreutils 111 pkgs.iproute2 112 ]; 113 114 serviceConfig = { 115 User = cfg.user; 116 Group = cfg.group; 117 ExecStart = "${cfg.package}/bin/scollector -conf=${conf} ${lib.concatStringsSep " " cfg.extraOpts}"; 118 }; 119 }; 120 121 users.users.scollector = { 122 description = "scollector user"; 123 group = "scollector"; 124 uid = config.ids.uids.scollector; 125 }; 126 127 users.groups.scollector.gid = config.ids.gids.scollector; 128 129 }; 130 131}