1 { config, lib, pkgs, ... }:
13 cfg = config.services.metricbeat;
15 settingsFormat = pkgs.formats.yaml {};
21 services.metricbeat = {
23 enable = mkEnableOption "metricbeat";
25 package = mkPackageOption pkgs "metricbeat" {
26 example = "metricbeat7";
31 Metricbeat modules are responsible for reading metrics from the various sources.
33 This is like `services.metricbeat.settings.metricbeat.modules`,
34 but structured as an attribute set. This has the benefit that multiple
35 NixOS modules can contribute settings to a single metricbeat module.
37 A module can be specified multiple times by choosing a different `<name>`
38 for each, but setting [](#opt-services.metricbeat.modules._name_.module) to the same value.
40 See <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
43 type = types.attrsOf (types.submodule ({ name, ... }: {
44 freeformType = settingsFormat.type;
50 The name of the module.
52 Look for the value after `module:` on the individual
53 module pages linked from <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
60 metricsets = ["cpu" "load" "memory" "network" "process" "process_summary" "uptime" "socket_summary"];
64 cpu.metrics = ["percentages" "normalized_percentages"];
65 core.metrics = ["percentages"];
71 type = types.submodule {
72 freeformType = settingsFormat.type;
79 Name of the beat. Defaults to the hostname.
80 See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_name>.
85 type = types.listOf types.str;
88 Tags to place on the shipped metrics.
89 See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_tags_2>.
93 metricbeat.modules = mkOption {
94 type = types.listOf settingsFormat.type;
98 The metric collecting modules. Use [](#opt-services.metricbeat.modules) instead.
100 See <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
107 Configuration for metricbeat. See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuring-howto-metricbeat.html> for supported values.
114 config = mkIf cfg.enable {
118 # empty modules would cause a failure at runtime
119 assertion = cfg.settings.metricbeat.modules != [];
120 message = "services.metricbeat: You must configure one or more modules.";
124 services.metricbeat.settings.metricbeat.modules = attrValues cfg.modules;
126 systemd.services.metricbeat = {
127 description = "metricbeat metrics shipper";
128 wantedBy = [ "multi-user.target" ];
131 ${cfg.package}/bin/metricbeat \
132 -c ${settingsFormat.generate "metricbeat.yml" cfg.settings} \
133 --path.data $STATE_DIRECTORY \
134 --path.logs $LOGS_DIRECTORY \
139 ProtectSystem = "strict";
140 ProtectHome = "tmpfs";
141 StateDirectory = "metricbeat";
142 LogsDirectory = "metricbeat";