{ pkgs, lib, config, ...}: with lib; let mkLauncher = import ../../packages/darwin-launcher.nix { inherit pkgs; }; durnitispOutPath = config.services.durnitisp.stdoutPath; durnitispErrPath = config.services.durnitisp.stderrPath; durnitispPidPath = config.services.durnitisp.pidPath; durnitispLauncher = mkLauncher '' exec ${pkgs.clio}/bin/clio \ --out-path=${durnitispOutPath} \ --err-path=${durnitispErrPath} \ --pid-file=${durnitispPidPath} \ --paranoid \ -- \ ${pkgs.durnitisp}/bin/durnitisp \ --listenHost=${config.services.durnitisp.listen} \ --stunHosts="stun.ekiga.net:3478,stun.schlund.de:3478,stun.voipbuster.com:3478,stun.voipstunt.com:3478,stun.xten.com:3478" \ --pingHosts="google.com,prod.actual.battle.net" ''; in { options.services.node-exporter = { enable = mkEnableOption "Enable the prometheus node_exporter"; listen = mkOption { description = "[host]:port to listen on for the node_exporter"; default = "localhost:9100"; defaultText = "localhost:9100"; }; }; options.services.heracles = { enable = mkEnableOption "Enable the heracles server"; listen = mkOption { description = "[host]:port to listen on for the heracles server"; default = "localhost:9001"; defaultText = "localhost:9001"; }; logsPath = mkOption rec { description = "Path to save heracles log files to"; default = "/Users/zaphar/opt/heracles"; defaultText = default; }; stdoutPath = mkOption { default = "${config.services.heracles.logsPath}/heracles.out.log"; }; stderrPath = mkOption { default = "${config.services.heracles.logsPath}/heracles.err.log"; }; pidPath = mkOption { default = "${config.services.heracles.logsPath}/heracles.pid"; }; settings = mkOption { description = "Settings for the heracles dashboards"; default = []; defaultText = "[]"; }; }; options.services.durnitisp = { enable = mkEnableOption "Enable the durnitisp server"; listen = mkOption { description = "[host]:port to listen on for the durnitisp metrics server"; default = "localhost:9002"; defaultText = "localhost:9002"; }; stdoutPath = mkOption { default = "/var/log/durnitisp.out.log"; }; stderrPath = mkOption { default = "/var/log/durnitisp.err.log"; }; # TODO(zaphar): Should this be written somewhere else? pidPath = mkOption { default = "/var/log/durnitisp.pid"; }; }; options.services.prometheus = { enable = lib.mkEnableOption "Enable the prometheus server"; listen = mkOption { description = "[host]:port to listen on for the prometheus server"; default = "localhost:9000"; defaultText = "localhost:9000"; }; stdoutPath = mkOption { default = "${config.services.prometheus.dataPath}/prometheus.out.log"; }; stderrPath = mkOption { default = "${config.services.prometheus.dataPath}/prometheus.err.log"; }; pidPath = mkOption { default = "${config.services.prometheus.dataPath}/prometheus.pid"; }; settings = mkOption { description = "The yaml configuration file settings for prometheus"; default = { scrape_configs = [ { job_name = "node_exporter"; scrape_interval = "30s"; metrics_path = "/metrics"; static_configs = [ { targets = [ "${config.services.node-exporter.listen}" ]; } ]; } { job_name = "network_quality"; scrape_interval = "30s"; metrics_path = "/"; static_configs = [ { targets = [ "${config.services.durnitisp.listen}" ]; } ]; } ]; }; defaultText = ''{ scrape_configs = [ { job_name = "nodestats"; scrape_interval = "30s"; metrics_path = "/metrics"; static_configs = [ { targets = [ "${config.services.node-exporter.listen}" ]; } ]; } ]; }''; }; dataPath = mkOption rec { description = "Storage path for the tsdb"; default = "/Users/zaphar/opt/prometheus"; defaultText = default; }; }; config = let heraclesOutPath = config.services.heracles.stdoutPath; heraclesErrPath = config.services.heracles.stderrPath; heraclesPidPath = config.services.heracles.pidPath; prometheusOutPath = config.services.prometheus.stdoutPath; prometheusErrPath = config.services.prometheus.stderrPath; prometheusPidPath = config.services.prometheus.pidPath; in { launchd.user.agents.node-exporter = mkIf config.services.node-exporter.enable { serviceConfig = { ProgramArguments = [ "${pkgs.prometheus-node-exporter}/bin/node_exporter" "--web.listen-address=${config.services.node-exporter.listen}" ]; KeepAlive = true; RunAtLoad = true; }; }; environment.etc."prometheus.yaml" = mkIf config.services.prometheus.enable { text = (generators.toYAML {} config.services.prometheus.settings); }; environment.etc."heracles.yaml" = mkIf config.services.heracles.enable { text = (generators.toYAML {} config.services.heracles.settings); }; launchd.user.agents.heracles = mkIf config.services.heracles.enable { serviceConfig = { ProgramArguments = [ "${pkgs.clio}/bin/clio" "--out-path=${heraclesOutPath}" "--err-path=${heraclesErrPath}" "--pid-file=${heraclesPidPath}" "--paranoid" "--" "${pkgs.heracles}/bin/heracles" "--listen=${config.services.heracles.listen}" "--config=/etc/${config.environment.etc."heracles.yaml".target}" ]; WatchPaths = [ "/etc/${config.environment.etc."heracles.yaml".target}" ]; KeepAlive = true; RunAtLoad = true; }; }; launchd.daemons.durnitisp = mkIf config.services.durnitisp.enable { serviceConfig = { ProgramArguments = [ "${durnitispLauncher}" ]; #StandardErrorPath = "/var/log/clio.durnitisp.err"; #StandardOutPath = "/var/log/clio.durnitisp.out"; RunAtLoad = true; }; }; launchd.user.agents.prometheus = mkIf config.services.prometheus.enable { serviceConfig = { ProgramArguments = [ "/bin/sh" "-c" '' /bin/wait4path ${pkgs.clio}/bin/clio && \ exec ${pkgs.clio}/bin/clio \ --out-path=${prometheusOutPath} \ --err-path=${prometheusErrPath} \ --pid-file=${prometheusPidPath} \ --paranoid \ -- \ ${pkgs.prometheus}/bin/prometheus \ --web.listen-address=${config.services.prometheus.listen} \ --config.file=/etc/${config.environment.etc."prometheus.yaml".target} \ --storage.tsdb.path=${config.services.prometheus.dataPath}/data \ '' ]; WorkingDirectory = config.services.prometheus.dataPath; WatchPaths = [ "/etc/${config.environment.etc."prometheus.yaml".target}" ]; KeepAlive = true; RunAtLoad = true; }; }; environment.etc."newsyslog.d/org.nixos.prometheus.conf" = mkIf config.services.prometheus.enable { text = '' # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] ${prometheusOutPath} zaphar:staff 644 10 1000 * BJ ${prometheusPidPath} 1 ${prometheusErrPath} zaphar:staff 644 10 1000 * BJ ${prometheusPidPath} 1 ''; }; #environment.etc."newsyslog.d/org.nixos.heracles.conf" = mkIf config.services.prometheus.enable { # text = '' # # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] # ${heraclesOutPath} zaphar:staff 644 10 1000 * BJ ${heraclesPidPath} 1 # ${heraclesErrPath} zaphar:staff 644 10 1000 * BJ ${heraclesPidPath} 1 # ''; #}; environment.etc."newsyslog.d/org.nixos.durnitisp.conf" = mkIf config.services.durnitisp.enable { text = '' # logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] ${durnitispOutPath} zaphar:staff 644 10 1000 * BJ ${prometheusPidPath} 1 ${durnitispErrPath} zaphar:staff 644 10 1000 * BJ ${prometheusPidPath} 1 ''; }; }; }