1 { config, lib, pkgs, ... }:
12 cfg = config.services.metricbeat;
14 settingsFormat = pkgs.formats.yaml {};
20 services.metricbeat = {
22 enable = mkEnableOption (lib.mdDoc "metricbeat");
26 default = pkgs.metricbeat;
27 defaultText = literalExpression "pkgs.metricbeat";
28 example = literalExpression "pkgs.metricbeat7";
29 description = lib.mdDoc ''
30 The metricbeat package to use
35 description = lib.mdDoc ''
36 Metricbeat modules are responsible for reading metrics from the various sources.
38 This is like `services.metricbeat.settings.metricbeat.modules`,
39 but structured as an attribute set. This has the benefit that multiple
40 NixOS modules can contribute settings to a single metricbeat module.
42 A module can be specified multiple times by choosing a different `<name>`
43 for each, but setting [](#opt-services.metricbeat.modules._name_.module) to the same value.
45 See <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
48 type = types.attrsOf (types.submodule ({ name, ... }: {
49 freeformType = settingsFormat.type;
54 description = lib.mdDoc ''
55 The name of the module.
57 Look for the value after `module:` on the individual
58 module pages linked from <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
65 metricsets = ["cpu" "load" "memory" "network" "process" "process_summary" "uptime" "socket_summary"];
69 cpu.metrics = ["percentages" "normalized_percentages"];
70 core.metrics = ["percentages"];
76 type = types.submodule {
77 freeformType = settingsFormat.type;
83 description = lib.mdDoc ''
84 Name of the beat. Defaults to the hostname.
85 See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_name>.
90 type = types.listOf types.str;
92 description = lib.mdDoc ''
93 Tags to place on the shipped metrics.
94 See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_tags_2>.
98 metricbeat.modules = mkOption {
99 type = types.listOf settingsFormat.type;
102 description = lib.mdDoc ''
103 The metric collecting modules. Use [](#opt-services.metricbeat.modules) instead.
105 See <https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html>.
111 description = lib.mdDoc ''
112 Configuration for metricbeat. See <https://www.elastic.co/guide/en/beats/metricbeat/current/configuring-howto-metricbeat.html> for supported values.
119 config = mkIf cfg.enable {
123 # empty modules would cause a failure at runtime
124 assertion = cfg.settings.metricbeat.modules != [];
125 message = "services.metricbeat: You must configure one or more modules.";
129 services.metricbeat.settings.metricbeat.modules = attrValues cfg.modules;
131 systemd.services.metricbeat = {
132 description = "metricbeat metrics shipper";
133 wantedBy = [ "multi-user.target" ];
136 ${cfg.package}/bin/metricbeat \
137 -c ${settingsFormat.generate "metricbeat.yml" cfg.settings} \
138 --path.data $STATE_DIRECTORY \
139 --path.logs $LOGS_DIRECTORY \
144 ProtectSystem = "strict";
145 ProtectHome = "tmpfs";
146 StateDirectory = "metricbeat";
147 LogsDirectory = "metricbeat";