Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into HEAD
- Loading branch information
Showing
126 changed files
with
2,454 additions
and
1,953 deletions.
There are no files selected for viewing
This file contains 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 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 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,80 @@ | ||
<section xmlns="http://docbook.org/ns/docbook" | ||
xmlns:xlink="http://www.w3.org/1999/xlink" | ||
xmlns:xi="http://www.w3.org/2001/XInclude" | ||
version="5.0" | ||
xml:id="sec-assertions"> | ||
|
||
<title>Warnings and Assertions</title> | ||
|
||
<para> | ||
When configuration problems are detectable in a module, it is a good | ||
idea to write an assertion or warning. Doing so provides clear | ||
feedback to the user and prevents errors after the build. | ||
</para> | ||
|
||
<para> | ||
Although Nix has the <literal>abort</literal> and | ||
<literal>builtins.trace</literal> <link xlink:href="https://nixos.org/nix/manual/#ssec-builtins">functions</link> to perform such tasks, | ||
they are not ideally suited for NixOS modules. Instead of these | ||
functions, you can declare your warnings and assertions using the | ||
NixOS module system. | ||
</para> | ||
|
||
<section> | ||
|
||
<title>Warnings</title> | ||
|
||
<para> | ||
This is an example of using <literal>warnings</literal>. | ||
</para> | ||
|
||
<programlisting> | ||
<![CDATA[ | ||
{ config, lib, ... }: | ||
{ | ||
config = lib.mkIf config.services.foo.enable { | ||
warnings = | ||
if config.services.foo.bar | ||
then [ ''You have enabled the bar feature of the foo service. | ||
This is known to cause some specific problems in certain situations. | ||
'' ] | ||
else []; | ||
} | ||
} | ||
]]> | ||
</programlisting> | ||
|
||
</section> | ||
|
||
<section> | ||
|
||
<title>Assertions</title> | ||
|
||
|
||
<para> | ||
This example, extracted from the | ||
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/release-17.09/nixos/modules/services/logging/syslogd.nix"> | ||
<literal>syslogd</literal> module | ||
</link> shows how to use <literal>assertions</literal>. Since there | ||
can only be one active syslog daemon at a time, an assertion is useful to | ||
prevent such a broken system from being built. | ||
</para> | ||
|
||
<programlisting> | ||
<![CDATA[ | ||
{ config, lib, ... }: | ||
{ | ||
config = lib.mkIf config.services.syslogd.enable { | ||
assertions = | ||
[ { assertion = !config.services.rsyslogd.enable; | ||
message = "rsyslogd conflicts with syslogd"; | ||
} | ||
]; | ||
} | ||
} | ||
]]> | ||
</programlisting> | ||
|
||
</section> | ||
|
||
</section> |
This file contains 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 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 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 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 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
128 changes: 128 additions & 0 deletions
128
nixos/modules/services/monitoring/prometheus/collectd-exporter.nix
This file contains 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,128 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.prometheus.collectdExporter; | ||
|
||
collectSettingsArgs = if (cfg.collectdBinary.enable) then '' | ||
-collectd.listen-address ${optionalString (cfg.collectdBinary.listenAddress != null) cfg.collectdBinary.listenAddress}:${toString cfg.collectdBinary.port} \ | ||
-collectd.security-level ${cfg.collectdBinary.securityLevel} \ | ||
'' else ""; | ||
|
||
in { | ||
options = { | ||
services.prometheus.collectdExporter = { | ||
enable = mkEnableOption "prometheus collectd exporter"; | ||
|
||
port = mkOption { | ||
type = types.int; | ||
default = 9103; | ||
description = '' | ||
Port to listen on. | ||
This is used for scraping as well as the to receive collectd data via the write_http plugin. | ||
''; | ||
}; | ||
|
||
listenAddress = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "0.0.0.0"; | ||
description = '' | ||
Address to listen on for web interface, telemetry and collectd JSON data. | ||
''; | ||
}; | ||
|
||
collectdBinary = { | ||
enable = mkEnableOption "collectd binary protocol receiver"; | ||
|
||
authFile = mkOption { | ||
default = null; | ||
type = types.nullOr types.path; | ||
description = "File mapping user names to pre-shared keys (passwords)."; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.int; | ||
default = 25826; | ||
description = ''Network address on which to accept collectd binary network packets.''; | ||
}; | ||
|
||
listenAddress = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
example = "0.0.0.0"; | ||
description = '' | ||
Address to listen on for binary network packets. | ||
''; | ||
}; | ||
|
||
securityLevel = mkOption { | ||
type = types.enum ["None" "Sign" "Encrypt"]; | ||
default = "None"; | ||
description = '' | ||
Minimum required security level for accepted packets. | ||
''; | ||
}; | ||
}; | ||
|
||
extraFlags = mkOption { | ||
type = types.listOf types.str; | ||
default = []; | ||
description = '' | ||
Extra commandline options when launching the collectd exporter. | ||
''; | ||
}; | ||
|
||
logFormat = mkOption { | ||
type = types.str; | ||
default = "logger:stderr"; | ||
example = "logger:syslog?appname=bob&local=7 or logger:stdout?json=true"; | ||
description = '' | ||
Set the log target and format. | ||
''; | ||
}; | ||
|
||
logLevel = mkOption { | ||
type = types.enum ["debug" "info" "warn" "error" "fatal"]; | ||
default = "info"; | ||
description = '' | ||
Only log messages with the given severity or above. | ||
''; | ||
}; | ||
|
||
openFirewall = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = '' | ||
Open port in firewall for incoming connections. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
networking.firewall.allowedTCPPorts = (optional cfg.openFirewall cfg.port) ++ | ||
(optional (cfg.openFirewall && cfg.collectdBinary.enable) cfg.collectdBinary.port); | ||
|
||
systemd.services.prometheus-collectd-exporter = { | ||
description = "Prometheus exporter for Collectd metrics"; | ||
unitConfig.Documentation = "https://github.com/prometheus/collectd_exporter"; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = { | ||
DynamicUser = true; | ||
Restart = "always"; | ||
PrivateTmp = true; | ||
WorkingDirectory = /tmp; | ||
ExecStart = '' | ||
${pkgs.prometheus-collectd-exporter}/bin/collectd_exporter \ | ||
-log.format ${cfg.logFormat} \ | ||
-log.level ${cfg.logLevel} \ | ||
-web.listen-address ${optionalString (cfg.listenAddress != null) cfg.listenAddress}:${toString cfg.port} \ | ||
${collectSettingsArgs} \ | ||
${concatStringsSep " " cfg.extraFlags} | ||
''; | ||
}; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.