diff options
Diffstat (limited to 'nixos/modules/services/monitoring')
5 files changed, 45 insertions, 166 deletions
diff --git a/nixos/modules/services/monitoring/grafana-agent.nix b/nixos/modules/services/monitoring/grafana-agent.nix index bbeda184647..a4b18b4f28e 100644 --- a/nixos/modules/services/monitoring/grafana-agent.nix +++ b/nixos/modules/services/monitoring/grafana-agent.nix @@ -48,9 +48,10 @@ in freeformType = settingsFormat.type; }; - default = { + default = { }; + defaultText = '' metrics = { - wal_directory = "\${STATE_DIRECTORY}"; + wal_directory = "\''${STATE_DIRECTORY}"; global.scrape_interval = "5s"; }; integrations = { @@ -59,8 +60,7 @@ in node_exporter.enabled = true; replace_instance_label = true; }; - }; - + ''; example = { metrics.global.remote_write = [{ url = "\${METRICS_REMOTE_WRITE_URL}"; @@ -104,6 +104,20 @@ in }; config = mkIf cfg.enable { + services.grafana-agent.settings = { + # keep this in sync with config.services.grafana-agent.settings.defaultText. + metrics = { + wal_directory = mkDefault "\${STATE_DIRECTORY}"; + global.scrape_interval = mkDefault "5s"; + }; + integrations = { + agent.enabled = mkDefault true; + agent.scrape_integration = mkDefault true; + node_exporter.enabled = mkDefault true; + replace_instance_label = mkDefault true; + }; + }; + systemd.services.grafana-agent = { wantedBy = [ "multi-user.target" ]; script = '' diff --git a/nixos/modules/services/monitoring/graphite.nix b/nixos/modules/services/monitoring/graphite.nix index baa943302a0..1dc2cee479a 100644 --- a/nixos/modules/services/monitoring/graphite.nix +++ b/nixos/modules/services/monitoring/graphite.nix @@ -24,16 +24,6 @@ let + cfg.web.extraConfig ); - graphiteApiConfig = pkgs.writeText "graphite-api.yaml" '' - search_index: ${dataDir}/index - ${optionalString (config.time.timeZone != null) "time_zone: ${config.time.timeZone}"} - ${optionalString (cfg.api.finders != []) "finders:"} - ${concatMapStringsSep "\n" (f: " - " + f.moduleName) cfg.api.finders} - ${optionalString (cfg.api.functions != []) "functions:"} - ${concatMapStringsSep "\n" (f: " - " + f) cfg.api.functions} - ${cfg.api.extraConfig} - ''; - seyrenConfig = { SEYREN_URL = cfg.seyren.seyrenUrl; MONGO_URL = cfg.seyren.mongoUrl; @@ -72,6 +62,8 @@ let in { imports = [ + (mkRemovedOptionModule ["services" "graphite" "api"] "") + (mkRemovedOptionModule ["services" "graphite" "beacon"] "") (mkRemovedOptionModule ["services" "graphite" "pager"] "") ]; @@ -115,88 +107,6 @@ in { }; }; - api = { - enable = mkOption { - description = '' - Whether to enable graphite api. Graphite api is lightweight alternative - to graphite web, with api and without dashboard. It's advised to use - grafana as alternative dashboard and influxdb as alternative to - graphite carbon. - - For more information visit - <link xlink:href="https://graphite-api.readthedocs.org/en/latest/"/> - ''; - default = false; - type = types.bool; - }; - - finders = mkOption { - description = "List of finder plugins to load."; - default = []; - example = literalExpression "[ pkgs.python3Packages.influxgraph ]"; - type = types.listOf types.package; - }; - - functions = mkOption { - description = "List of functions to load."; - default = [ - "graphite_api.functions.SeriesFunctions" - "graphite_api.functions.PieFunctions" - ]; - type = types.listOf types.str; - }; - - listenAddress = mkOption { - description = "Graphite web service listen address."; - default = "127.0.0.1"; - type = types.str; - }; - - port = mkOption { - description = "Graphite api service port."; - default = 8080; - type = types.int; - }; - - package = mkOption { - description = "Package to use for graphite api."; - default = pkgs.python3Packages.graphite_api; - defaultText = literalExpression "pkgs.python3Packages.graphite_api"; - type = types.package; - }; - - extraConfig = mkOption { - description = "Extra configuration for graphite api."; - default = '' - whisper: - directories: - - ${dataDir}/whisper - ''; - defaultText = literalExpression '' - ''' - whisper: - directories: - - ''${config.${opt.dataDir}}/whisper - ''' - ''; - example = '' - allowed_origins: - - dashboard.example.com - cheat_times: true - influxdb: - host: localhost - port: 8086 - user: influxdb - pass: influxdb - db: metrics - cache: - CACHE_TYPE: 'filesystem' - CACHE_DIR: '/tmp/graphite-api-cache' - ''; - type = types.lines; - }; - }; - carbon = { config = mkOption { description = "Content of carbon configuration file."; @@ -354,16 +264,6 @@ in { ''; }; }; - - beacon = { - enable = mkEnableOption "graphite beacon"; - - config = mkOption { - description = "Graphite beacon configuration."; - default = {}; - type = types.attrs; - }; - }; }; ###### implementation @@ -489,44 +389,6 @@ in { environment.systemPackages = [ pkgs.python3Packages.graphite-web ]; })) - (mkIf cfg.api.enable { - systemd.services.graphiteApi = { - description = "Graphite Api Interface"; - wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; - environment = { - PYTHONPATH = let - aenv = pkgs.python3.buildEnv.override { - extraLibs = [ cfg.api.package pkgs.cairo pkgs.python3Packages.cffi ] ++ cfg.api.finders; - }; - in "${aenv}/${pkgs.python3.sitePackages}"; - GRAPHITE_API_CONFIG = graphiteApiConfig; - LD_LIBRARY_PATH = "${pkgs.cairo.out}/lib"; - }; - serviceConfig = { - ExecStart = '' - ${pkgs.python3Packages.waitress}/bin/waitress-serve \ - --host=${cfg.api.listenAddress} --port=${toString cfg.api.port} \ - graphite_api.app:app - ''; - User = "graphite"; - Group = "graphite"; - PermissionsStartOnly = true; - }; - preStart = '' - if ! test -e ${dataDir}/db-created; then - mkdir -p ${dataDir}/cache/ - chmod 0700 ${dataDir}/cache/ - - chown graphite:graphite ${cfg.dataDir} - chown -R graphite:graphite ${cfg.dataDir}/cache - - touch ${dataDir}/db-created - fi - ''; - }; - }) - (mkIf cfg.seyren.enable { systemd.services.seyren = { description = "Graphite Alerting Dashboard"; @@ -550,25 +412,9 @@ in { services.mongodb.enable = mkDefault true; }) - (mkIf cfg.beacon.enable { - systemd.services.graphite-beacon = { - description = "Grpahite Beacon Alerting Daemon"; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStart = '' - ${pkgs.python3Packages.graphite_beacon}/bin/graphite-beacon \ - --config=${pkgs.writeText "graphite-beacon.json" (builtins.toJSON cfg.beacon.config)} - ''; - User = "graphite"; - Group = "graphite"; - }; - }; - }) - (mkIf ( cfg.carbon.enableCache || cfg.carbon.enableAggregator || cfg.carbon.enableRelay || - cfg.web.enable || cfg.api.enable || - cfg.seyren.enable || cfg.beacon.enable + cfg.web.enable || cfg.seyren.enable ) { users.users.graphite = { uid = config.ids.uids.graphite; diff --git a/nixos/modules/services/monitoring/netdata.nix b/nixos/modules/services/monitoring/netdata.nix index 489dd337bb7..baf869af1c4 100644 --- a/nixos/modules/services/monitoring/netdata.nix +++ b/nixos/modules/services/monitoring/netdata.nix @@ -186,7 +186,7 @@ in { description = "Real time performance monitoring"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - path = (with pkgs; [ curl gawk iproute2 which procps ]) + path = (with pkgs; [ curl gawk iproute2 which procps bash ]) ++ lib.optional cfg.python.enable (pkgs.python3.withPackages cfg.python.extraPackages) ++ lib.optional config.virtualisation.libvirtd.enable (config.virtualisation.libvirtd.package); environment = { @@ -201,7 +201,9 @@ in { serviceConfig = { ExecStart = "${cfg.package}/bin/netdata -P /run/netdata/netdata.pid -D -c /etc/netdata/netdata.conf"; ExecReload = "${pkgs.util-linux}/bin/kill -s HUP -s USR1 -s USR2 $MAINPID"; - ExecPostStart = ''while [ "$(netdatacli ping)" != pong ]; do sleep 0.5; done''; + ExecStartPost = pkgs.writeShellScript "wait-for-netdata-up" '' + while [ "$(${pkgs.netdata}/bin/netdatacli ping)" != pong ]; do sleep 0.5; done + ''; TimeoutStopSec = 60; Restart = "on-failure"; diff --git a/nixos/modules/services/monitoring/prometheus/exporters/mail.nix b/nixos/modules/services/monitoring/prometheus/exporters/mail.nix index 956bd96aa45..a60f47f6393 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/mail.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/mail.nix @@ -5,6 +5,8 @@ with lib; let cfg = config.services.prometheus.exporters.mail; + configFile = if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile); + configurationFile = pkgs.writeText "prometheus-mail-exporter.conf" (builtins.toJSON ( # removes the _module attribute, null values and converts attrNames to lowercase mapAttrs' (name: value: @@ -137,6 +139,13 @@ in { port = 9225; extraOpts = { + environmentFile = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + File containing env-vars to be substituted into the exporter's config. + ''; + }; configFile = mkOption { type = types.nullOr types.path; default = null; @@ -162,13 +171,19 @@ in serviceOpts = { serviceConfig = { DynamicUser = false; + EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; + RuntimeDirectory = "prometheus-mail-exporter"; + ExecStartPre = [ + "${pkgs.writeShellScript "subst-secrets-mail-exporter" '' + umask 0077 + ${pkgs.envsubst}/bin/envsubst -i ${configFile} -o ''${RUNTIME_DIRECTORY}/mail-exporter.json + ''}" + ]; ExecStart = '' ${pkgs.prometheus-mail-exporter}/bin/mailexporter \ --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ --web.telemetry-path ${cfg.telemetryPath} \ - --config.file ${ - if cfg.configuration != null then configurationFile else (escapeShellArg cfg.configFile) - } \ + --config.file ''${RUNTIME_DIRECTORY}/mail-exporter.json \ ${concatStringsSep " \\\n " cfg.extraFlags} ''; }; diff --git a/nixos/modules/services/monitoring/prometheus/exporters/node.nix b/nixos/modules/services/monitoring/prometheus/exporters/node.nix index 5e5fc7cd552..417920402f3 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/node.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/node.nix @@ -44,6 +44,8 @@ in ]; # The timex collector needs to access clock APIs ProtectClock = any (collector: collector == "timex") cfg.disabledCollectors; + # Allow space monitoring under /home + ProtectHome = true; }; }; } |