-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
nixos/metricbeat: init #117379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
nixos/metricbeat: init #117379
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| { config, lib, pkgs, ... }: | ||
|
|
||
| let | ||
| inherit (lib) | ||
| attrValues | ||
| literalExample | ||
| mkEnableOption | ||
| mkIf | ||
| mkOption | ||
| types | ||
| ; | ||
| cfg = config.services.metricbeat; | ||
|
|
||
| settingsFormat = pkgs.formats.yaml {}; | ||
|
|
||
| in | ||
| { | ||
| options = { | ||
|
|
||
| services.metricbeat = { | ||
|
|
||
| enable = mkEnableOption "metricbeat"; | ||
|
|
||
| package = mkOption { | ||
| type = types.package; | ||
| default = pkgs.metricbeat; | ||
| defaultText = literalExample "pkgs.metricbeat"; | ||
| example = literalExample "pkgs.metricbeat7"; | ||
| description = '' | ||
| The metricbeat package to use | ||
| ''; | ||
| }; | ||
|
|
||
| modules = mkOption { | ||
| description = '' | ||
| Metricbeat modules are responsible for reading metrics from the various sources. | ||
|
|
||
| This is like <literal>services.metricbeat.settings.metricbeat.modules</literal>, | ||
| but structured as an attribute set. This has the benefit that multiple | ||
| NixOS modules can contribute settings to a single metricbeat module. | ||
|
|
||
| A module can be specified multiple times by choosing a different <literal><name></literal> | ||
| for each, but setting <xref linkend="opt-services.metricbeat.modules._name_.module"/> to the same value. | ||
|
|
||
| See <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html"/>. | ||
| ''; | ||
| default = {}; | ||
| type = types.attrsOf (types.submodule ({ name, ... }: { | ||
| freeformType = settingsFormat.type; | ||
| options = { | ||
| module = mkOption { | ||
| type = types.str; | ||
| default = name; | ||
| defaultText = literalExample ''<name>''; | ||
| description = '' | ||
| The name of the module. | ||
|
|
||
| Look for the value after <literal>module:</literal> on the individual | ||
| module pages linked from <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html"/>. | ||
| ''; | ||
| }; | ||
| }; | ||
| })); | ||
| example = { | ||
| system = { | ||
| metricsets = ["cpu" "load" "memory" "network" "process" "process_summary" "uptime" "socket_summary"]; | ||
| enabled = true; | ||
| period = "10s"; | ||
| processes = [".*"]; | ||
| cpu.metrics = ["percentages" "normalized_percentages"]; | ||
| core.metrics = ["percentages"]; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| settings = mkOption { | ||
| type = types.submodule { | ||
| freeformType = settingsFormat.type; | ||
| options = { | ||
|
|
||
| name = mkOption { | ||
| type = types.str; | ||
| default = ""; | ||
| description = '' | ||
| Name of the beat. Defaults to the hostname. | ||
| See <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_name"/>. | ||
| ''; | ||
| }; | ||
|
|
||
| tags = mkOption { | ||
| type = types.listOf types.str; | ||
| default = []; | ||
| description = '' | ||
| Tags to place on the shipped metrics. | ||
| See <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-general-options.html#_tags_2"/>. | ||
| ''; | ||
| }; | ||
|
|
||
| metricbeat.modules = mkOption { | ||
| type = types.listOf settingsFormat.type; | ||
| default = []; | ||
| internal = true; | ||
| description = '' | ||
| The metric collecting modules. Use <xref linkend="opt-services.metricbeat.modules"/> instead. | ||
|
|
||
| See <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-modules.html"/>. | ||
| ''; | ||
| }; | ||
| }; | ||
| }; | ||
| default = {}; | ||
| description = '' | ||
| Configuration for metricbeat. See <link xlink:href="https://www.elastic.co/guide/en/beats/metricbeat/current/configuring-howto-metricbeat.html"/> for supported values. | ||
| ''; | ||
| }; | ||
|
|
||
| }; | ||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
|
|
||
| assertions = [ | ||
| { | ||
| # empty modules would cause a failure at runtime | ||
| assertion = cfg.settings.metricbeat.modules != []; | ||
| message = "services.metricbeat: You must configure one or more modules."; | ||
| } | ||
| ]; | ||
|
|
||
| services.metricbeat.settings.metricbeat.modules = attrValues cfg.modules; | ||
|
|
||
| systemd.services.metricbeat = { | ||
| description = "metricbeat metrics shipper"; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| serviceConfig = { | ||
| ExecStart = '' | ||
| ${cfg.package}/bin/metricbeat \ | ||
| -c ${settingsFormat.generate "metricbeat.yml" cfg.settings} \ | ||
| --path.data $STATE_DIRECTORY \ | ||
| --path.logs $LOGS_DIRECTORY \ | ||
| ; | ||
| ''; | ||
| Restart = "always"; | ||
| DynamicUser = true; | ||
| ProtectSystem = "strict"; | ||
| ProtectHome = "tmpfs"; | ||
| StateDirectory = "metricbeat"; | ||
| LogsDirectory = "metricbeat"; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the semicolon needed for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for the backslash. This style of multi-line statement produces smaller diffs, making it easier to merge.